我們在自動化貼裝機標定過程中,需要計算吸頭的旋轉中心位置。我們一般使用的方法是使用模板匹配,做一個模板,吸頭旋轉一個角度尋找模板一次,通過多次旋轉求取吸頭的旋轉中心。
使用halcon實現
public bool FitCircle(double[] X, double[] Y, out double RcX, out double RcY, out double R){try{HTuple hTuple = new HTuple();HTuple hTuple2 = new HTuple();int num = 0;for (num = 0; num < X.Length; num++){if ((X[num] > 0.0) & (Y[num] > 0.0))//獲得尋找到的模板中心裝入hTuple2與hTuple{hTuple2.TupleConcat(X[num]);hTuple.TupleConcat(Y[num]);}}HObject contour;HOperatorSet.GenContourPolygonXld(out contour, hTuple, hTuple2);//使用模板中心生成多邊形XLD輪廓HTuple row, column,radius,StartPhi,EndPhi,pointOrder;HOperatorSet.FitCircleContourXld(contour, "algebraic", -1, 0, 0, 3, 2, out row, out column, out radius, out StartPhi, out EndPhi, out pointOrder);//擬合圓形//得出結果RcY = row;RcX = column;R = radius;contour.Dispose();return true;}catch{RcY = -1.0;RcX = -1.0;R = -1.0;return false;}}