public static void dispImage(HWindowControl hWC, HObject HImage) { HTuple hv_Width = null, hv_Height = null, hv_picWHRatio = null; HTuple hv_winWHRatio = null, hv_dispWidth = new HTuple(); HTuple hv_dispHeight = new HTuple(); // Initialize local and output iconic variables HTuple hv_winWidth = hWC.Width; HTuple hv_winHeight = hWC.Height; HOperatorSet.SetSystem("int_zooming", "true"); HOperatorSet.GetImageSize(HImage, out hv_Width, out hv_Height); hv_picWHRatio = (1.0 * hv_Width) / hv_Height; hv_winWHRatio = (1.0 * hv_winWidth) / hv_winHeight; if (new HTuple(hv_Width.TupleGreater(hv_winWidth)).TupleOr(new HTuple(hv_Height.TupleGreater( hv_winHeight))) != 0) { //如果图片宽高比 大于 窗口宽高比 //则宽度方向顶格 if (new HTuple(hv_picWHRatio.TupleGreaterEqual(hv_winWHRatio)) != 0) { hv_dispWidth = hv_Width.Clone(); hv_dispHeight = hv_Width / hv_winWHRatio; HOperatorSet.SetPart(hWC.HalconWindow, 0, 0, hv_dispHeight, hv_dispWidth); HOperatorSet.DispObj(HImage, hWC.HalconWindow); } //如果图片宽高比 小于 窗口宽高比 //则高度方向顶格 if (new HTuple(hv_picWHRatio.TupleLess(hv_winWHRatio)) == 0) { return; } hv_dispWidth = hv_Height * hv_winWHRatio; hv_dispHeight = hv_Height.Clone(); HOperatorSet.SetPart(hWC.HalconWindow, 0, 0, hv_dispHeight, hv_dispWidth); HOperatorSet.DispObj(HImage, hWC.HalconWindow); } else { //如果图片的长和宽都小于窗口,则以图片的原真实尺寸显示 HOperatorSet.SetPart(hWC.HalconWindow, 0, 0, hv_winWidth, hv_winHeight); HOperatorSet.DispObj(HImage, hWC.HalconWindow); } return; ////////////////////////////////////////////////////////////////////////////test-end }
// Local procedures public static void Get_11_Point_Coordinates(HObject ho_Image, HTuple hv_Diameter, HTuple hv_Threshold, out HTuple hv_isFind, out HTuple hv_Rows_cc, out HTuple hv_Cols_cc) { // Stack for temporary objects HObject[] OTemp = new HObject[20]; // Local iconic variables HObject ho_ImageOut = null, ho_Region, ho_RegionOpening; HObject ho_ConnectedRegions, ho_Regions_11_Circles, ho_RegionUnion100; HObject ho_RegionClosing, ho_Regions_9_Circles, ho_Regions_2_Circles; // Local control variables HTuple hv_Channels = null, hv_Areas11 = null; HTuple hv_Rows11 = null, hv_Columns11 = null, hv_Indices0 = null; HTuple hv_x1 = null, hv_y1 = null, hv_x3 = null, hv_y3 = null; HTuple hv_Dist1_3 = null, hv_Areas = null, hv_Rows = null; HTuple hv_Columns = null, hv_Distances = null, hv_i = null; HTuple hv_Dist = new HTuple(), hv_Indices = null, hv_x9 = null; HTuple hv_y9 = null, hv_x7 = null, hv_y7 = null, hv_x5_ = null; HTuple hv_y5_ = null, hv_x5 = null, hv_y5 = null, hv_x2_ = null; HTuple hv_y2_ = null, hv_x2 = null, hv_y2 = null, hv_x6_ = null; HTuple hv_y6_ = null, hv_x6 = null, hv_y6 = null, hv_x8_ = null; HTuple hv_y8_ = null, hv_x8 = null, hv_y8 = null, hv_x4_ = null; HTuple hv_y4_ = null, hv_x4 = null, hv_y4 = null, hv_Areas2 = null; HTuple hv_Rows2 = null, hv_Columns2 = null, hv_x11 = null; HTuple hv_y11 = null, hv_x10 = null, hv_y10 = null; // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_ImageOut); HOperatorSet.GenEmptyObj(out ho_Region); HOperatorSet.GenEmptyObj(out ho_RegionOpening); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions); HOperatorSet.GenEmptyObj(out ho_Regions_11_Circles); HOperatorSet.GenEmptyObj(out ho_RegionUnion100); HOperatorSet.GenEmptyObj(out ho_RegionClosing); HOperatorSet.GenEmptyObj(out ho_Regions_9_Circles); HOperatorSet.GenEmptyObj(out ho_Regions_2_Circles); hv_Rows_cc = new HTuple(); hv_Cols_cc = new HTuple(); try { //说明: //1、Diameter指的是常规的9个圆的直径大小(以像素计量),如果懒得设置,可以令Diameter := 0。isFind ==1 表示成功找到11个圆。 //2、每个黑圆中央必须有一个小白点清晰可见,并且黑圆的个数必须为11个,否则函数将计算失败。 //3、当标定板摆正时,圆的排序“先从左到右,再从上到下”,最小的圆是圆1,最大的圆是圆3 //4、标定板可以任意角度摆放,不一定需要摆正。标定板表面不得有其他脏污,否则可能计算失败。标定板图像需黑白分明。 //5、halcon的x、y(Rows_cc和Cols_cc)和其他编程语言中的图像中x、y值刚好是相反的。具体使用时,要把x、y的值调换顺序。 //6、圆10和圆11必须离圆1-9比较远 //7、如程序执行异常需要优化,可联系[email protected] ho_ImageOut.Dispose(); ho_ImageOut = ho_Image.CopyObj(1, -1); hv_isFind = 0; HOperatorSet.CountChannels(ho_ImageOut, out hv_Channels); if ((int)(new HTuple(hv_Channels.TupleGreaterEqual(3))) != 0) { { HObject ExpTmpOutVar_0; HOperatorSet.Rgb1ToGray(ho_ImageOut, out ExpTmpOutVar_0); ho_ImageOut.Dispose(); ho_ImageOut = ExpTmpOutVar_0; } } ho_Region.Dispose(); HOperatorSet.Threshold(ho_ImageOut, out ho_Region, 0, hv_Threshold); { HObject ExpTmpOutVar_0; HOperatorSet.FillUp(ho_Region, out ExpTmpOutVar_0); ho_Region.Dispose(); ho_Region = ExpTmpOutVar_0; } ho_RegionOpening.Dispose(); HOperatorSet.OpeningCircle(ho_Region, out ho_RegionOpening, 4.0); ho_ConnectedRegions.Dispose(); HOperatorSet.Connection(ho_RegionOpening, out ho_ConnectedRegions); ho_Regions_11_Circles.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_Regions_11_Circles, (new HTuple("circularity")).TupleConcat( "area"), "and", (new HTuple(0.9)).TupleConcat(10000), (new HTuple(1.0)).TupleConcat( 9999999999)); if ((int)(new HTuple(hv_Diameter.TupleNotEqual(0))) != 0) { { HObject ExpTmpOutVar_0; HOperatorSet.SelectShape(ho_Regions_11_Circles, out ExpTmpOutVar_0, "width", "and", hv_Diameter * 0.3, hv_Diameter * 3); ho_Regions_11_Circles.Dispose(); ho_Regions_11_Circles = ExpTmpOutVar_0; } } HOperatorSet.AreaCenter(ho_Regions_11_Circles, out hv_Areas11, out hv_Rows11, out hv_Columns11); ho_RegionUnion100.Dispose(); HOperatorSet.Union1(ho_Regions_11_Circles, out ho_RegionUnion100); if ((int)(new HTuple((new HTuple(hv_Areas11.TupleLength())).TupleNotEqual(11))) != 0) { hv_isFind = 0; ho_ImageOut.Dispose(); ho_Region.Dispose(); ho_RegionOpening.Dispose(); ho_ConnectedRegions.Dispose(); ho_Regions_11_Circles.Dispose(); ho_RegionUnion100.Dispose(); ho_RegionClosing.Dispose(); ho_Regions_9_Circles.Dispose(); ho_Regions_2_Circles.Dispose(); return; } HOperatorSet.TupleSortIndex(hv_Areas11, out hv_Indices0); //直径最小的是圆1 hv_x1 = hv_Rows11.TupleSelect(hv_Indices0.TupleSelect(0)); hv_y1 = hv_Columns11.TupleSelect(hv_Indices0.TupleSelect(0)); //直径最大的是圆3 hv_x3 = hv_Rows11.TupleSelect(hv_Indices0.TupleSelect((new HTuple(hv_Areas11.TupleLength() )) - 1)); hv_y3 = hv_Columns11.TupleSelect(hv_Indices0.TupleSelect((new HTuple(hv_Areas11.TupleLength() )) - 1)); HOperatorSet.DistancePp(hv_x1, hv_y1, hv_x3, hv_y3, out hv_Dist1_3); ho_RegionClosing.Dispose(); HOperatorSet.ClosingCircle(ho_RegionUnion100, out ho_RegionClosing, 5 + (hv_Dist1_3 / 4)); { HObject ExpTmpOutVar_0; HOperatorSet.FillUp(ho_RegionClosing, out ExpTmpOutVar_0); ho_RegionClosing.Dispose(); ho_RegionClosing = ExpTmpOutVar_0; } { HObject ExpTmpOutVar_0; HOperatorSet.Connection(ho_RegionClosing, out ExpTmpOutVar_0); ho_RegionClosing.Dispose(); ho_RegionClosing = ExpTmpOutVar_0; } { HObject ExpTmpOutVar_0; HOperatorSet.SelectShapeStd(ho_RegionClosing, out ExpTmpOutVar_0, "max_area", 70); ho_RegionClosing.Dispose(); ho_RegionClosing = ExpTmpOutVar_0; } ho_Regions_9_Circles.Dispose(); HOperatorSet.SelectShapeProto(ho_Regions_11_Circles, ho_RegionClosing, out ho_Regions_9_Circles, "overlaps_rel", 80, 100); HOperatorSet.AreaCenter(ho_Regions_9_Circles, out hv_Areas, out hv_Rows, out hv_Columns); if ((int)(new HTuple((new HTuple(hv_Areas.TupleLength())).TupleNotEqual(9))) != 0) { hv_isFind = 0; ho_ImageOut.Dispose(); ho_Region.Dispose(); ho_RegionOpening.Dispose(); ho_ConnectedRegions.Dispose(); ho_Regions_11_Circles.Dispose(); ho_RegionUnion100.Dispose(); ho_RegionClosing.Dispose(); ho_Regions_9_Circles.Dispose(); ho_Regions_2_Circles.Dispose(); return; } //离圆1最远的是圆9 hv_Distances = new HTuple(); for (hv_i = 0; (int)hv_i <= (int)((new HTuple(hv_Areas.TupleLength())) - 1); hv_i = (int)hv_i + 1) { HOperatorSet.DistancePp(hv_x1, hv_y1, hv_Rows.TupleSelect(hv_i), hv_Columns.TupleSelect( hv_i), out hv_Dist); hv_Distances = hv_Distances.TupleConcat(hv_Dist); } HOperatorSet.TupleSortIndex(hv_Distances, out hv_Indices); hv_x9 = hv_Rows.TupleSelect(hv_Indices.TupleSelect(8)); hv_y9 = hv_Columns.TupleSelect(hv_Indices.TupleSelect(8)); //离圆3最远的是圆7 hv_Distances = new HTuple(); for (hv_i = 0; (int)hv_i <= (int)((new HTuple(hv_Areas.TupleLength())) - 1); hv_i = (int)hv_i + 1) { HOperatorSet.DistancePp(hv_x3, hv_y3, hv_Rows.TupleSelect(hv_i), hv_Columns.TupleSelect( hv_i), out hv_Dist); hv_Distances = hv_Distances.TupleConcat(hv_Dist); } HOperatorSet.TupleSortIndex(hv_Distances, out hv_Indices); hv_x7 = hv_Rows.TupleSelect(hv_Indices.TupleSelect(8)); hv_y7 = hv_Columns.TupleSelect(hv_Indices.TupleSelect(8)); //圆1、9中间的是圆5 hv_x5_ = (hv_x1 + hv_x9) / 2; hv_y5_ = (hv_y1 + hv_y9) / 2; hv_Distances = new HTuple(); for (hv_i = 0; (int)hv_i <= (int)((new HTuple(hv_Areas.TupleLength())) - 1); hv_i = (int)hv_i + 1) { HOperatorSet.DistancePp(hv_x5_, hv_y5_, hv_Rows.TupleSelect(hv_i), hv_Columns.TupleSelect( hv_i), out hv_Dist); hv_Distances = hv_Distances.TupleConcat(hv_Dist); } HOperatorSet.TupleSortIndex(hv_Distances, out hv_Indices); hv_x5 = hv_Rows.TupleSelect(hv_Indices.TupleSelect(0)); hv_y5 = hv_Columns.TupleSelect(hv_Indices.TupleSelect(0)); //圆1、3中间的是圆2 hv_x2_ = (hv_x1 + hv_x3) / 2; hv_y2_ = (hv_y1 + hv_y3) / 2; hv_Distances = new HTuple(); for (hv_i = 0; (int)hv_i <= (int)((new HTuple(hv_Areas.TupleLength())) - 1); hv_i = (int)hv_i + 1) { HOperatorSet.DistancePp(hv_x2_, hv_y2_, hv_Rows.TupleSelect(hv_i), hv_Columns.TupleSelect( hv_i), out hv_Dist); hv_Distances = hv_Distances.TupleConcat(hv_Dist); } HOperatorSet.TupleSortIndex(hv_Distances, out hv_Indices); hv_x2 = hv_Rows.TupleSelect(hv_Indices.TupleSelect(0)); hv_y2 = hv_Columns.TupleSelect(hv_Indices.TupleSelect(0)); //圆3、9中间的是圆6 hv_x6_ = (hv_x3 + hv_x9) / 2; hv_y6_ = (hv_y3 + hv_y9) / 2; hv_Distances = new HTuple(); for (hv_i = 0; (int)hv_i <= (int)((new HTuple(hv_Areas.TupleLength())) - 1); hv_i = (int)hv_i + 1) { HOperatorSet.DistancePp(hv_x6_, hv_y6_, hv_Rows.TupleSelect(hv_i), hv_Columns.TupleSelect( hv_i), out hv_Dist); hv_Distances = hv_Distances.TupleConcat(hv_Dist); } HOperatorSet.TupleSortIndex(hv_Distances, out hv_Indices); hv_x6 = hv_Rows.TupleSelect(hv_Indices.TupleSelect(0)); hv_y6 = hv_Columns.TupleSelect(hv_Indices.TupleSelect(0)); //圆7、9中间的是圆8 hv_x8_ = (hv_x7 + hv_x9) / 2; hv_y8_ = (hv_y7 + hv_y9) / 2; hv_Distances = new HTuple(); for (hv_i = 0; (int)hv_i <= (int)((new HTuple(hv_Areas.TupleLength())) - 1); hv_i = (int)hv_i + 1) { HOperatorSet.DistancePp(hv_x8_, hv_y8_, hv_Rows.TupleSelect(hv_i), hv_Columns.TupleSelect( hv_i), out hv_Dist); hv_Distances = hv_Distances.TupleConcat(hv_Dist); } HOperatorSet.TupleSortIndex(hv_Distances, out hv_Indices); hv_x8 = hv_Rows.TupleSelect(hv_Indices.TupleSelect(0)); hv_y8 = hv_Columns.TupleSelect(hv_Indices.TupleSelect(0)); //圆1、7中间的是圆4 hv_x4_ = (hv_x1 + hv_x7) / 2; hv_y4_ = (hv_y1 + hv_y7) / 2; hv_Distances = new HTuple(); for (hv_i = 0; (int)hv_i <= (int)((new HTuple(hv_Areas.TupleLength())) - 1); hv_i = (int)hv_i + 1) { HOperatorSet.DistancePp(hv_x4_, hv_y4_, hv_Rows.TupleSelect(hv_i), hv_Columns.TupleSelect( hv_i), out hv_Dist); hv_Distances = hv_Distances.TupleConcat(hv_Dist); } HOperatorSet.TupleSortIndex(hv_Distances, out hv_Indices); hv_x4 = hv_Rows.TupleSelect(hv_Indices.TupleSelect(0)); hv_y4 = hv_Columns.TupleSelect(hv_Indices.TupleSelect(0)); hv_Rows_cc = new HTuple(); hv_Rows_cc = hv_Rows_cc.TupleConcat(hv_x1); hv_Rows_cc = hv_Rows_cc.TupleConcat(hv_x2); hv_Rows_cc = hv_Rows_cc.TupleConcat(hv_x3); hv_Rows_cc = hv_Rows_cc.TupleConcat(hv_x4); hv_Rows_cc = hv_Rows_cc.TupleConcat(hv_x5); hv_Rows_cc = hv_Rows_cc.TupleConcat(hv_x6); hv_Rows_cc = hv_Rows_cc.TupleConcat(hv_x7); hv_Rows_cc = hv_Rows_cc.TupleConcat(hv_x8); hv_Rows_cc = hv_Rows_cc.TupleConcat(hv_x9); hv_Cols_cc = new HTuple(); hv_Cols_cc = hv_Cols_cc.TupleConcat(hv_y1); hv_Cols_cc = hv_Cols_cc.TupleConcat(hv_y2); hv_Cols_cc = hv_Cols_cc.TupleConcat(hv_y3); hv_Cols_cc = hv_Cols_cc.TupleConcat(hv_y4); hv_Cols_cc = hv_Cols_cc.TupleConcat(hv_y5); hv_Cols_cc = hv_Cols_cc.TupleConcat(hv_y6); hv_Cols_cc = hv_Cols_cc.TupleConcat(hv_y7); hv_Cols_cc = hv_Cols_cc.TupleConcat(hv_y8); hv_Cols_cc = hv_Cols_cc.TupleConcat(hv_y9); //找最后两个点 ho_Regions_2_Circles.Dispose(); HOperatorSet.SelectShapeProto(ho_Regions_11_Circles, ho_RegionClosing, out ho_Regions_2_Circles, "overlaps_rel", 0, 30); HOperatorSet.AreaCenter(ho_Regions_2_Circles, out hv_Areas2, out hv_Rows2, out hv_Columns2); if ((int)(new HTuple((new HTuple(hv_Areas2.TupleLength())).TupleNotEqual(2))) != 0) { hv_isFind = 0; ho_ImageOut.Dispose(); ho_Region.Dispose(); ho_RegionOpening.Dispose(); ho_ConnectedRegions.Dispose(); ho_Regions_11_Circles.Dispose(); ho_RegionUnion100.Dispose(); ho_RegionClosing.Dispose(); ho_Regions_9_Circles.Dispose(); ho_Regions_2_Circles.Dispose(); return; } //离圆1最远的是圆11 hv_Distances = new HTuple(); for (hv_i = 0; (int)hv_i <= (int)((new HTuple(hv_Areas2.TupleLength())) - 1); hv_i = (int)hv_i + 1) { HOperatorSet.DistancePp(hv_x1, hv_y1, hv_Rows2.TupleSelect(hv_i), hv_Columns2.TupleSelect( hv_i), out hv_Dist); hv_Distances = hv_Distances.TupleConcat(hv_Dist); } HOperatorSet.TupleSortIndex(hv_Distances, out hv_Indices); hv_x11 = hv_Rows2.TupleSelect(hv_Indices.TupleSelect(1)); hv_y11 = hv_Columns2.TupleSelect(hv_Indices.TupleSelect(1)); //另一个点就是最近的 hv_x10 = hv_Rows2.TupleSelect(hv_Indices.TupleSelect(0)); hv_y10 = hv_Columns2.TupleSelect(hv_Indices.TupleSelect(0)); hv_Rows_cc = new HTuple(); hv_Rows_cc = hv_Rows_cc.TupleConcat(hv_x1); hv_Rows_cc = hv_Rows_cc.TupleConcat(hv_x2); hv_Rows_cc = hv_Rows_cc.TupleConcat(hv_x3); hv_Rows_cc = hv_Rows_cc.TupleConcat(hv_x4); hv_Rows_cc = hv_Rows_cc.TupleConcat(hv_x5); hv_Rows_cc = hv_Rows_cc.TupleConcat(hv_x6); hv_Rows_cc = hv_Rows_cc.TupleConcat(hv_x7); hv_Rows_cc = hv_Rows_cc.TupleConcat(hv_x8); hv_Rows_cc = hv_Rows_cc.TupleConcat(hv_x9); hv_Rows_cc = hv_Rows_cc.TupleConcat(hv_x10); hv_Rows_cc = hv_Rows_cc.TupleConcat(hv_x11); hv_Cols_cc = new HTuple(); hv_Cols_cc = hv_Cols_cc.TupleConcat(hv_y1); hv_Cols_cc = hv_Cols_cc.TupleConcat(hv_y2); hv_Cols_cc = hv_Cols_cc.TupleConcat(hv_y3); hv_Cols_cc = hv_Cols_cc.TupleConcat(hv_y4); hv_Cols_cc = hv_Cols_cc.TupleConcat(hv_y5); hv_Cols_cc = hv_Cols_cc.TupleConcat(hv_y6); hv_Cols_cc = hv_Cols_cc.TupleConcat(hv_y7); hv_Cols_cc = hv_Cols_cc.TupleConcat(hv_y8); hv_Cols_cc = hv_Cols_cc.TupleConcat(hv_y9); hv_Cols_cc = hv_Cols_cc.TupleConcat(hv_y10); hv_Cols_cc = hv_Cols_cc.TupleConcat(hv_y11); hv_isFind = 1; ho_ImageOut.Dispose(); ho_Region.Dispose(); ho_RegionOpening.Dispose(); ho_ConnectedRegions.Dispose(); ho_Regions_11_Circles.Dispose(); ho_RegionUnion100.Dispose(); ho_RegionClosing.Dispose(); ho_Regions_9_Circles.Dispose(); ho_Regions_2_Circles.Dispose(); return; } catch (HalconException HDevExpDefaultException) { ho_ImageOut.Dispose(); ho_Region.Dispose(); ho_RegionOpening.Dispose(); ho_ConnectedRegions.Dispose(); ho_Regions_11_Circles.Dispose(); ho_RegionUnion100.Dispose(); ho_RegionClosing.Dispose(); ho_Regions_9_Circles.Dispose(); ho_Regions_2_Circles.Dispose(); throw HDevExpDefaultException; } }
private void action() { // Stack for temporary objects HObject[] OTemp = new HObject[20]; // Local iconic variables HObject ho_Rectangle, ho_ImageReduced; HObject ho_Region, ho_ConnectedRegions, ho_SelectedRegions; HObject ho_Rectangle1, ho_ImageRotate, ho_Region1, ho_RegionAffineTrans; HObject ho_Region2, ho_RegionUnionu, ho_RegionUniond, ho_Contours; HObject ho_SelectedContours, ho_SmoothedContours1, ho_ClippedContoursu; HObject ho_ClippedContoursd, ho_Rectangle2, ho_ClippedContoursuObjectSelected = null; HObject ho_ClippedContoursdObjectSelected = null, ho_Circle = null; HObject ho_Circle1 = null, ho_ConnectedRegions1, ho_SelectedRegions1; HObject ho_SortedRegionssdj, ho_Region3, ho_ConnectedRegions2; HObject ho_SelectedRegions2, ho_SortedRegionsxdj, ho_RegionLines = null; HObject ho_RegionAffineTrans1; // Local control variables HTuple hv_Width = null, hv_Height = null; HTuple hv_jd = null, hv_Row = null, hv_Column = null, hv_Phi = null; HTuple hv_Length1 = null, hv_Length2 = null, hv_HomMat2DIdentity = null; HTuple hv_HomMat2DRotate = null, hv_Row1 = null, hv_Column1 = null; HTuple hv_Row2 = null, hv_Column2 = null, hv_Rown = null; HTuple hv_Rowu = null, hv_Columnu = null, hv_Phiu = null; HTuple hv_Length1u = null, hv_Length2u = null, hv_MeasureHandleu = null; HTuple hv_GrayValuesu = null, hv_Sigmau = null, hv_Functionu = null; HTuple hv_SmoothedFunctionu = null, hv_FirstDerivativeu = null; HTuple hv_ZeroCrossingsu = null, hv_RowStartu = null, hv_ColStartu = null; HTuple hv_RowEndu = null, hv_ColEndu = null, hv_iu = null; HTuple hv_Rowd = null, hv_Columnd = null, hv_Phid = null; HTuple hv_Length1d = null, hv_Length2d = null, hv_MeasureHandled = null; HTuple hv_GrayValuesd = null, hv_Sigmad = null, hv_Functiond = null; HTuple hv_SmoothedFunctiond = null, hv_FirstDerivatived = null; HTuple hv_ZeroCrossingsd = null, hv_RowStartd = null, hv_ColStartd = null; HTuple hv_RowEndd = null, hv_ColEndd = null, hv_id = null; HTuple hv_RowIntuAll = null, hv_ColumnIntuAll = null, hv_u1 = null; HTuple hv_i = null, hv_Length = new HTuple(), hv_Indices1 = new HTuple(); HTuple hv_RowIntu = new HTuple(), hv_ColumnIntu = new HTuple(); HTuple hv_IsOverlappingu = new HTuple(), hv_RowIntdAll = null; HTuple hv_ColumnIntdAll = null, hv_j = null, hv_RowIntd = new HTuple(); HTuple hv_ColumnIntd = new HTuple(), hv_IsOverlappingd = new HTuple(); HTuple hv_Sortedu = null, hv_Sortedd = null, hv_RowIntuu = null; HTuple hv_ColumnIntuu = null, hv_RowIntud = null, hv_ColumnIntud = null; HTuple hv_uu = null, hv_ud = null, hv_ub1 = null, hv_RowIntdu = null; HTuple hv_ColumnIntdu = null, hv_RowIntdd = null, hv_ColumnIntdd = null; HTuple hv_du = null, hv_dd = null, hv_db1 = null, hv_Areasdj = null; HTuple hv_Rowsdj = null, hv_Columnsdj = null, hv_sdj = null; HTuple hv_Areaxdj = null, hv_Rowxdj = null, hv_Columnxdj = null; HTuple hv_xdj = null, hv_djsl1 = null, hv_djsl = null; HTuple hv_Mean1 = null, hv_Mean2 = null, hv_Mean3 = null; HTuple hv_Mean4 = null, hv_Columnuu = null, hv_Columndd = null; HTuple hv_AngleAll = null, hv_l = null, hv_Angle = new HTuple(); HTuple hv_DegAll = null, hv_Mean5 = null, hv_Mean8 = null; HTuple hv_Columnuum = null, hv_uum1 = null, hv_uus = null; HTuple hv_Columnddm = null, hv_ddm = null, hv_dds = null; HTuple hv_ColumnmArr = null, hv_Mean9 = null, hv_Mean10 = null; HTuple hv_Sorteda = null, hv_Ai = null, hv_Ax = null, hv_pixeldist = null; HTuple hv_L = null, hv_D = null, hv_Dmax = null, hv_Dmin = null; HTuple hv_d = null, hv_dmax = null, hv_dmin = null, hv_LS = null; HTuple hv_HomMat2DIdentity1 = null, hv_HomMat2DRotate1 = null; // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Rectangle); HOperatorSet.GenEmptyObj(out ho_ImageReduced); HOperatorSet.GenEmptyObj(out ho_Region); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions); HOperatorSet.GenEmptyObj(out ho_SelectedRegions); HOperatorSet.GenEmptyObj(out ho_Rectangle1); HOperatorSet.GenEmptyObj(out ho_ImageRotate); HOperatorSet.GenEmptyObj(out ho_Region1); HOperatorSet.GenEmptyObj(out ho_RegionAffineTrans); HOperatorSet.GenEmptyObj(out ho_Region2); HOperatorSet.GenEmptyObj(out ho_RegionUnionu); HOperatorSet.GenEmptyObj(out ho_RegionUniond); HOperatorSet.GenEmptyObj(out ho_Contours); HOperatorSet.GenEmptyObj(out ho_SelectedContours); HOperatorSet.GenEmptyObj(out ho_SmoothedContours1); HOperatorSet.GenEmptyObj(out ho_ClippedContoursu); HOperatorSet.GenEmptyObj(out ho_ClippedContoursd); HOperatorSet.GenEmptyObj(out ho_Rectangle2); HOperatorSet.GenEmptyObj(out ho_ClippedContoursuObjectSelected); HOperatorSet.GenEmptyObj(out ho_ClippedContoursdObjectSelected); HOperatorSet.GenEmptyObj(out ho_Circle); HOperatorSet.GenEmptyObj(out ho_Circle1); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions1); HOperatorSet.GenEmptyObj(out ho_SelectedRegions1); HOperatorSet.GenEmptyObj(out ho_SortedRegionssdj); HOperatorSet.GenEmptyObj(out ho_Region3); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions2); HOperatorSet.GenEmptyObj(out ho_SelectedRegions2); HOperatorSet.GenEmptyObj(out ho_SortedRegionsxdj); HOperatorSet.GenEmptyObj(out ho_RegionLines); HOperatorSet.GenEmptyObj(out ho_RegionAffineTrans1); HOperatorSet.Union1(algorithm.Region, out RegionToDisp); try { HOperatorSet.GetImageSize(Image, out hv_Width, out hv_Height); ho_Rectangle.Dispose(); HOperatorSet.GenRectangle1(out ho_Rectangle, DRow1m, DCol1m, DRow2m, DCol2m); ho_ImageReduced.Dispose(); HOperatorSet.ReduceDomain(Image, ho_Rectangle, out ho_ImageReduced); //* ho_Region.Dispose(); HOperatorSet.Threshold(ho_ImageReduced, out ho_Region, 0, 128); ho_ConnectedRegions.Dispose(); HOperatorSet.Connection(ho_Region, out ho_ConnectedRegions); ho_SelectedRegions.Dispose(); HOperatorSet.SelectShapeStd(ho_ConnectedRegions, out ho_SelectedRegions, "max_area", 70); //hv_jd = 0; HOperatorSet.SmallestRectangle2(ho_SelectedRegions, out hv_Row, out hv_Column, out hv_Phi, out hv_Length1, out hv_Length2); ho_Rectangle1.Dispose(); HOperatorSet.GenRectangle2(out ho_Rectangle1, hv_Row, hv_Column, hv_Phi, hv_Length1, hv_Length2); ho_ImageRotate.Dispose(); HOperatorSet.RotateImage(Image, out ho_ImageRotate, -(hv_Phi.TupleDeg()), "constant"); //* ho_Region1.Dispose(); HOperatorSet.Threshold(ho_ImageRotate, out ho_Region1, 0, 128); //* HOperatorSet.HomMat2dIdentity(out hv_HomMat2DIdentity); HOperatorSet.HomMat2dRotate(hv_HomMat2DIdentity, -hv_Phi, hv_Height / 2, hv_Width / 2, out hv_HomMat2DRotate); ho_RegionAffineTrans.Dispose(); HOperatorSet.AffineTransRegion(ho_Rectangle1, out ho_RegionAffineTrans, hv_HomMat2DRotate, "nearest_neighbor"); HOperatorSet.SmallestRectangle1(ho_RegionAffineTrans, out hv_Row1, out hv_Column1, out hv_Row2, out hv_Column2); //*** ho_Region2.Dispose(); HOperatorSet.GenRegionPoints(out ho_Region2, hv_Row1, hv_Column1); ho_RegionUnionu.Dispose(); HOperatorSet.Union1(ho_Region2, out ho_RegionUnionu); ho_RegionUniond.Dispose(); HOperatorSet.Union1(ho_Region2, out ho_RegionUniond); ho_Contours.Dispose(); HOperatorSet.GenContourRegionXld(ho_Region1, out ho_Contours, "border"); ho_SelectedContours.Dispose(); HOperatorSet.SelectContoursXld(ho_Contours, out ho_SelectedContours, "contour_length", 20, 2000000, -1, 1); ho_SmoothedContours1.Dispose(); HOperatorSet.SmoothContoursXld(ho_SelectedContours, out ho_SmoothedContours1, 13); //* hv_Rown = (hv_Row1 + hv_Row2) / 2; ho_ClippedContoursu.Dispose(); HOperatorSet.ClipContoursXld(ho_SmoothedContours1, out ho_ClippedContoursu, hv_Row1, hv_Column1, hv_Rown, hv_Column2); ho_ClippedContoursd.Dispose(); HOperatorSet.ClipContoursXld(ho_SmoothedContours1, out ho_ClippedContoursd, hv_Rown, hv_Column1, hv_Row2, hv_Column2); hv_Rowu = (hv_Row1 + hv_Rown) / 2; hv_Columnu = (hv_Column1 + hv_Column2) / 2; hv_Phiu = 0; hv_Length1u = (hv_Column2 - hv_Column1) / 2; hv_Length2u = (hv_Rown - hv_Row1) / 2; //dev_set_draw ('margin') HOperatorSet.GenMeasureRectangle2(hv_Rowu, hv_Columnu, hv_Phiu, hv_Length1u, hv_Length2u, hv_Width, hv_Height, "bilinear", out hv_MeasureHandleu); ho_Rectangle2.Dispose(); HOperatorSet.GenRectangle2(out ho_Rectangle2, hv_Rowu, hv_Columnu, hv_Phiu, hv_Length1u, hv_Length2u); HOperatorSet.MeasureProjection(ho_ImageRotate, hv_MeasureHandleu, out hv_GrayValuesu); hv_Sigmau = 5; HOperatorSet.CreateFunct1dArray(hv_GrayValuesu, out hv_Functionu); HOperatorSet.SmoothFunct1dGauss(hv_Functionu, hv_Sigmau, out hv_SmoothedFunctionu); HOperatorSet.DerivateFunct1d(hv_SmoothedFunctionu, "first", out hv_FirstDerivativeu); HOperatorSet.ZeroCrossingsFunct1d(hv_FirstDerivativeu, out hv_ZeroCrossingsu); hv_RowStartu = hv_Rowu - (hv_Length2u / 2); hv_ColStartu = (hv_Columnu - hv_Length1u) + hv_ZeroCrossingsu; hv_RowEndu = hv_Rowu + (hv_Length2u / 2); hv_ColEndu = (hv_Columnu - hv_Length1u) + hv_ZeroCrossingsu; hv_iu = new HTuple(hv_ZeroCrossingsu.TupleLength()); hv_Rowd = (hv_Rown + hv_Row2) / 2; hv_Columnd = (hv_Column1 + hv_Column2) / 2; hv_Phid = 0; hv_Length1d = (hv_Column2 - hv_Column1) / 2; hv_Length2d = (hv_Row2 - hv_Rown) / 2; HOperatorSet.GenMeasureRectangle2(hv_Rowd, hv_Columnd, hv_Phid, hv_Length1d, hv_Length2d, hv_Width, hv_Height, "bilinear", out hv_MeasureHandled); HOperatorSet.MeasureProjection(ho_ImageRotate, hv_MeasureHandled, out hv_GrayValuesd); // hv_Sigmad = 5; HOperatorSet.CreateFunct1dArray(hv_GrayValuesd, out hv_Functiond); HOperatorSet.SmoothFunct1dGauss(hv_Functiond, hv_Sigmad, out hv_SmoothedFunctiond); HOperatorSet.DerivateFunct1d(hv_SmoothedFunctiond, "first", out hv_FirstDerivatived); HOperatorSet.ZeroCrossingsFunct1d(hv_FirstDerivatived, out hv_ZeroCrossingsd); HOperatorSet.CloseMeasure(hv_MeasureHandleu); HOperatorSet.CloseMeasure(hv_MeasureHandled); hv_RowStartd = hv_Rowd - (hv_Length2d / 2); hv_ColStartd = (hv_Columnd - hv_Length1d) + hv_ZeroCrossingsd; hv_RowEndd = hv_Rowd + (hv_Length2d / 2); hv_ColEndd = (hv_Columnd - hv_Length1d) + hv_ZeroCrossingsd; hv_id = new HTuple(hv_ZeroCrossingsd.TupleLength()); hv_RowIntuAll = new HTuple(); hv_ColumnIntuAll = new HTuple(); hv_u1 = 0; HTuple end_val96 = hv_iu - 1; HTuple step_val96 = 1; for (hv_i = 0; hv_i.Continue(end_val96, step_val96); hv_i = hv_i.TupleAdd(step_val96)) { HOperatorSet.LengthXld(ho_ClippedContoursu, out hv_Length); HOperatorSet.TupleFind(hv_Length, hv_Length.TupleMax(), out hv_Indices1); ho_ClippedContoursuObjectSelected.Dispose(); HOperatorSet.SelectObj(ho_ClippedContoursu, out ho_ClippedContoursuObjectSelected, hv_Indices1 + 1); HOperatorSet.IntersectionLineContourXld(ho_ClippedContoursuObjectSelected, hv_RowStartu, hv_ColStartu.TupleSelect(hv_i), hv_RowEndu, hv_ColEndu.TupleSelect( hv_i), out hv_RowIntu, out hv_ColumnIntu, out hv_IsOverlappingu); //*gen_cross_contour_xld (Cross1u, RowIntu, ColumnIntu, 12, 0)//根据每个输入点交叉的形状创键一个XLD轮廓(contour) hv_RowIntuAll = hv_RowIntuAll.TupleConcat(hv_RowIntu); hv_ColumnIntuAll = hv_ColumnIntuAll.TupleConcat(hv_ColumnIntu); hv_u1 = hv_u1 + 1; } hv_RowIntdAll = new HTuple(); hv_ColumnIntdAll = new HTuple(); HTuple end_val109 = hv_id - 1; HTuple step_val109 = 1; for (hv_j = 0; hv_j.Continue(end_val109, step_val109); hv_j = hv_j.TupleAdd(step_val109)) { HOperatorSet.LengthXld(ho_ClippedContoursd, out hv_Length); HOperatorSet.TupleFind(hv_Length, hv_Length.TupleMax(), out hv_Indices1); ho_ClippedContoursdObjectSelected.Dispose(); HOperatorSet.SelectObj(ho_ClippedContoursd, out ho_ClippedContoursdObjectSelected, hv_Indices1 + 1); HOperatorSet.IntersectionLineContourXld(ho_ClippedContoursdObjectSelected, hv_RowStartd, hv_ColStartd.TupleSelect(hv_j), hv_RowEndd, hv_ColEndd.TupleSelect( hv_j), out hv_RowIntd, out hv_ColumnIntd, out hv_IsOverlappingd); //*gen_cross_contour_xld (Cross1d, RowIntd, ColumnIntd, 12, 0)//根据每个输入点交叉的形状创键一个XLD轮廓(contour) hv_RowIntdAll = hv_RowIntdAll.TupleConcat(hv_RowIntd); hv_ColumnIntdAll = hv_ColumnIntdAll.TupleConcat(hv_ColumnIntd); } //stop () HOperatorSet.TupleSort(hv_RowIntuAll, out hv_Sortedu); HOperatorSet.TupleSort(hv_RowIntdAll, out hv_Sortedd); hv_RowIntuu = new HTuple(); hv_ColumnIntuu = new HTuple(); hv_RowIntud = new HTuple(); hv_ColumnIntud = new HTuple(); hv_uu = 0; hv_ud = 0; for (hv_ub1 = 0; (int)hv_ub1 <= (int)((new HTuple(hv_Sortedu.TupleLength())) - 1); hv_ub1 = (int)hv_ub1 + 1) { if ((int)(new HTuple(((hv_RowIntuAll.TupleSelect(hv_ub1))).TupleLess(((((hv_Sortedu.TupleSelect( 0)) * 2) + (hv_Sortedu.TupleSelect((new HTuple(hv_Sortedu.TupleLength())) - 1))) / 3) + 3))) != 0) { hv_RowIntuu = hv_RowIntuu.TupleConcat(hv_RowIntuAll.TupleSelect(hv_ub1)); hv_ColumnIntuu = hv_ColumnIntuu.TupleConcat(hv_ColumnIntuAll.TupleSelect( hv_ub1)); ho_Circle.Dispose(); HOperatorSet.GenCircle(out ho_Circle, hv_RowIntuAll.TupleSelect(hv_ub1), hv_ColumnIntuAll.TupleSelect(hv_ub1), 1); { HObject ExpTmpOutVar_0; HOperatorSet.Union2(ho_RegionUnionu, ho_Circle, out ExpTmpOutVar_0); ho_RegionUnionu.Dispose(); ho_RegionUnionu = ExpTmpOutVar_0; } hv_uu = hv_uu + 1; } if ((int)(new HTuple(((hv_RowIntuAll.TupleSelect(hv_ub1))).TupleGreater((((hv_Sortedu.TupleSelect( 0)) + ((hv_Sortedu.TupleSelect((new HTuple(hv_Sortedu.TupleLength())) - 1)) * 2)) / 3) - 3))) != 0) { hv_RowIntud = hv_RowIntud.TupleConcat(hv_RowIntuAll.TupleSelect(hv_ub1)); hv_ColumnIntud = hv_ColumnIntud.TupleConcat(hv_ColumnIntuAll.TupleSelect( hv_ub1)); hv_ud = hv_ud + 1; } } //stop () hv_RowIntdu = new HTuple(); hv_ColumnIntdu = new HTuple(); hv_RowIntdd = new HTuple(); hv_ColumnIntdd = new HTuple(); hv_du = 0; hv_dd = 0; for (hv_db1 = 0; (int)hv_db1 <= (int)((new HTuple(hv_Sortedd.TupleLength())) - 1); hv_db1 = (int)hv_db1 + 1) { if ((int)(new HTuple(((hv_RowIntdAll.TupleSelect(hv_db1))).TupleLess(((((hv_Sortedd.TupleSelect( 0)) * 2) + (hv_Sortedd.TupleSelect((new HTuple(hv_Sortedd.TupleLength())) - 1))) / 3) + 3))) != 0) { hv_RowIntdu = hv_RowIntdu.TupleConcat(hv_RowIntdAll.TupleSelect(hv_db1)); hv_ColumnIntdu = hv_ColumnIntdu.TupleConcat(hv_ColumnIntdAll.TupleSelect( hv_db1)); hv_du = hv_du + 1; } if ((int)(new HTuple(((hv_RowIntdAll.TupleSelect(hv_db1))).TupleGreater((((hv_Sortedd.TupleSelect( 0)) + ((hv_Sortedd.TupleSelect((new HTuple(hv_Sortedd.TupleLength())) - 1)) * 2)) / 3) - 3))) != 0) { hv_RowIntdd = hv_RowIntdd.TupleConcat(hv_RowIntdAll.TupleSelect(hv_db1)); hv_ColumnIntdd = hv_ColumnIntdd.TupleConcat(hv_ColumnIntdAll.TupleSelect( hv_db1)); ho_Circle1.Dispose(); HOperatorSet.GenCircle(out ho_Circle1, hv_RowIntdAll.TupleSelect(hv_db1), hv_ColumnIntdAll.TupleSelect(hv_db1), 1); { HObject ExpTmpOutVar_0; HOperatorSet.Union2(ho_RegionUniond, ho_Circle1, out ExpTmpOutVar_0); ho_RegionUniond.Dispose(); ho_RegionUniond = ExpTmpOutVar_0; } hv_dd = hv_dd + 1; } } ho_ConnectedRegions1.Dispose(); HOperatorSet.Connection(ho_RegionUnionu, out ho_ConnectedRegions1); ho_SelectedRegions1.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions1, out ho_SelectedRegions1, "area", "and", 3, 99999); ho_SortedRegionssdj.Dispose(); HOperatorSet.SortRegion(ho_SelectedRegions1, out ho_SortedRegionssdj, "upper_left", "true", "column"); HOperatorSet.AreaCenter(ho_SortedRegionssdj, out hv_Areasdj, out hv_Rowsdj, out hv_Columnsdj); ho_Region3.Dispose(); HOperatorSet.GenRegionPoints(out ho_Region3, hv_Rowsdj.TupleSelect(0), hv_Columnsdj.TupleSelect( 0)); hv_sdj = new HTuple(hv_Columnsdj.TupleLength()); ho_ConnectedRegions2.Dispose(); HOperatorSet.Connection(ho_RegionUniond, out ho_ConnectedRegions2); ho_SelectedRegions2.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions2, out ho_SelectedRegions2, "area", "and", 3, 99999); ho_SortedRegionsxdj.Dispose(); HOperatorSet.SortRegion(ho_SelectedRegions2, out ho_SortedRegionsxdj, "upper_left", "true", "column"); HOperatorSet.AreaCenter(ho_SortedRegionsxdj, out hv_Areaxdj, out hv_Rowxdj, out hv_Columnxdj); hv_xdj = new HTuple(hv_Columnxdj.TupleLength()); hv_djsl1 = new HTuple(); hv_djsl1 = hv_djsl1.TupleConcat(hv_sdj); hv_djsl1 = hv_djsl1.TupleConcat(hv_xdj); HOperatorSet.TupleMin(hv_djsl1, out hv_djsl); HOperatorSet.TupleMean(hv_RowIntuu, out hv_Mean1); HOperatorSet.TupleMean(hv_RowIntud, out hv_Mean2); HOperatorSet.TupleMean(hv_RowIntdu, out hv_Mean3); HOperatorSet.TupleMean(hv_RowIntdd, out hv_Mean4); hv_Columnuu = new HTuple(); hv_Columndd = new HTuple(); hv_AngleAll = new HTuple(); HTuple end_val191 = hv_djsl - 1; HTuple step_val191 = 1; for (hv_l = 0; hv_l.Continue(end_val191, step_val191); hv_l = hv_l.TupleAdd(step_val191)) { ho_RegionLines.Dispose(); HOperatorSet.GenRegionLine(out ho_RegionLines, hv_Rowsdj.TupleSelect(hv_l), hv_Columnsdj.TupleSelect(hv_l), hv_Rowxdj.TupleSelect(hv_l), hv_Columnxdj.TupleSelect( hv_l)); { HObject ExpTmpOutVar_0; HOperatorSet.Union2(ho_Region3, ho_RegionLines, out ExpTmpOutVar_0); ho_Region3.Dispose(); ho_Region3 = ExpTmpOutVar_0; } HOperatorSet.AngleLx(hv_Rowsdj.TupleSelect(hv_l), hv_Columnsdj.TupleSelect( hv_l), hv_Rowxdj.TupleSelect(hv_l), hv_Columnxdj.TupleSelect(hv_l), out hv_Angle); hv_AngleAll = hv_AngleAll.TupleConcat(0 - hv_Angle); if ((int)(new HTuple(hv_l.TupleGreater(0))) != 0) { hv_Columnuu = hv_Columnuu.TupleConcat((hv_ColumnIntuu.TupleSelect(hv_l)) - (hv_ColumnIntuu.TupleSelect( hv_l - 1))); hv_Columndd = hv_Columndd.TupleConcat((hv_ColumnIntdd.TupleSelect(hv_l)) - (hv_ColumnIntdd.TupleSelect( hv_l - 1))); } //stop () } HOperatorSet.TupleDeg(hv_AngleAll, out hv_DegAll); HOperatorSet.TupleMean(hv_Columnuu, out hv_Mean5); HOperatorSet.TupleMean(hv_Columndd, out hv_Mean8); //**过滤 hv_Columnuum = new HTuple(); hv_uum1 = 0; for (hv_uus = 0; (int)hv_uus <= (int)((new HTuple(hv_Columnuu.TupleLength())) - 1); hv_uus = (int)hv_uus + 1) { if ((int)((new HTuple(hv_Columnuu.TupleLessEqual(hv_Mean5 * 1.1))).TupleAnd(new HTuple(hv_Columnuu.TupleGreaterEqual( hv_Mean5 * 0.9)))) != 0) { hv_Columnuum = hv_Columnuum.TupleConcat(hv_Columnuu.TupleSelect(hv_uus)); hv_uum1 = hv_uum1 + 1; } } hv_Columnddm = new HTuple(); hv_ddm = 0; for (hv_dds = 0; (int)hv_dds <= (int)((new HTuple(hv_Columndd.TupleLength())) - 1); hv_dds = (int)hv_dds + 1) { if ((int)((new HTuple(hv_Columndd.TupleLessEqual(hv_Mean8 * 1.1))).TupleAnd(new HTuple(hv_Columndd.TupleGreaterEqual( hv_Mean8 * 0.9)))) != 0) { hv_Columnddm = hv_Columnddm.TupleConcat(hv_Columndd.TupleSelect(hv_dds)); hv_ddm = hv_ddm + 1; } } hv_ColumnmArr = new HTuple(); hv_ColumnmArr = hv_ColumnmArr.TupleConcat(hv_Columnuum); hv_ColumnmArr = hv_ColumnmArr.TupleConcat(hv_Columnddm); HOperatorSet.TupleMean(hv_ColumnmArr, out hv_Mean9); HOperatorSet.TupleMean(hv_DegAll, out hv_Mean10); HOperatorSet.TupleSort(hv_DegAll, out hv_Sorteda); hv_Ai = hv_Sorteda[0]; hv_Ax = hv_Sorteda[(new HTuple(hv_Sorteda.TupleLength())) - 1]; hv_pixeldist = 1; hv_L = ((hv_Columnsdj.TupleSelect(hv_djsl - 1)) - (hv_Columnsdj.TupleSelect(0))) * hv_pixeldist; hv_D = (hv_Mean4 - hv_Mean1) * hv_pixeldist; hv_Dmax = ((hv_RowIntdd.TupleMax()) - (hv_RowIntuu.TupleMin())) * hv_pixeldist; hv_Dmin = ((hv_RowIntdd.TupleMin()) - (hv_RowIntuu.TupleMax())) * hv_pixeldist; hv_d = (hv_Mean3 - hv_Mean2) * hv_pixeldist; hv_dmax = ((hv_RowIntdu.TupleMax()) - (hv_RowIntud.TupleMin())) * hv_pixeldist; hv_dmin = ((hv_RowIntdu.TupleMin()) - (hv_RowIntud.TupleMax())) * hv_pixeldist; hv_LS = hv_Mean9 * hv_pixeldist; //*区域旋转 HOperatorSet.HomMat2dIdentity(out hv_HomMat2DIdentity1); HOperatorSet.HomMat2dRotate(hv_HomMat2DIdentity1, hv_Phi, hv_Height / 2, hv_Width / 2, out hv_HomMat2DRotate1); ho_RegionAffineTrans1.Dispose(); HOperatorSet.AffineTransRegion(ho_Region3, out ho_RegionAffineTrans1, hv_HomMat2DRotate1, "nearest_neighbor"); HOperatorSet.Union1(ho_RegionAffineTrans1, out RegionToDisp); HTuple hv_result = GetHv_result(); hv_result = hv_result.TupleConcat("齿数"); hv_result = hv_result.TupleConcat(hv_djsl.D); hv_result = hv_result.TupleConcat("螺纹长度"); hv_result = hv_result.TupleConcat(hv_L.D * pixeldist); hv_result = hv_result.TupleConcat("螺纹大径平均值"); hv_result = hv_result.TupleConcat(hv_D.D * pixeldist); hv_result = hv_result.TupleConcat("螺纹大径最小值"); hv_result = hv_result.TupleConcat(hv_Dmin.D * pixeldist); hv_result = hv_result.TupleConcat("螺纹大径最大值"); hv_result = hv_result.TupleConcat(hv_Dmax.D * pixeldist); hv_result = hv_result.TupleConcat("螺纹小径平均值"); hv_result = hv_result.TupleConcat(hv_d.D * pixeldist); hv_result = hv_result.TupleConcat("螺纹小径最小值"); hv_result = hv_result.TupleConcat(hv_dmin.D * pixeldist); hv_result = hv_result.TupleConcat("螺纹小径最大值"); hv_result = hv_result.TupleConcat(hv_dmax.D * pixeldist); hv_result = hv_result.TupleConcat("牙距"); hv_result = hv_result.TupleConcat(hv_LS.D * pixeldist); hv_result = hv_result.TupleConcat("平均牙倾角"); hv_result = hv_result.TupleConcat(hv_Mean10.D); hv_result = hv_result.TupleConcat("最小牙倾角"); hv_result = hv_result.TupleConcat(hv_Ai.D); hv_result = hv_result.TupleConcat("最大牙倾角"); hv_result = hv_result.TupleConcat(hv_Ax.D); result = hv_result.Clone(); ho_Rectangle.Dispose(); ho_ImageReduced.Dispose(); ho_Region.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions.Dispose(); ho_Rectangle1.Dispose(); ho_ImageRotate.Dispose(); ho_Region1.Dispose(); ho_RegionAffineTrans.Dispose(); ho_Region2.Dispose(); ho_RegionUnionu.Dispose(); ho_RegionUniond.Dispose(); ho_Contours.Dispose(); ho_SelectedContours.Dispose(); ho_SmoothedContours1.Dispose(); ho_ClippedContoursu.Dispose(); ho_ClippedContoursd.Dispose(); ho_Rectangle2.Dispose(); ho_ClippedContoursuObjectSelected.Dispose(); ho_ClippedContoursdObjectSelected.Dispose(); ho_Circle.Dispose(); ho_Circle1.Dispose(); ho_ConnectedRegions1.Dispose(); ho_SelectedRegions1.Dispose(); ho_SortedRegionssdj.Dispose(); ho_Region3.Dispose(); ho_ConnectedRegions2.Dispose(); ho_SelectedRegions2.Dispose(); ho_SortedRegionsxdj.Dispose(); ho_RegionLines.Dispose(); ho_RegionAffineTrans1.Dispose(); algorithm.Region.Dispose(); } catch { HTuple hv_result = GetHv_result(); hv_result = hv_result.TupleConcat("齿数"); hv_result = hv_result.TupleConcat(0); hv_result = hv_result.TupleConcat("螺纹长度"); hv_result = hv_result.TupleConcat(0); hv_result = hv_result.TupleConcat("螺纹大径平均值"); hv_result = hv_result.TupleConcat(0); hv_result = hv_result.TupleConcat("螺纹大径最小值"); hv_result = hv_result.TupleConcat(0); hv_result = hv_result.TupleConcat("螺纹大径最大值"); hv_result = hv_result.TupleConcat(0); hv_result = hv_result.TupleConcat("螺纹小径平均值"); hv_result = hv_result.TupleConcat(0); hv_result = hv_result.TupleConcat("螺纹小径最小值"); hv_result = hv_result.TupleConcat(0); hv_result = hv_result.TupleConcat("螺纹小径最大值"); hv_result = hv_result.TupleConcat(0); hv_result = hv_result.TupleConcat("牙距"); hv_result = hv_result.TupleConcat(0); hv_result = hv_result.TupleConcat("平均牙倾角"); hv_result = hv_result.TupleConcat(0); hv_result = hv_result.TupleConcat("最小牙倾角"); hv_result = hv_result.TupleConcat(0); hv_result = hv_result.TupleConcat("最大牙倾角"); hv_result = hv_result.TupleConcat(0); result = hv_result.Clone(); ho_Rectangle.Dispose(); ho_ImageReduced.Dispose(); ho_Region.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions.Dispose(); ho_Rectangle1.Dispose(); ho_ImageRotate.Dispose(); ho_Region1.Dispose(); ho_RegionAffineTrans.Dispose(); ho_Region2.Dispose(); ho_RegionUnionu.Dispose(); ho_RegionUniond.Dispose(); ho_Contours.Dispose(); ho_SelectedContours.Dispose(); ho_SmoothedContours1.Dispose(); ho_ClippedContoursu.Dispose(); ho_ClippedContoursd.Dispose(); ho_Rectangle2.Dispose(); ho_ClippedContoursuObjectSelected.Dispose(); ho_ClippedContoursdObjectSelected.Dispose(); ho_Circle.Dispose(); ho_Circle1.Dispose(); ho_ConnectedRegions1.Dispose(); ho_SelectedRegions1.Dispose(); ho_SortedRegionssdj.Dispose(); ho_Region3.Dispose(); ho_ConnectedRegions2.Dispose(); ho_SelectedRegions2.Dispose(); ho_SortedRegionsxdj.Dispose(); ho_RegionLines.Dispose(); ho_RegionAffineTrans1.Dispose(); algorithm.Region.Dispose(); } finally { ho_Rectangle.Dispose(); ho_ImageReduced.Dispose(); ho_Region.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions.Dispose(); ho_Rectangle1.Dispose(); ho_ImageRotate.Dispose(); ho_Region1.Dispose(); ho_RegionAffineTrans.Dispose(); ho_Region2.Dispose(); ho_RegionUnionu.Dispose(); ho_RegionUniond.Dispose(); ho_Contours.Dispose(); ho_SelectedContours.Dispose(); ho_SmoothedContours1.Dispose(); ho_ClippedContoursu.Dispose(); ho_ClippedContoursd.Dispose(); ho_Rectangle2.Dispose(); ho_ClippedContoursuObjectSelected.Dispose(); ho_ClippedContoursdObjectSelected.Dispose(); ho_Circle.Dispose(); ho_Circle1.Dispose(); ho_ConnectedRegions1.Dispose(); ho_SelectedRegions1.Dispose(); ho_SortedRegionssdj.Dispose(); ho_Region3.Dispose(); ho_ConnectedRegions2.Dispose(); ho_SelectedRegions2.Dispose(); ho_SortedRegionsxdj.Dispose(); ho_RegionLines.Dispose(); ho_RegionAffineTrans1.Dispose(); algorithm.Region.Dispose(); } }
public void CombinImage(HObject RawImage, int SubImageWidth, int SubImageHeight) { ho_Rectangle.Dispose(); HOperatorSet.GenRectangle1(out ho_Rectangle, 0, 7436, 97, 7706); ho_ImageReduced.Dispose(); HOperatorSet.ReduceDomain(RawImage, ho_Rectangle, out ho_ImageReduced); ho_Region.Dispose(); HOperatorSet.Threshold(ho_ImageReduced, out ho_Region, 35, 255); ho_ConnectedRegions.Dispose(); HOperatorSet.Connection(ho_Region, out ho_ConnectedRegions); ho_SelectedRegions.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, "rectangularity", "and", 0.9, 1); HOperatorSet.AreaCenter(ho_SelectedRegions, out hv_Area, out hv_Row, out hv_Column); // 判断图像开始位置 if ((int)((new HTuple(hv_Area.TupleGreaterEqual(50))).TupleAnd(new HTuple(hv_Area.TupleLess(50000)))) != 0) { if ((int)(new HTuple(((hv_ImageIndex - hv_TempIndex)).TupleNotEqual(1))) != 0) { hv_flag = hv_flag + 1; } hv_TempIndex = hv_ImageIndex.Clone(); } //构建图像队列 if ((int)((new HTuple(hv_flag.TupleEqual(1))).TupleOr(new HTuple(hv_flag.TupleEqual(2)))) != 0) { { HObject ExpTmpOutVar_0; HOperatorSet.ConcatObj(ho_TotalImage, RawImage, out ExpTmpOutVar_0); ho_TotalImage.Dispose(); ho_TotalImage = ExpTmpOutVar_0; } hv_ImageCount = hv_ImageCount + 1; } //判断图像结束位置 HTuple hv_StartRow = new HTuple(), hv_StartColumn = new HTuple(); HTuple hv_Row1 = new HTuple(), hv_Column1 = new HTuple(), hv_Row2 = new HTuple(), hv_Column2 = new HTuple(); HTuple hv_j = new HTuple(); if ((int)(new HTuple(hv_flag.TupleEqual(2))) != 0) { hv_flag = 1; HTuple end_val459 = hv_ImageCount - 1; HTuple step_val459 = 1; for (hv_j = 0; hv_j.Continue(end_val459, step_val459); hv_j = hv_j.TupleAdd(step_val459)) { if (hv_StartRow == null) { hv_StartRow = new HTuple(); } hv_StartRow[hv_j] = SubImageHeight * hv_j; if (hv_StartColumn == null) { hv_StartColumn = new HTuple(); } hv_StartColumn[hv_j] = 0; if (hv_Row1 == null) { hv_Row1 = new HTuple(); } hv_Row1[hv_j] = -1; if (hv_Column1 == null) { hv_Column1 = new HTuple(); } hv_Column1[hv_j] = -1; if (hv_Row2 == null) { hv_Row2 = new HTuple(); } hv_Row2[hv_j] = -1; if (hv_Column2 == null) { hv_Column2 = new HTuple(); } hv_Column2[hv_j] = -1; } HOperatorSet.TileImagesOffset(ho_TotalImage, out ho_TiledImage, hv_StartRow, hv_StartColumn, hv_Row1, hv_Column1, hv_Row2, hv_Column2, SubImageWidth, SubImageHeight * hv_ImageCount); HOperatorSet.CopyImage(ho_TiledImage, out Model.RawImageSequence[AcquisionImageCount]); if (AcquisionImageCount == 0) { Model.AccessImageIndex = 0; } else if (AcquisionImageCount == 1) { Model.AccessImageIndex = 1; } else if (AcquisionImageCount == 2) { Model.AccessImageIndex = 2; } else if (AcquisionImageCount == 3) { Model.AccessImageIndex = 3; } //SaveImage(CommonModuleClass.RawImageSequence[AcquisionImageCount], false); hv_ImageCount = 1; ho_TiledImage.Dispose(); ho_TotalImage.Dispose(); HOperatorSet.CopyImage(RawImage, out ho_TotalImage); if (ho_CopyImage != null) { HOperatorSet.ClearWindow(Model.MainUI_Camera_WindowID); HOperatorSet.DispObj(Model.RawImageSequence[AcquisionImageCount], Model.MainUI_Camera_WindowID); } AcquisionImageCount++; if (AcquisionImageCount == 4) { AcquisionImageCount = 0; } } hv_ImageIndex++; }
/// <summary> /// Extracts the calibration plate and the marks on this plate /// for the supplied image /// </summary> public void find_caltab_edges(HObject ho_Image, out HObject ho_Caltab, out HObject ho_Marks, HTuple hv_DescriptionFileName) { // Stack for temporary objects HObject[] OTemp = new HObject[20]; // Local iconic variables HObject ho_ImageMean, ho_RegionDynThresh, ho_RegionBorder; HObject ho_RegionOpening1, ho_ConnectedRegions1, ho_SelectedRegions4; HObject ho_SelectedRegions5, ho_RegionBorder2, ho_RegionTrans; HObject ho_RegionErosion, ho_RegionBorder1, ho_RegionDilation2; HObject ho_RegionDifference1, ho_RegionOpening, ho_ConnectedRegions; HObject ho_SelectedRegions2, ho_SelectedRegions, ho_RegionFillUp; HObject ho_SelectedRegions1, ho_RegionIntersection, ho_RegionFillUp1; HObject ho_RegionDifference, ho_CaltabCandidates, ho_ObjectSelected = null; HObject ho_ConnectedMarks = null, ho_ObjectSelectedCaltab = null; HObject ho_RegionFillUpCand, ho_MarksCand, ho_RegionDilation1; HObject ho_ImageReduced, ho_DefaultEdges, ho_UnionContours; HObject ho_SelectedXLD, ho_SelectedXLD1; // Local control variables HTuple hv_Width, hv_Height, hv_EstimatedCaltabSize; HTuple hv_EstimatedMarkSize, hv_Number, hv_X, hv_Y, hv_Z; HTuple hv_NumDescrMarks, hv_Index, hv_NumberMarks = new HTuple(); HTuple hv_Anisometry = new HTuple(), hv_Bulkiness = new HTuple(); HTuple hv_StructureFactor = new HTuple(), hv_AreaMarks = new HTuple(); HTuple hv_Row = new HTuple(), hv_Column = new HTuple(), hv_Rectangularity; HTuple hv_SortedIndex, hv_IndexBest, hv_MinContrast, hv_NumberCand; HTuple hv_Area, hv_Dummy, hv_DummyS, hv_AreaMedian; // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Caltab); HOperatorSet.GenEmptyObj(out ho_Marks); HOperatorSet.GenEmptyObj(out ho_ImageMean); HOperatorSet.GenEmptyObj(out ho_RegionDynThresh); HOperatorSet.GenEmptyObj(out ho_RegionBorder); HOperatorSet.GenEmptyObj(out ho_RegionOpening1); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions1); HOperatorSet.GenEmptyObj(out ho_SelectedRegions4); HOperatorSet.GenEmptyObj(out ho_SelectedRegions5); HOperatorSet.GenEmptyObj(out ho_RegionBorder2); HOperatorSet.GenEmptyObj(out ho_RegionTrans); HOperatorSet.GenEmptyObj(out ho_RegionErosion); HOperatorSet.GenEmptyObj(out ho_RegionBorder1); HOperatorSet.GenEmptyObj(out ho_RegionDilation2); HOperatorSet.GenEmptyObj(out ho_RegionDifference1); HOperatorSet.GenEmptyObj(out ho_RegionOpening); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions); HOperatorSet.GenEmptyObj(out ho_SelectedRegions2); HOperatorSet.GenEmptyObj(out ho_SelectedRegions); HOperatorSet.GenEmptyObj(out ho_RegionFillUp); HOperatorSet.GenEmptyObj(out ho_SelectedRegions1); HOperatorSet.GenEmptyObj(out ho_RegionIntersection); HOperatorSet.GenEmptyObj(out ho_RegionFillUp1); HOperatorSet.GenEmptyObj(out ho_RegionDifference); HOperatorSet.GenEmptyObj(out ho_CaltabCandidates); HOperatorSet.GenEmptyObj(out ho_ObjectSelected); HOperatorSet.GenEmptyObj(out ho_ConnectedMarks); HOperatorSet.GenEmptyObj(out ho_ObjectSelectedCaltab); HOperatorSet.GenEmptyObj(out ho_RegionFillUpCand); HOperatorSet.GenEmptyObj(out ho_MarksCand); HOperatorSet.GenEmptyObj(out ho_RegionDilation1); HOperatorSet.GenEmptyObj(out ho_ImageReduced); HOperatorSet.GenEmptyObj(out ho_DefaultEdges); HOperatorSet.GenEmptyObj(out ho_UnionContours); HOperatorSet.GenEmptyObj(out ho_SelectedXLD); HOperatorSet.GenEmptyObj(out ho_SelectedXLD1); // ho_Marks.Dispose(); HOperatorSet.GenEmptyObj(out ho_Marks); ho_Caltab.Dispose(); HOperatorSet.GenEmptyObj(out ho_Caltab); HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height); hv_EstimatedCaltabSize = (((((hv_Width.TupleConcat(hv_Height))).TupleMax()) / 2.5)).TupleRound() ; hv_EstimatedMarkSize = ((hv_EstimatedCaltabSize / 12.0)).TupleRound(); ho_ImageMean.Dispose(); HOperatorSet.MeanImage(ho_Image, out ho_ImageMean, hv_EstimatedMarkSize * 3, hv_EstimatedMarkSize * 3); ho_RegionDynThresh.Dispose(); HOperatorSet.DynThreshold(ho_Image, ho_ImageMean, out ho_RegionDynThresh, 3, "light"); ho_RegionBorder.Dispose(); HOperatorSet.DynThreshold(ho_Image, ho_ImageMean, out ho_RegionBorder, 20, "dark"); ho_RegionOpening1.Dispose(); HOperatorSet.OpeningCircle(ho_RegionBorder, out ho_RegionOpening1, 1.5); ho_ConnectedRegions1.Dispose(); HOperatorSet.Connection(ho_RegionOpening1, out ho_ConnectedRegions1); ho_SelectedRegions4.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions1, out ho_SelectedRegions4, "compactness", "and", 17, 50); ho_SelectedRegions5.Dispose(); HOperatorSet.SelectShape(ho_SelectedRegions4, out ho_SelectedRegions5, "anisometry", "and", 1, 1.4); ho_RegionBorder2.Dispose(); HOperatorSet.Boundary(ho_SelectedRegions5, out ho_RegionBorder2, "outer"); ho_SelectedRegions5.Dispose(); HOperatorSet.SelectShape(ho_RegionBorder2, out ho_SelectedRegions5, "circularity", "and", 0.006, 1); ho_RegionTrans.Dispose(); HOperatorSet.ShapeTrans(ho_SelectedRegions5, out ho_RegionTrans, "rectangle2"); ho_RegionErosion.Dispose(); HOperatorSet.ErosionCircle(ho_RegionTrans, out ho_RegionErosion, (hv_Width / 640.0) * 5.5); ho_RegionBorder1.Dispose(); HOperatorSet.Boundary(ho_RegionErosion, out ho_RegionBorder1, "inner"); ho_RegionDilation2.Dispose(); HOperatorSet.DilationCircle(ho_RegionBorder1, out ho_RegionDilation2, 3.5); ho_RegionDifference1.Dispose(); HOperatorSet.Difference(ho_RegionDynThresh, ho_RegionDilation2, out ho_RegionDifference1 ); ho_RegionOpening.Dispose(); HOperatorSet.OpeningCircle(ho_RegionDifference1, out ho_RegionOpening, (hv_Width / 640) * 1.5); ho_ConnectedRegions.Dispose(); HOperatorSet.Connection(ho_RegionOpening, out ho_ConnectedRegions); ho_SelectedRegions2.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions2, "area", "and", (hv_EstimatedCaltabSize.TuplePow(2)) / 10, (hv_EstimatedCaltabSize.TuplePow( 2)) * 5); ho_SelectedRegions.Dispose(); HOperatorSet.SelectShape(ho_SelectedRegions2, out ho_SelectedRegions, "compactness", "and", 1.4, 10); ho_RegionFillUp.Dispose(); HOperatorSet.FillUp(ho_SelectedRegions, out ho_RegionFillUp); ho_SelectedRegions1.Dispose(); HOperatorSet.SelectShape(ho_RegionFillUp, out ho_SelectedRegions1, "rectangularity", "and", 0.6, 1); ho_RegionIntersection.Dispose(); HOperatorSet.Intersection(ho_SelectedRegions1, ho_RegionDynThresh, out ho_RegionIntersection ); ho_RegionFillUp1.Dispose(); HOperatorSet.FillUp(ho_RegionIntersection, out ho_RegionFillUp1); ho_RegionDifference.Dispose(); HOperatorSet.Difference(ho_RegionFillUp1, ho_RegionIntersection, out ho_RegionDifference ); HOperatorSet.CountObj(ho_RegionDifference, out hv_Number); ho_CaltabCandidates.Dispose(); HOperatorSet.GenEmptyObj(out ho_CaltabCandidates); HOperatorSet.CaltabPoints(hv_DescriptionFileName, out hv_X, out hv_Y, out hv_Z); hv_NumDescrMarks = new HTuple(hv_X.TupleLength()); for (hv_Index = 1; hv_Index.Continue(hv_Number, 1); hv_Index = hv_Index.TupleAdd(1)) { ho_ObjectSelected.Dispose(); HOperatorSet.SelectObj(ho_RegionDifference, out ho_ObjectSelected, hv_Index); ho_ConnectedMarks.Dispose(); HOperatorSet.Connection(ho_ObjectSelected, out ho_ConnectedMarks); HOperatorSet.CountObj(ho_ConnectedMarks, out hv_NumberMarks); HOperatorSet.Eccentricity(ho_ConnectedMarks, out hv_Anisometry, out hv_Bulkiness, out hv_StructureFactor); HOperatorSet.AreaCenter(ho_ConnectedMarks, out hv_AreaMarks, out hv_Row, out hv_Column); ho_ObjectSelectedCaltab.Dispose(); HOperatorSet.SelectObj(ho_RegionIntersection, out ho_ObjectSelectedCaltab, hv_Index); if ((int)((new HTuple((new HTuple((new HTuple(hv_NumberMarks.TupleGreaterEqual( 10))).TupleAnd(new HTuple(hv_NumberMarks.TupleLess(hv_NumDescrMarks + 20))))).TupleAnd( new HTuple(((((hv_Anisometry.TupleSort())).TupleSelect((new HTuple(hv_Anisometry.TupleLength() )) / 2))).TupleLess(2))))).TupleAnd(new HTuple((new HTuple(hv_AreaMarks.TupleMean() )).TupleGreater(20)))) != 0) { HOperatorSet.ConcatObj(ho_CaltabCandidates, ho_ObjectSelectedCaltab, out OTemp[0] ); ho_CaltabCandidates.Dispose(); ho_CaltabCandidates = OTemp[0]; } } ho_RegionFillUpCand.Dispose(); HOperatorSet.FillUp(ho_CaltabCandidates, out ho_RegionFillUpCand); HOperatorSet.Rectangularity(ho_RegionFillUpCand, out hv_Rectangularity); if ((int)(new HTuple((new HTuple(hv_Rectangularity.TupleLength())).TupleEqual( 0))) != 0) { ho_ImageMean.Dispose(); ho_RegionDynThresh.Dispose(); ho_RegionBorder.Dispose(); ho_RegionOpening1.Dispose(); ho_ConnectedRegions1.Dispose(); ho_SelectedRegions4.Dispose(); ho_SelectedRegions5.Dispose(); ho_RegionBorder2.Dispose(); ho_RegionTrans.Dispose(); ho_RegionErosion.Dispose(); ho_RegionBorder1.Dispose(); ho_RegionDilation2.Dispose(); ho_RegionDifference1.Dispose(); ho_RegionOpening.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions2.Dispose(); ho_SelectedRegions.Dispose(); ho_RegionFillUp.Dispose(); ho_SelectedRegions1.Dispose(); ho_RegionIntersection.Dispose(); ho_RegionFillUp1.Dispose(); ho_RegionDifference.Dispose(); ho_CaltabCandidates.Dispose(); ho_ObjectSelected.Dispose(); ho_ConnectedMarks.Dispose(); ho_ObjectSelectedCaltab.Dispose(); ho_RegionFillUpCand.Dispose(); ho_MarksCand.Dispose(); ho_RegionDilation1.Dispose(); ho_ImageReduced.Dispose(); ho_DefaultEdges.Dispose(); ho_UnionContours.Dispose(); ho_SelectedXLD.Dispose(); ho_SelectedXLD1.Dispose(); return; } hv_SortedIndex = hv_Rectangularity.TupleSortIndex(); hv_IndexBest = (((hv_SortedIndex.TupleInverse())).TupleSelect(0)) + 1; ho_Caltab.Dispose(); HOperatorSet.SelectObj(ho_RegionFillUpCand, out ho_Caltab, hv_IndexBest); ho_RegionFillUp.Dispose(); HOperatorSet.FillUp(ho_Caltab, out ho_RegionFillUp); ho_MarksCand.Dispose(); HOperatorSet.Difference(ho_RegionFillUp, ho_RegionDynThresh, out ho_MarksCand ); ho_RegionBorder.Dispose(); HOperatorSet.Boundary(ho_MarksCand, out ho_RegionBorder, "inner"); ho_RegionDilation1.Dispose(); HOperatorSet.DilationCircle(ho_RegionBorder, out ho_RegionDilation1, 9.5); ho_ImageReduced.Dispose(); HOperatorSet.ReduceDomain(ho_Image, ho_RegionDilation1, out ho_ImageReduced); hv_MinContrast = 10; ho_DefaultEdges.Dispose(); HOperatorSet.EdgesSubPix(ho_ImageReduced, out ho_DefaultEdges, "canny", 2, hv_MinContrast / 2, hv_MinContrast); HOperatorSet.CountObj(ho_DefaultEdges, out hv_NumberCand); if ((int)(new HTuple(hv_NumberCand.TupleLess(10))) != 0) { ho_ImageMean.Dispose(); ho_RegionDynThresh.Dispose(); ho_RegionBorder.Dispose(); ho_RegionOpening1.Dispose(); ho_ConnectedRegions1.Dispose(); ho_SelectedRegions4.Dispose(); ho_SelectedRegions5.Dispose(); ho_RegionBorder2.Dispose(); ho_RegionTrans.Dispose(); ho_RegionErosion.Dispose(); ho_RegionBorder1.Dispose(); ho_RegionDilation2.Dispose(); ho_RegionDifference1.Dispose(); ho_RegionOpening.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions2.Dispose(); ho_SelectedRegions.Dispose(); ho_RegionFillUp.Dispose(); ho_SelectedRegions1.Dispose(); ho_RegionIntersection.Dispose(); ho_RegionFillUp1.Dispose(); ho_RegionDifference.Dispose(); ho_CaltabCandidates.Dispose(); ho_ObjectSelected.Dispose(); ho_ConnectedMarks.Dispose(); ho_ObjectSelectedCaltab.Dispose(); ho_RegionFillUpCand.Dispose(); ho_MarksCand.Dispose(); ho_RegionDilation1.Dispose(); ho_ImageReduced.Dispose(); ho_DefaultEdges.Dispose(); ho_UnionContours.Dispose(); ho_SelectedXLD.Dispose(); ho_SelectedXLD1.Dispose(); return; } ho_UnionContours.Dispose(); HOperatorSet.UnionCocircularContoursXld(ho_DefaultEdges, out ho_UnionContours, 0.5, 0.1, 0.2, 30, 10, 10, "true", 1); ho_SelectedXLD.Dispose(); HOperatorSet.SelectShapeXld(ho_UnionContours, out ho_SelectedXLD, "area", "and", 30, 10000); ho_SelectedXLD1.Dispose(); HOperatorSet.SelectShapeXld(ho_SelectedXLD, out ho_SelectedXLD1, "circularity", "and", 0.4, 1); ho_MarksCand.Dispose(); HOperatorSet.SelectShapeXld(ho_SelectedXLD1, out ho_MarksCand, "compactness", "and", 1, 1.5); HOperatorSet.AreaCenterXld(ho_MarksCand, out hv_Area, out hv_Dummy, out hv_Dummy, out hv_DummyS); HOperatorSet.CountObj(ho_MarksCand, out hv_Number); if ((int)(new HTuple(hv_Number.TupleLess(4))) != 0) { ho_ImageMean.Dispose(); ho_RegionDynThresh.Dispose(); ho_RegionBorder.Dispose(); ho_RegionOpening1.Dispose(); ho_ConnectedRegions1.Dispose(); ho_SelectedRegions4.Dispose(); ho_SelectedRegions5.Dispose(); ho_RegionBorder2.Dispose(); ho_RegionTrans.Dispose(); ho_RegionErosion.Dispose(); ho_RegionBorder1.Dispose(); ho_RegionDilation2.Dispose(); ho_RegionDifference1.Dispose(); ho_RegionOpening.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions2.Dispose(); ho_SelectedRegions.Dispose(); ho_RegionFillUp.Dispose(); ho_SelectedRegions1.Dispose(); ho_RegionIntersection.Dispose(); ho_RegionFillUp1.Dispose(); ho_RegionDifference.Dispose(); ho_CaltabCandidates.Dispose(); ho_ObjectSelected.Dispose(); ho_ConnectedMarks.Dispose(); ho_ObjectSelectedCaltab.Dispose(); ho_RegionFillUpCand.Dispose(); ho_MarksCand.Dispose(); ho_RegionDilation1.Dispose(); ho_ImageReduced.Dispose(); ho_DefaultEdges.Dispose(); ho_UnionContours.Dispose(); ho_SelectedXLD.Dispose(); ho_SelectedXLD1.Dispose(); return; } hv_AreaMedian = ((hv_Area.TupleSort())).TupleSelect(hv_Number / 2); ho_Marks.Dispose(); HOperatorSet.SelectShapeXld(ho_MarksCand, out ho_Marks, "area", "and", hv_AreaMedian - (hv_AreaMedian * 0.5), hv_AreaMedian + (hv_AreaMedian * 0.5)); ho_ImageMean.Dispose(); ho_RegionDynThresh.Dispose(); ho_RegionBorder.Dispose(); ho_RegionOpening1.Dispose(); ho_ConnectedRegions1.Dispose(); ho_SelectedRegions4.Dispose(); ho_SelectedRegions5.Dispose(); ho_RegionBorder2.Dispose(); ho_RegionTrans.Dispose(); ho_RegionErosion.Dispose(); ho_RegionBorder1.Dispose(); ho_RegionDilation2.Dispose(); ho_RegionDifference1.Dispose(); ho_RegionOpening.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions2.Dispose(); ho_SelectedRegions.Dispose(); ho_RegionFillUp.Dispose(); ho_SelectedRegions1.Dispose(); ho_RegionIntersection.Dispose(); ho_RegionFillUp1.Dispose(); ho_RegionDifference.Dispose(); ho_CaltabCandidates.Dispose(); ho_ObjectSelected.Dispose(); ho_ConnectedMarks.Dispose(); ho_ObjectSelectedCaltab.Dispose(); ho_RegionFillUpCand.Dispose(); ho_MarksCand.Dispose(); ho_RegionDilation1.Dispose(); ho_ImageReduced.Dispose(); ho_DefaultEdges.Dispose(); ho_UnionContours.Dispose(); ho_SelectedXLD.Dispose(); ho_SelectedXLD1.Dispose(); return; }
/// <summary> /// Extracts the calibration plate and the marks on this plate /// for the supplied image /// </summary> public void find_caltab_edges(HObject ho_Image, out HObject ho_Caltab, out HObject ho_Marks, HTuple hv_DescriptionFileName) { // Stack for temporary objects HObject[] OTemp = new HObject[20]; long SP_O = 0; // Local iconic variables HObject ho_ImageMean, ho_RegionDynThresh, ho_RegionBorder; HObject ho_RegionOpening1, ho_ConnectedRegions1, ho_SelectedRegions4; HObject ho_SelectedRegions5, ho_RegionBorder2, ho_RegionTrans; HObject ho_RegionErosion, ho_RegionBorder1, ho_RegionDilation2; HObject ho_RegionDifference1, ho_RegionOpening, ho_ConnectedRegions; HObject ho_SelectedRegions2, ho_SelectedRegions, ho_RegionFillUp; HObject ho_SelectedRegions1, ho_RegionIntersection, ho_RegionFillUp1; HObject ho_RegionDifference, ho_CaltabCandidates, ho_ObjectSelected = null; HObject ho_ConnectedMarks = null, ho_ObjectSelectedCaltab = null; HObject ho_RegionFillUpCand, ho_MarksCand, ho_RegionDilation1; HObject ho_ImageReduced, ho_DefaultEdges, ho_UnionContours; HObject ho_SelectedXLD, ho_SelectedXLD1; // Local control variables HTuple hv_ExpDefaultCtrlDummyVar, hv_Width; HTuple hv_Height, hv_EstimatedCaltabSize, hv_EstimatedMarkSize; HTuple hv_Number, hv_X, hv_Y, hv_Z, hv_NumDescrMarks, hv_Index; HTuple hv_NumberMarks = new HTuple(), hv_Anisometry = new HTuple(); HTuple hv_Bulkiness = new HTuple(), hv_StructureFactor = new HTuple(); HTuple hv_AreaMarks = new HTuple(), hv_Row = new HTuple(); HTuple hv_Column = new HTuple(), hv_Rectangularity, hv_SortedIndex; HTuple hv_IndexBest, hv_MinContrast, hv_NumberCand, hv_Area; HTuple hv_Dummy, hv_DummyS, hv_AreaMedian; // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Caltab); HOperatorSet.GenEmptyObj(out ho_Marks); HOperatorSet.GenEmptyObj(out ho_ImageMean); HOperatorSet.GenEmptyObj(out ho_RegionDynThresh); HOperatorSet.GenEmptyObj(out ho_RegionBorder); HOperatorSet.GenEmptyObj(out ho_RegionOpening1); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions1); HOperatorSet.GenEmptyObj(out ho_SelectedRegions4); HOperatorSet.GenEmptyObj(out ho_SelectedRegions5); HOperatorSet.GenEmptyObj(out ho_RegionBorder2); HOperatorSet.GenEmptyObj(out ho_RegionTrans); HOperatorSet.GenEmptyObj(out ho_RegionErosion); HOperatorSet.GenEmptyObj(out ho_RegionBorder1); HOperatorSet.GenEmptyObj(out ho_RegionDilation2); HOperatorSet.GenEmptyObj(out ho_RegionDifference1); HOperatorSet.GenEmptyObj(out ho_RegionOpening); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions); HOperatorSet.GenEmptyObj(out ho_SelectedRegions2); HOperatorSet.GenEmptyObj(out ho_SelectedRegions); HOperatorSet.GenEmptyObj(out ho_RegionFillUp); HOperatorSet.GenEmptyObj(out ho_SelectedRegions1); HOperatorSet.GenEmptyObj(out ho_RegionIntersection); HOperatorSet.GenEmptyObj(out ho_RegionFillUp1); HOperatorSet.GenEmptyObj(out ho_RegionDifference); HOperatorSet.GenEmptyObj(out ho_CaltabCandidates); HOperatorSet.GenEmptyObj(out ho_ObjectSelected); HOperatorSet.GenEmptyObj(out ho_ConnectedMarks); HOperatorSet.GenEmptyObj(out ho_ObjectSelectedCaltab); HOperatorSet.GenEmptyObj(out ho_RegionFillUpCand); HOperatorSet.GenEmptyObj(out ho_MarksCand); HOperatorSet.GenEmptyObj(out ho_RegionDilation1); HOperatorSet.GenEmptyObj(out ho_ImageReduced); HOperatorSet.GenEmptyObj(out ho_DefaultEdges); HOperatorSet.GenEmptyObj(out ho_UnionContours); HOperatorSet.GenEmptyObj(out ho_SelectedXLD); HOperatorSet.GenEmptyObj(out ho_SelectedXLD1); // ho_Marks.Dispose(); HOperatorSet.GenEmptyObj(out ho_Marks); ho_Caltab.Dispose(); HOperatorSet.GenEmptyObj(out ho_Caltab); HOperatorSet.GetImagePointer1(ho_Image, out hv_ExpDefaultCtrlDummyVar, out hv_ExpDefaultCtrlDummyVar, out hv_Width, out hv_Height); hv_EstimatedCaltabSize = (((((hv_Width.TupleConcat(hv_Height))).TupleMax()) / 2.5)).TupleRound() ; hv_EstimatedMarkSize = ((hv_EstimatedCaltabSize / 12.0)).TupleRound(); ho_ImageMean.Dispose(); HOperatorSet.MeanImage(ho_Image, out ho_ImageMean, hv_EstimatedMarkSize * 3, hv_EstimatedMarkSize * 3); ho_RegionDynThresh.Dispose(); HOperatorSet.DynThreshold(ho_Image, ho_ImageMean, out ho_RegionDynThresh, 3, "light"); ho_RegionBorder.Dispose(); HOperatorSet.DynThreshold(ho_Image, ho_ImageMean, out ho_RegionBorder, 20, "dark"); ho_RegionOpening1.Dispose(); HOperatorSet.OpeningCircle(ho_RegionBorder, out ho_RegionOpening1, 1.5); ho_ConnectedRegions1.Dispose(); HOperatorSet.Connection(ho_RegionOpening1, out ho_ConnectedRegions1); ho_SelectedRegions4.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions1, out ho_SelectedRegions4, "compactness", "and", 17, 50); ho_SelectedRegions5.Dispose(); HOperatorSet.SelectShape(ho_SelectedRegions4, out ho_SelectedRegions5, "anisometry", "and", 1, 1.4); ho_RegionBorder2.Dispose(); HOperatorSet.Boundary(ho_SelectedRegions5, out ho_RegionBorder2, "outer"); ho_SelectedRegions5.Dispose(); HOperatorSet.SelectShape(ho_RegionBorder2, out ho_SelectedRegions5, "circularity", "and", 0.006, 1); ho_RegionTrans.Dispose(); HOperatorSet.ShapeTrans(ho_SelectedRegions5, out ho_RegionTrans, "rectangle2"); ho_RegionErosion.Dispose(); HOperatorSet.ErosionCircle(ho_RegionTrans, out ho_RegionErosion, (hv_Width / 640.0) * 5.5); ho_RegionBorder1.Dispose(); HOperatorSet.Boundary(ho_RegionErosion, out ho_RegionBorder1, "inner"); ho_RegionDilation2.Dispose(); HOperatorSet.DilationCircle(ho_RegionBorder1, out ho_RegionDilation2, 3.5); ho_RegionDifference1.Dispose(); HOperatorSet.Difference(ho_RegionDynThresh, ho_RegionDilation2, out ho_RegionDifference1 ); ho_RegionOpening.Dispose(); HOperatorSet.OpeningCircle(ho_RegionDifference1, out ho_RegionOpening, (hv_Width / 640) * 1.5); ho_ConnectedRegions.Dispose(); HOperatorSet.Connection(ho_RegionOpening, out ho_ConnectedRegions); ho_SelectedRegions2.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions2, "area", "and", (hv_EstimatedCaltabSize.TuplePow(2)) / 10, (hv_EstimatedCaltabSize.TuplePow( 2)) * 5); ho_SelectedRegions.Dispose(); HOperatorSet.SelectShape(ho_SelectedRegions2, out ho_SelectedRegions, "compactness", "and", 1.4, 10); ho_RegionFillUp.Dispose(); HOperatorSet.FillUp(ho_SelectedRegions, out ho_RegionFillUp); ho_SelectedRegions1.Dispose(); HOperatorSet.SelectShape(ho_RegionFillUp, out ho_SelectedRegions1, "rectangularity", "and", 0.6, 1); ho_RegionIntersection.Dispose(); HOperatorSet.Intersection(ho_SelectedRegions1, ho_RegionDynThresh, out ho_RegionIntersection ); ho_RegionFillUp1.Dispose(); HOperatorSet.FillUp(ho_RegionIntersection, out ho_RegionFillUp1); ho_RegionDifference.Dispose(); HOperatorSet.Difference(ho_RegionFillUp1, ho_RegionIntersection, out ho_RegionDifference ); HOperatorSet.CountObj(ho_RegionDifference, out hv_Number); ho_CaltabCandidates.Dispose(); HOperatorSet.GenEmptyObj(out ho_CaltabCandidates); HOperatorSet.CaltabPoints(hv_DescriptionFileName, out hv_X, out hv_Y, out hv_Z); hv_NumDescrMarks = new HTuple(hv_X.TupleLength()); for (hv_Index = 1; hv_Index.Continue(hv_Number, 1); hv_Index = hv_Index.TupleAdd(1)) { ho_ObjectSelected.Dispose(); HOperatorSet.SelectObj(ho_RegionDifference, out ho_ObjectSelected, hv_Index); ho_ConnectedMarks.Dispose(); HOperatorSet.Connection(ho_ObjectSelected, out ho_ConnectedMarks); HOperatorSet.CountObj(ho_ConnectedMarks, out hv_NumberMarks); HOperatorSet.Eccentricity(ho_ConnectedMarks, out hv_Anisometry, out hv_Bulkiness, out hv_StructureFactor); HOperatorSet.AreaCenter(ho_ConnectedMarks, out hv_AreaMarks, out hv_Row, out hv_Column); ho_ObjectSelectedCaltab.Dispose(); HOperatorSet.SelectObj(ho_RegionIntersection, out ho_ObjectSelectedCaltab, hv_Index); if ((int)((new HTuple((new HTuple((new HTuple(hv_NumberMarks.TupleGreaterEqual( 10))).TupleAnd(new HTuple(hv_NumberMarks.TupleLess(hv_NumDescrMarks + 20))))).TupleAnd( new HTuple(((((hv_Anisometry.TupleSort())).TupleSelect((new HTuple(hv_Anisometry.TupleLength() )) / 2))).TupleLess(2))))).TupleAnd(new HTuple((new HTuple(hv_AreaMarks.TupleMean() )).TupleGreater(20)))) != 0) { OTemp[SP_O] = ho_CaltabCandidates.CopyObj(1, -1); SP_O++; ho_CaltabCandidates.Dispose(); HOperatorSet.ConcatObj(OTemp[SP_O - 1], ho_ObjectSelectedCaltab, out ho_CaltabCandidates ); OTemp[SP_O - 1].Dispose(); SP_O = 0; } } ho_RegionFillUpCand.Dispose(); HOperatorSet.FillUp(ho_CaltabCandidates, out ho_RegionFillUpCand); HOperatorSet.Rectangularity(ho_RegionFillUpCand, out hv_Rectangularity); if ((int)(new HTuple((new HTuple(hv_Rectangularity.TupleLength())).TupleEqual( 0))) != 0) { ho_ImageMean.Dispose(); ho_RegionDynThresh.Dispose(); ho_RegionBorder.Dispose(); ho_RegionOpening1.Dispose(); ho_ConnectedRegions1.Dispose(); ho_SelectedRegions4.Dispose(); ho_SelectedRegions5.Dispose(); ho_RegionBorder2.Dispose(); ho_RegionTrans.Dispose(); ho_RegionErosion.Dispose(); ho_RegionBorder1.Dispose(); ho_RegionDilation2.Dispose(); ho_RegionDifference1.Dispose(); ho_RegionOpening.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions2.Dispose(); ho_SelectedRegions.Dispose(); ho_RegionFillUp.Dispose(); ho_SelectedRegions1.Dispose(); ho_RegionIntersection.Dispose(); ho_RegionFillUp1.Dispose(); ho_RegionDifference.Dispose(); ho_CaltabCandidates.Dispose(); ho_ObjectSelected.Dispose(); ho_ConnectedMarks.Dispose(); ho_ObjectSelectedCaltab.Dispose(); ho_RegionFillUpCand.Dispose(); ho_MarksCand.Dispose(); ho_RegionDilation1.Dispose(); ho_ImageReduced.Dispose(); ho_DefaultEdges.Dispose(); ho_UnionContours.Dispose(); ho_SelectedXLD.Dispose(); ho_SelectedXLD1.Dispose(); return; } hv_SortedIndex = hv_Rectangularity.TupleSortIndex(); hv_IndexBest = (((hv_SortedIndex.TupleInverse())).TupleSelect(0)) + 1; ho_Caltab.Dispose(); HOperatorSet.SelectObj(ho_RegionFillUpCand, out ho_Caltab, hv_IndexBest); ho_RegionFillUp.Dispose(); HOperatorSet.FillUp(ho_Caltab, out ho_RegionFillUp); ho_MarksCand.Dispose(); HOperatorSet.Difference(ho_RegionFillUp, ho_RegionDynThresh, out ho_MarksCand ); ho_RegionBorder.Dispose(); HOperatorSet.Boundary(ho_MarksCand, out ho_RegionBorder, "inner"); ho_RegionDilation1.Dispose(); HOperatorSet.DilationCircle(ho_RegionBorder, out ho_RegionDilation1, 9.5); ho_ImageReduced.Dispose(); HOperatorSet.ReduceDomain(ho_Image, ho_RegionDilation1, out ho_ImageReduced); hv_MinContrast = 10; ho_DefaultEdges.Dispose(); HOperatorSet.EdgesSubPix(ho_ImageReduced, out ho_DefaultEdges, "canny", 2, hv_MinContrast / 2, hv_MinContrast); HOperatorSet.CountObj(ho_DefaultEdges, out hv_NumberCand); if ((int)(new HTuple(hv_NumberCand.TupleLess(10))) != 0) { ho_ImageMean.Dispose(); ho_RegionDynThresh.Dispose(); ho_RegionBorder.Dispose(); ho_RegionOpening1.Dispose(); ho_ConnectedRegions1.Dispose(); ho_SelectedRegions4.Dispose(); ho_SelectedRegions5.Dispose(); ho_RegionBorder2.Dispose(); ho_RegionTrans.Dispose(); ho_RegionErosion.Dispose(); ho_RegionBorder1.Dispose(); ho_RegionDilation2.Dispose(); ho_RegionDifference1.Dispose(); ho_RegionOpening.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions2.Dispose(); ho_SelectedRegions.Dispose(); ho_RegionFillUp.Dispose(); ho_SelectedRegions1.Dispose(); ho_RegionIntersection.Dispose(); ho_RegionFillUp1.Dispose(); ho_RegionDifference.Dispose(); ho_CaltabCandidates.Dispose(); ho_ObjectSelected.Dispose(); ho_ConnectedMarks.Dispose(); ho_ObjectSelectedCaltab.Dispose(); ho_RegionFillUpCand.Dispose(); ho_MarksCand.Dispose(); ho_RegionDilation1.Dispose(); ho_ImageReduced.Dispose(); ho_DefaultEdges.Dispose(); ho_UnionContours.Dispose(); ho_SelectedXLD.Dispose(); ho_SelectedXLD1.Dispose(); return; } ho_UnionContours.Dispose(); HOperatorSet.UnionCocircularContoursXld(ho_DefaultEdges, out ho_UnionContours, 0.5, 0.1, 0.2, 30, 10, 10, "true", 1); ho_SelectedXLD.Dispose(); HOperatorSet.SelectShapeXld(ho_UnionContours, out ho_SelectedXLD, "area", "and", 30, 10000); ho_SelectedXLD1.Dispose(); HOperatorSet.SelectShapeXld(ho_SelectedXLD, out ho_SelectedXLD1, "circularity", "and", 0.4, 1); ho_MarksCand.Dispose(); HOperatorSet.SelectShapeXld(ho_SelectedXLD1, out ho_MarksCand, "compactness", "and", 1, 1.5); HOperatorSet.AreaCenterXld(ho_MarksCand, out hv_Area, out hv_Dummy, out hv_Dummy, out hv_DummyS); HOperatorSet.CountObj(ho_MarksCand, out hv_Number); if ((int)(new HTuple(hv_Number.TupleLess(4))) != 0) { ho_ImageMean.Dispose(); ho_RegionDynThresh.Dispose(); ho_RegionBorder.Dispose(); ho_RegionOpening1.Dispose(); ho_ConnectedRegions1.Dispose(); ho_SelectedRegions4.Dispose(); ho_SelectedRegions5.Dispose(); ho_RegionBorder2.Dispose(); ho_RegionTrans.Dispose(); ho_RegionErosion.Dispose(); ho_RegionBorder1.Dispose(); ho_RegionDilation2.Dispose(); ho_RegionDifference1.Dispose(); ho_RegionOpening.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions2.Dispose(); ho_SelectedRegions.Dispose(); ho_RegionFillUp.Dispose(); ho_SelectedRegions1.Dispose(); ho_RegionIntersection.Dispose(); ho_RegionFillUp1.Dispose(); ho_RegionDifference.Dispose(); ho_CaltabCandidates.Dispose(); ho_ObjectSelected.Dispose(); ho_ConnectedMarks.Dispose(); ho_ObjectSelectedCaltab.Dispose(); ho_RegionFillUpCand.Dispose(); ho_MarksCand.Dispose(); ho_RegionDilation1.Dispose(); ho_ImageReduced.Dispose(); ho_DefaultEdges.Dispose(); ho_UnionContours.Dispose(); ho_SelectedXLD.Dispose(); ho_SelectedXLD1.Dispose(); return; } hv_AreaMedian = ((hv_Area.TupleSort())).TupleSelect(hv_Number / 2); ho_Marks.Dispose(); HOperatorSet.SelectShapeXld(ho_MarksCand, out ho_Marks, "area", "and", hv_AreaMedian - (hv_AreaMedian * 0.5), hv_AreaMedian + (hv_AreaMedian * 0.5)); ho_ImageMean.Dispose(); ho_RegionDynThresh.Dispose(); ho_RegionBorder.Dispose(); ho_RegionOpening1.Dispose(); ho_ConnectedRegions1.Dispose(); ho_SelectedRegions4.Dispose(); ho_SelectedRegions5.Dispose(); ho_RegionBorder2.Dispose(); ho_RegionTrans.Dispose(); ho_RegionErosion.Dispose(); ho_RegionBorder1.Dispose(); ho_RegionDilation2.Dispose(); ho_RegionDifference1.Dispose(); ho_RegionOpening.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions2.Dispose(); ho_SelectedRegions.Dispose(); ho_RegionFillUp.Dispose(); ho_SelectedRegions1.Dispose(); ho_RegionIntersection.Dispose(); ho_RegionFillUp1.Dispose(); ho_RegionDifference.Dispose(); ho_CaltabCandidates.Dispose(); ho_ObjectSelected.Dispose(); ho_ConnectedMarks.Dispose(); ho_ObjectSelectedCaltab.Dispose(); ho_RegionFillUpCand.Dispose(); ho_MarksCand.Dispose(); ho_RegionDilation1.Dispose(); ho_ImageReduced.Dispose(); ho_DefaultEdges.Dispose(); ho_UnionContours.Dispose(); ho_SelectedXLD.Dispose(); ho_SelectedXLD1.Dispose(); return; }
public void GetParallelLineFromDistance(HTuple hv_LineInRow, HTuple hv_LineInCol, HTuple hv_LineInRow1, HTuple hv_LineInCol1, HTuple hv_Distance, HTuple hv_Direction, HTuple hv_Polarity, out HTuple hv_LineOutRow, out HTuple hv_LineOutCol, out HTuple hv_LineOutRow1, out HTuple hv_LineOutCol1, out HTuple hv_k, out HTuple hv_b) { // Local control variables HTuple hv_RealDeltaCol, hv_RealDeltaRow, hv_kIn; HTuple hv_bIn, hv_k1, hv_b1, hv_k2, hv_b2, hv_Sqrt1, hv_Sqrt2; HTuple hv_row1, hv_col1, hv_rowTemp1, hv_colTemp1, hv_row2; HTuple hv_col2, hv_rowTemp2, hv_colTemp2; // Initialize local and output iconic variables hv_LineOutRow = new HTuple(); hv_LineOutCol = new HTuple(); hv_LineOutRow1 = new HTuple(); hv_LineOutCol1 = new HTuple(); HOperatorSet.TupleReal(hv_LineInCol1 - hv_LineInCol, out hv_RealDeltaCol); HOperatorSet.TupleReal(hv_LineInRow1 - hv_LineInRow, out hv_RealDeltaRow); hv_kIn = hv_RealDeltaCol / hv_RealDeltaRow; hv_bIn = hv_LineInCol - (hv_kIn * hv_LineInRow); hv_k = hv_kIn.Clone(); hv_b = hv_bIn.Clone(); hv_k1 = -1 / hv_kIn; hv_b1 = ((hv_LineInRow * hv_kIn) + hv_bIn) - (hv_k1 * hv_LineInRow); hv_k2 = hv_k1.Clone(); hv_b2 = ((hv_LineInRow1 * hv_kIn) + hv_bIn) - (hv_k2 * hv_LineInRow1); //找出目标点 HOperatorSet.TupleSqrt((hv_Distance * hv_Distance) / ((hv_k1 * hv_k1) + 1), out hv_Sqrt1); HOperatorSet.TupleSqrt((hv_Distance * hv_Distance) / ((hv_k2 * hv_k2) + 1), out hv_Sqrt2); hv_row1 = hv_Sqrt1 + hv_LineInRow; hv_col1 = (hv_k1 * hv_row1) + hv_b1; hv_rowTemp1 = hv_Sqrt2 + hv_LineInRow1; hv_colTemp1 = (hv_k2 * hv_rowTemp1) + hv_b2; //另一条平行线 hv_row2 = (-hv_Sqrt1) + hv_LineInRow; hv_col2 = (hv_k1 * hv_row2) + hv_b1; hv_rowTemp2 = (-hv_Sqrt2) + hv_LineInRow1; hv_colTemp2 = (hv_k2 * hv_rowTemp2) + hv_b2; if ((int)(new HTuple(hv_Direction.TupleEqual("row"))) != 0) { if ((int)(new HTuple(hv_Polarity.TupleGreaterEqual(0))) != 0) { hv_LineOutRow = hv_row1.Clone(); hv_LineOutCol = hv_col1.Clone(); hv_LineOutRow1 = hv_rowTemp1.Clone(); hv_LineOutCol1 = hv_colTemp1.Clone(); } else { hv_LineOutRow = hv_row2.Clone(); hv_LineOutCol = hv_col2.Clone(); hv_LineOutRow1 = hv_rowTemp2.Clone(); hv_LineOutCol1 = hv_colTemp2.Clone(); } } if ((int)(new HTuple(hv_Direction.TupleEqual("col"))) != 0) { if ((int)(new HTuple(hv_Polarity.TupleGreaterEqual(0))) != 0) { if ((int)(new HTuple(hv_col1.TupleGreaterEqual(hv_LineInCol))) != 0) { hv_LineOutCol = hv_col1.Clone(); hv_LineOutRow = hv_row1.Clone(); hv_LineOutRow1 = hv_rowTemp1.Clone(); hv_LineOutCol1 = hv_colTemp1.Clone(); } else { hv_LineOutCol = hv_col2.Clone(); hv_LineOutRow = hv_row2.Clone(); hv_LineOutRow1 = hv_rowTemp2.Clone(); hv_LineOutCol1 = hv_colTemp2.Clone(); } } else { if ((int)(new HTuple(hv_col1.TupleGreaterEqual(hv_LineInCol))) != 0) { hv_LineOutCol = hv_col2.Clone(); hv_LineOutRow = hv_row2.Clone(); hv_LineOutRow1 = hv_rowTemp2.Clone(); hv_LineOutCol1 = hv_colTemp2.Clone(); } else { hv_LineOutCol = hv_col1.Clone(); hv_LineOutRow = hv_row1.Clone(); hv_LineOutRow1 = hv_rowTemp1.Clone(); hv_LineOutCol1 = hv_colTemp1.Clone(); } } } return; }
// Local procedures public void GetVerticalFromDistance(HTuple hv_FootRow, HTuple hv_FootCol, HTuple hv_LineRowStart, HTuple hv_LineColStart, HTuple hv_LineRowEnd, HTuple hv_LineColEnd, HTuple hv_Distance, HTuple hv_Direction, HTuple hv_Polarity, out HTuple hv_TargetRow, out HTuple hv_TargetCol, out HTuple hv_k, out HTuple hv_b, out HTuple hv_kIn, out HTuple hv_bIn) { // Local control variables HTuple hv_RealDeltaCol, hv_RealDeltaRow, hv_Sqrt; HTuple hv_row1, hv_col1, hv_row2, hv_col2, hv_TargetCo1 = new HTuple(); // Initialize local and output iconic variables hv_TargetRow = new HTuple(); hv_TargetCol = new HTuple(); HOperatorSet.TupleReal(hv_LineColEnd - hv_LineColStart, out hv_RealDeltaCol); HOperatorSet.TupleReal(hv_LineRowEnd - hv_LineRowStart, out hv_RealDeltaRow); hv_kIn = hv_RealDeltaCol / hv_RealDeltaRow; hv_bIn = hv_FootCol - (hv_kIn * hv_FootRow); hv_k = -1 / hv_kIn; hv_b = ((hv_FootRow * hv_kIn) + hv_bIn) - (hv_k * hv_FootRow); //找出目标点 HOperatorSet.TupleSqrt((hv_Distance * hv_Distance) / ((hv_k * hv_k) + 1), out hv_Sqrt); hv_row1 = hv_Sqrt + hv_FootRow; hv_col1 = (hv_k * hv_row1) + hv_b; hv_row2 = (-hv_Sqrt) + hv_FootRow; hv_col2 = (hv_k * hv_row2) + hv_b; if ((int)(new HTuple(hv_Direction.TupleEqual("row"))) != 0) { if ((int)(new HTuple(hv_Polarity.TupleGreaterEqual(0))) != 0) { hv_TargetRow = hv_row1.Clone(); hv_TargetCol = hv_col1.Clone(); } else { hv_TargetRow = hv_row2.Clone(); hv_TargetCol = hv_col2.Clone(); } } if ((int)(new HTuple(hv_Direction.TupleEqual("col"))) != 0) { if ((int)(new HTuple(hv_Polarity.TupleGreaterEqual(0))) != 0) { if ((int)(new HTuple(hv_col1.TupleGreaterEqual(hv_FootCol))) != 0) { hv_TargetCo1 = hv_col1.Clone(); hv_TargetRow = hv_row1.Clone(); } else { hv_TargetCo1 = hv_col2.Clone(); hv_TargetRow = hv_row1.Clone(); } } else { if ((int)(new HTuple(hv_col1.TupleGreaterEqual(hv_FootCol))) != 0) { hv_TargetCo1 = hv_col2.Clone(); hv_TargetRow = hv_row2.Clone(); } else { hv_TargetCo1 = hv_col1.Clone(); hv_TargetRow = hv_row1.Clone(); } } } return; }
// Main procedure private void RunPick(bool leftpallet, bool lastlayer) { // Stack for temporary objects HObject[] OTemp = new HObject[20]; // Local iconic variables HObject ho_Image, ho_ImageRectified = null, ho_FOV; HObject ho_Box, ho_ImageReduced, ho_Objects, ho_Cross = null; HObject ho_GripPoint = null, ho_ImageReducedGripPoint = null; HObject ho_ImageMedian = null, ho_ObjectGripPoint = null, ho_Cross1 = null; HObject ho_Arrow = null, ho_Cross2 = null, ho_ContCircle; // Local control variables HTuple hv_AcqHandle = null, hv_pi = null, hv_angle = null; HTuple hv_CamParam = null, hv_CamPose = null, hv_GMMHandle = null; HTuple hv_Width = null, hv_Height = null, hv_CamParamOut = null; HTuple hv_Classes1 = null, hv_Row1 = null, hv_Column1 = null; HTuple hv_Row2 = null, hv_Column2 = null, hv_Diameter = null; HTuple hv_Area1 = null, hv_Row3 = null, hv_Column3 = null; HTuple hv_len_area = null, hv_MAX = new HTuple(), hv_index = new HTuple(); HTuple hv_out = new HTuple(), hv_Length = new HTuple(); HTuple hv_i = new HTuple(), hv_INDEX = new HTuple(), hv_j = new HTuple(); HTuple hv_pom = new HTuple(), hv_DevDia = new HTuple(); HTuple hv_joint = new HTuple(), hv_x_ = new HTuple(), hv_y_ = new HTuple(); HTuple hv_w_ = new HTuple(), hv_a = new HTuple(), hv_b = new HTuple(); HTuple hv_k = new HTuple(), hv_x_cross = new HTuple(); HTuple hv_y_cross = new HTuple(), hv_WorldPose = new HTuple(); HTuple hv_HomMat3D = new HTuple(), hv_HomMat3DRotate = new HTuple(); HTuple hv_Area2 = new HTuple(); HTuple hv_Row5 = new HTuple(), hv_Column5 = new HTuple(); HTuple hv_SumX = new HTuple(), hv_SumY = new HTuple(); HTuple hv_GripPointX = new HTuple(), hv_GripPointY = new HTuple(); HTuple hv_maxdist = new HTuple(), hv_distgrippoints = new HTuple(); HTuple hv_indexgrip = new HTuple(), hv_distgrip = new HTuple(); HTuple hv_OrientX = new HTuple(), hv_OrientY = new HTuple(); HTuple hv_maxX = new HTuple(), hv_diff01 = new HTuple(); HTuple hv_diff02 = new HTuple(), hv_diff12 = new HTuple(); HTuple hv_mindiff = new HTuple(), hv_GX = new HTuple(); HTuple hv_GY = new HTuple(), hv_OX = new HTuple(), hv_OY = new HTuple(); HTuple hv_DY = new HTuple(), hv_DX = new HTuple(), hv_theta = new HTuple(); HTuple hv_anglerad = new HTuple(); // HTuple hv_Pixel1Y = new HTuple(), hv_Pixel2X = new HTuple(), hv_Pixel1X = new HTuple(); HTuple hv_Pixel2Y = new HTuple(), hv_distance = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Image); HOperatorSet.GenEmptyObj(out ho_ImageRectified); HOperatorSet.GenEmptyObj(out ho_FOV); HOperatorSet.GenEmptyObj(out ho_Box); HOperatorSet.GenEmptyObj(out ho_ImageReduced); HOperatorSet.GenEmptyObj(out ho_Objects); HOperatorSet.GenEmptyObj(out ho_Cross); HOperatorSet.GenEmptyObj(out ho_GripPoint); HOperatorSet.GenEmptyObj(out ho_ImageReducedGripPoint); HOperatorSet.GenEmptyObj(out ho_ImageMedian); HOperatorSet.GenEmptyObj(out ho_ObjectGripPoint); HOperatorSet.GenEmptyObj(out ho_Cross1); HOperatorSet.GenEmptyObj(out ho_Arrow); HOperatorSet.GenEmptyObj(out ho_Cross2); HOperatorSet.GenEmptyObj(out ho_ContCircle); // Set Default Variables hv_angledeg = 0; // Wait for CAM4 thread to be closed _waitHandleCam1.WaitOne(); // Close te thread DOOR _waitHandleCam1.Reset(); //Image Acquisition try { HOperatorSet.OpenFramegrabber("GigEVision", 0, 0, 0, 0, 0, 0, "default", -1, "default", -1, "false", "default", "RobotPick", 0, -1, out hv_AcqHandleCam1); HOperatorSet.SetFramegrabberParam(hv_AcqHandleCam1, "ExposureAuto", "Continuous"); } catch (HalconException exceptionCameraNotConnected) { } // Constants hv_pi = 3.14159265359; hv_angle = (0 * hv_pi) / 180; // Pallet calibration selection if (leftpallet) { // Relative path to file string IntrinsicsFileName = "CamParametersLeft.cal"; string IntrinsicsPath = Path.Combine(Environment.CurrentDirectory, @"CamPar", IntrinsicsFileName); // string ExtrinsicsFileName = "CamPoseLeft.dat"; string ExtrinsicsPath = Path.Combine(Environment.CurrentDirectory, @"CamPar", ExtrinsicsFileName); HOperatorSet.ReadCamPar(IntrinsicsPath, out hv_CamParam); HOperatorSet.ReadPose(ExtrinsicsPath, out hv_CamPose); } else { // Relative path to file string IntrinsicsFileName = "CamParametersRight.cal"; string IntrinsicsPath = Path.Combine(Environment.CurrentDirectory, @"CamPar", IntrinsicsFileName); // string ExtrinsicsFileName = "CamPoseRight.dat"; string ExtrinsicsPath = Path.Combine(Environment.CurrentDirectory, @"CamPar", ExtrinsicsFileName); HOperatorSet.ReadCamPar(IntrinsicsPath, out hv_CamParam); HOperatorSet.ReadPose(ExtrinsicsPath, out hv_CamPose); } // string TrainegGmmFileName = "traineg_gmm_pick_1.4.ggc"; string TrainegGmmPath = Path.Combine(Environment.CurrentDirectory, @"Train", TrainegGmmFileName); // Camera intrinsics and extrinsics call HOperatorSet.ReadClassGmm(TrainegGmmPath, out hv_GMMHandle); // Grab operator ho_Image.Dispose(); HOperatorSet.GrabImage(out ho_Image, hv_AcqHandleCam1); HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height); ho_FOV.Dispose(); HOperatorSet.GenRectangle1(out ho_FOV, 0, 0, hv_Height, hv_Width); ho_Box.Dispose(); if (leftpallet) { HOperatorSet.GenRectangle1(out ho_Box, 190, 160, 870, 1130); } else { HOperatorSet.GenRectangle1(out ho_Box, 190, 160, 870, 1130); } HOperatorSet.ChangeRadialDistortionCamPar("adaptive", hv_CamParam, 0, out hv_CamParamOut); ho_ImageRectified.Dispose(); HOperatorSet.ChangeRadialDistortionImage(ho_Image, ho_FOV, out ho_ImageRectified, hv_CamParam, hv_CamParamOut); ho_ImageReduced.Dispose(); HOperatorSet.ReduceDomain(ho_ImageRectified, ho_Box, out ho_ImageReduced); ho_ImageRectified.Dispose(); HOperatorSet.Illuminate(ho_ImageReduced, out ho_ImageRectified, 230, 230, 1.15); ho_ImageMedian.Dispose(); HOperatorSet.MedianImage(ho_ImageRectified, out ho_ImageRectified, "circle", 3, "mirrored"); ho_ObjectGripPoint.Dispose(); //segmentacija i klasifikacija ho_Objects.Dispose(); segment(ho_ImageRectified, out ho_Objects); classify(ho_Objects, hv_GMMHandle, out hv_Classes1); disp_obj_class(ho_Objects, hv_Classes1); { HObject ExpTmpOutVar_0; HOperatorSet.Connection(ho_Objects, out ExpTmpOutVar_0); ho_Objects.Dispose(); ho_Objects = ExpTmpOutVar_0; } //prefiltriranje klasificiranih predmeta { HObject ExpTmpOutVar_0; HOperatorSet.SelectShape(ho_Objects, out ExpTmpOutVar_0, "circularity", "and", 0.5, 1.0); ho_Objects.Dispose(); ho_Objects = ExpTmpOutVar_0; } { HObject ExpTmpOutVar_0; HOperatorSet.SelectShape(ho_Objects, out ExpTmpOutVar_0, "area", "and", 1000, 100000); ho_Objects.Dispose(); ho_Objects = ExpTmpOutVar_0; } //** Carolija *** HOperatorSet.DiameterRegion(ho_Objects, out hv_Row1, out hv_Column1, out hv_Row2, out hv_Column2, out hv_Diameter); HOperatorSet.AreaCenter(ho_Objects, out hv_Area1, out hv_Row3, out hv_Column3); HOperatorSet.TupleLength(hv_Area1, out hv_len_area); //* If objects exist sort them and find their 2D position if ((int)(new HTuple(hv_len_area.TupleGreater(0))) != 0) { hv_MAX = 0; hv_index = 0; hv_out = 0; HOperatorSet.TupleLength(hv_Diameter, out hv_Length); HOperatorSet.DispObj(ho_ImageRectified, hv_ExpDefaultWinHandle); HOperatorSet.DispLine(hv_ExpDefaultWinHandle, hv_Height / 2, 0, hv_Height / 2, hv_Width); HOperatorSet.DispLine(hv_ExpDefaultWinHandle, 0, hv_Width / 2, hv_Height, hv_Width / 2); hv_i = 1; HOperatorSet.TupleGenSequence(0, hv_Length - 1, 1, out hv_INDEX); while ((int)(new HTuple(hv_i.TupleLess(hv_Length))) != 0) { hv_j = hv_i.Clone(); while ((int)(new HTuple(((hv_Diameter.TupleSelect(hv_j - 1))).TupleLess(hv_Diameter.TupleSelect(hv_j)))) != 0) { hv_pom = hv_Diameter.TupleSelect(hv_j); if (hv_Diameter == null) { hv_Diameter = new HTuple(); } hv_Diameter[hv_j] = hv_Diameter.TupleSelect(hv_j - 1); if (hv_Diameter == null) { hv_Diameter = new HTuple(); } hv_Diameter[hv_j - 1] = hv_pom; hv_pom = hv_INDEX.TupleSelect(hv_j); if (hv_INDEX == null) { hv_INDEX = new HTuple(); } hv_INDEX[hv_j] = hv_INDEX.TupleSelect(hv_j - 1); if (hv_INDEX == null) { hv_INDEX = new HTuple(); } hv_INDEX[hv_j - 1] = hv_pom; hv_j = hv_j - 1; if ((int)(new HTuple(hv_j.TupleEqual(0))) != 0) { break; } } hv_i = hv_i + 1; } HOperatorSet.TupleMedian(hv_Diameter, out hv_MAX); HOperatorSet.TupleDeviation(hv_Diameter, out hv_DevDia); HTuple end_val75 = hv_Length; HTuple step_val75 = 1; for (hv_i = 1; hv_i.Continue(end_val75, step_val75); hv_i = hv_i.TupleAdd(step_val75)) { if ((int)((new HTuple(((hv_Diameter.TupleSelect(hv_i - 1))).TupleGreaterEqual( hv_MAX - (5 * hv_DevDia)))).TupleAnd(new HTuple(((hv_Diameter.TupleSelect( hv_i - 1))).TupleLessEqual(hv_MAX + (5 * hv_DevDia))))) != 0) { if ((int)(new HTuple(hv_MAX.TupleGreaterEqual(2 * 300))) != 0) { hv_joint = 1; } hv_index = hv_index + 1; } } //* w_ => weight factor for L1 norm ** //* row component weighting a => sort by column ** //* column component weighting b => sort by row ** hv_x_ = new HTuple(); hv_y_ = new HTuple(); hv_w_ = new HTuple(); hv_a = 0.2; hv_b = 1.0; HTuple end_val93 = hv_index; HTuple step_val93 = 1; for (hv_k = 1; hv_k.Continue(end_val93, step_val93); hv_k = hv_k.TupleAdd(step_val93)) { if (hv_x_ == null) { hv_x_ = new HTuple(); } hv_x_[hv_k - 1] = hv_Row3.TupleSelect(hv_k - 1); if (hv_y_ == null) { hv_y_ = new HTuple(); } hv_y_[hv_k - 1] = hv_Column3.TupleSelect(hv_k - 1); if (hv_w_ == null) { hv_w_ = new HTuple(); } hv_w_[hv_k - 1] = ((hv_x_.TupleSelect(hv_k - 1)) * hv_a) + ((hv_y_.TupleSelect(hv_k - 1)) * hv_b); } //* Sort objects by cost value ** hv_i = 1; while ((int)(new HTuple(hv_i.TupleLess(hv_index))) != 0) { hv_j = hv_i.Clone(); while ((int)(new HTuple(((hv_w_.TupleSelect(hv_j - 1))).TupleGreater(hv_w_.TupleSelect(hv_j)))) != 0) { hv_pom = hv_x_.TupleSelect(hv_j); if (hv_x_ == null) { hv_x_ = new HTuple(); } hv_x_[hv_j] = hv_x_.TupleSelect(hv_j - 1); if (hv_x_ == null) { hv_x_ = new HTuple(); } hv_x_[hv_j - 1] = hv_pom; hv_pom = hv_y_.TupleSelect(hv_j); if (hv_y_ == null) { hv_y_ = new HTuple(); } hv_y_[hv_j] = hv_y_.TupleSelect(hv_j - 1); if (hv_y_ == null) { hv_y_ = new HTuple(); } hv_y_[hv_j - 1] = hv_pom; hv_pom = hv_w_.TupleSelect(hv_j); if (hv_w_ == null) { hv_w_ = new HTuple(); } hv_w_[hv_j] = hv_w_.TupleSelect(hv_j - 1); if (hv_w_ == null) { hv_w_ = new HTuple(); } hv_w_[hv_j - 1] = hv_pom; hv_j = hv_j - 1; if ((int)(new HTuple(hv_j.TupleEqual(0))) != 0) { break; } } hv_i = hv_i + 1; } //* Display detected objects ** HTuple end_val124 = hv_index; HTuple step_val124 = 1; for (hv_k = 1; hv_k.Continue(end_val124, step_val124); hv_k = hv_k.TupleAdd(step_val124)) { hv_x_cross = hv_x_.TupleSelect(hv_k - 1); hv_y_cross = hv_y_.TupleSelect(hv_k - 1); HOperatorSet.SetColor(hv_ExpDefaultWinHandle, "green"); ho_Cross.Dispose(); HOperatorSet.GenCrossContourXld(out ho_Cross, hv_x_cross, hv_y_cross, 200, 0); HOperatorSet.DispObj(ho_Cross, hv_ExpDefaultWinHandle); HOperatorSet.SetColor(hv_ExpDefaultWinHandle, "red"); HOperatorSet.SetTposition(hv_ExpDefaultWinHandle, hv_x_cross, hv_y_cross); HOperatorSet.WriteString(hv_ExpDefaultWinHandle, hv_k); } HOperatorSet.SetOriginPose(hv_CamPose, 0, 0, 0.00, out hv_WorldPose); HOperatorSet.PoseToHomMat3d(hv_WorldPose, out hv_HomMat3D); HOperatorSet.HomMat3dRotateLocal(hv_HomMat3D, hv_angle, "z", out hv_HomMat3DRotate); HOperatorSet.HomMat3dToPose(hv_HomMat3DRotate, out hv_WorldPose); HOperatorSet.ImagePointsToWorldPlane(hv_CamParamOut, hv_WorldPose, hv_x_.TupleSelect(0), hv_y_.TupleSelect(0), "mm", out hv_X, out hv_Y); // Diameter check // Still not working //HOperatorSet.ImagePointsToWorldPlane(hv_CamParamOut, hv_WorldPose, hv_Row1, hv_Column1, "mm", out hv_Pixel1X, out hv_Pixel1Y); //HOperatorSet.ImagePointsToWorldPlane(hv_CamParamOut, hv_WorldPose, hv_Row2, hv_Column2, "mm", out hv_Pixel2X, out hv_Pixel2Y); //HOperatorSet.DistancePp(hv_Pixel1X, hv_Pixel1Y, hv_Pixel2X, hv_Pixel2Y, out hv_distance); //HOperatorSet.TupleMean(hv_distance, out hv_distance_mean); HOperatorSet.SetTposition(hv_ExpDefaultWinHandle, 100, 100); HOperatorSet.WriteString(hv_ExpDefaultWinHandle, hv_a); HOperatorSet.WriteString(hv_ExpDefaultWinHandle, ", "); HOperatorSet.WriteString(hv_ExpDefaultWinHandle, hv_b); HOperatorSet.SetTposition(hv_ExpDefaultWinHandle, 20, 20); HOperatorSet.WriteString(hv_ExpDefaultWinHandle, hv_Length); } //* If objects not found check for layer holes else if ((int)(new HTuple(hv_len_area.TupleGreater(0))) == 0 && lastlayer) { hv_X = 0; hv_Y = 0; hv_angledeg = 0; HOperatorSet.ClearWindow(hv_ExpDefaultWinHandle); HOperatorSet.DispObj(ho_ImageReduced, hv_ExpDefaultWinHandle); HOperatorSet.SetColor(hv_ExpDefaultWinHandle, "red"); HOperatorSet.SetTposition(hv_ExpDefaultWinHandle, 120, 450); HOperatorSet.WriteString(hv_ExpDefaultWinHandle, "NA ZADNJEM SLOJU NISU PRONADENI KOMADI! ROBOT IDE NA IDUCU ULAZNU PALETU"); App.PaletaPrazna(); } else { try { ho_GripPoint.Dispose(); HOperatorSet.GenRectangle1(out ho_GripPoint, 420, 520, 620, 770); ho_ImageReducedGripPoint.Dispose(); HOperatorSet.ReduceDomain(ho_ImageRectified, ho_GripPoint, out ho_ImageReducedGripPoint); ho_ImageMedian.Dispose(); HOperatorSet.MedianImage(ho_ImageReducedGripPoint, out ho_ImageMedian, "circle", 3, "mirrored"); ho_ObjectGripPoint.Dispose(); segment(ho_ImageMedian, out ho_ObjectGripPoint); { HObject ExpTmpOutVar_0; HOperatorSet.Connection(ho_ObjectGripPoint, out ExpTmpOutVar_0); ho_ObjectGripPoint.Dispose(); ho_ObjectGripPoint = ExpTmpOutVar_0; } { HObject ExpTmpOutVar_0; HOperatorSet.SelectShape(ho_ObjectGripPoint, out ExpTmpOutVar_0, "circularity", "and", 0.5, 1.0); ho_ObjectGripPoint.Dispose(); ho_ObjectGripPoint = ExpTmpOutVar_0; } { HObject ExpTmpOutVar_0; HOperatorSet.SelectShape(ho_ObjectGripPoint, out ExpTmpOutVar_0, "area", "and", 100, 1000); ho_ObjectGripPoint.Dispose(); ho_ObjectGripPoint = ExpTmpOutVar_0; } HOperatorSet.AreaCenter(ho_ObjectGripPoint, out hv_Area2, out hv_Row5, out hv_Column5); HOperatorSet.TupleSum(hv_Row5, out hv_SumX); HOperatorSet.TupleSum(hv_Column5, out hv_SumY); hv_GripPointX = hv_SumX / 9; hv_GripPointY = hv_SumY / 9; ho_Cross1.Dispose(); HOperatorSet.GenCrossContourXld(out ho_Cross1, hv_GripPointX, hv_GripPointY, 10, 0); hv_maxdist = 0; hv_distgrippoints = new HTuple(); hv_indexgrip = 0; for (hv_i = 1; (int)hv_i <= 9; hv_i = (int)hv_i + 1) { HOperatorSet.DistancePp(hv_Row5.TupleSelect(hv_i - 1), hv_Column5.TupleSelect(hv_i - 1), hv_GripPointX, hv_GripPointY, out hv_distgrip); HOperatorSet.TupleConcat(hv_distgrippoints, hv_distgrip, out hv_distgrippoints); if ((int)(new HTuple(hv_distgrip.TupleGreater(hv_maxdist))) != 0) { hv_indexgrip = hv_i - 1; hv_maxdist = hv_distgrip.Clone(); } } hv_indexgrip = new HTuple(); for (hv_i = 1; (int)hv_i <= 9; hv_i = (int)hv_i + 1) { if ((int)(new HTuple( ((hv_distgrippoints.TupleSelect(hv_i - 1))).TupleGreater(0.9 * hv_maxdist))) != 0) { HOperatorSet.TupleConcat(hv_indexgrip, hv_i - 1, out hv_indexgrip); } } hv_OrientX = 0; hv_OrientY = 0; hv_maxX = 0; HOperatorSet.TupleAbs( (hv_Row5.TupleSelect(hv_indexgrip.TupleSelect(0))) - (hv_Row5.TupleSelect(hv_indexgrip.TupleSelect(1))), out hv_diff01); HOperatorSet.TupleAbs( (hv_Row5.TupleSelect(hv_indexgrip.TupleSelect(0))) - (hv_Row5.TupleSelect(hv_indexgrip.TupleSelect(2))), out hv_diff02); HOperatorSet.TupleAbs( (hv_Row5.TupleSelect(hv_indexgrip.TupleSelect(1))) - (hv_Row5.TupleSelect(hv_indexgrip.TupleSelect(2))), out hv_diff12); HOperatorSet.TupleMin(((hv_diff01.TupleConcat(hv_diff02))).TupleConcat(hv_diff12), out hv_mindiff); if ((int)(new HTuple(hv_mindiff.TupleEqual(hv_diff01))) != 0) { hv_OrientX = hv_Row5.TupleSelect(hv_indexgrip.TupleSelect(2)); hv_OrientY = hv_Column5.TupleSelect(hv_indexgrip.TupleSelect(2)); } else if ((int)(new HTuple(hv_mindiff.TupleEqual(hv_diff02))) != 0) { hv_OrientX = hv_Row5.TupleSelect(hv_indexgrip.TupleSelect(1)); hv_OrientY = hv_Column5.TupleSelect(hv_indexgrip.TupleSelect(1)); } else if ((int)(new HTuple(hv_mindiff.TupleEqual(hv_diff12))) != 0) { hv_OrientX = hv_Row5.TupleSelect(hv_indexgrip.TupleSelect(0)); hv_OrientY = hv_Column5.TupleSelect(hv_indexgrip.TupleSelect(0)); } HOperatorSet.DispObj(ho_ImageReduced, hv_ExpDefaultWinHandle); HOperatorSet.SetColor(hv_ExpDefaultWinHandle, "red"); ho_Arrow.Dispose(); gen_arrow_contour_xld(out ho_Arrow, hv_GripPointX, hv_GripPointY, hv_OrientX, hv_OrientY, 15, 15); HOperatorSet.DispObj(ho_Arrow, hv_ExpDefaultWinHandle); HOperatorSet.SetColor(hv_ExpDefaultWinHandle, "green"); ho_Cross2.Dispose(); HOperatorSet.GenCrossContourXld(out ho_Cross2, hv_GripPointX, hv_GripPointY, 30, 0); //HOperatorSet.DispObj(ho_Cross2, hv_ExpDefaultWinHandle); HOperatorSet.SetOriginPose(hv_CamPose, 0, 0, 0.00, out hv_WorldPose); HOperatorSet.ImagePointsToWorldPlane(hv_CamParamOut, hv_WorldPose, hv_GripPointX, hv_GripPointY, "mm", out hv_GX, out hv_GY); HOperatorSet.ImagePointsToWorldPlane(hv_CamParamOut, hv_WorldPose, hv_OrientX, hv_OrientY, "mm", out hv_OX, out hv_OY); hv_DY = hv_OY - hv_GY; hv_DX = hv_OX - hv_GX; HOperatorSet.TupleAtan2(hv_DY, hv_DX, out hv_theta); hv_theta = hv_theta.Clone(); hv_X = hv_GX; hv_Y = hv_GY; hv_angledeg = (hv_theta * 180) / hv_pi; } catch (HalconException exceptionLayerNotFound) { hv_X = 0; hv_Y = 0; hv_angledeg = 0; HOperatorSet.ClearWindow(hv_ExpDefaultWinHandle); HOperatorSet.DispObj(ho_ImageReduced, hv_ExpDefaultWinHandle); HOperatorSet.SetColor(hv_ExpDefaultWinHandle, "red"); HOperatorSet.SetTposition(hv_ExpDefaultWinHandle, 120, 512); HOperatorSet.WriteString(hv_ExpDefaultWinHandle, "NA PALETI NISU PRONADENI KOMADI NI SLOJEVI!!!"); App.LayerNijePronaden(); } } // HOperatorSet.ClearWindow(hv_ExpDefaultWinHandle); HOperatorSet.SetColor(hv_ExpDefaultWinHandle, "red"); ho_ContCircle.Dispose(); HOperatorSet.GenCircleContourXld(out ho_ContCircle, hv_Height / 2, hv_Width / 2, 100, 0, 6.28318, "positive", 10); ho_Image.Dispose(); ho_ImageRectified.Dispose(); ho_FOV.Dispose(); ho_Box.Dispose(); ho_ImageReduced.Dispose(); ho_Objects.Dispose(); ho_Cross.Dispose(); ho_GripPoint.Dispose(); ho_ImageReducedGripPoint.Dispose(); ho_ImageMedian.Dispose(); ho_ObjectGripPoint.Dispose(); ho_Cross1.Dispose(); ho_Arrow.Dispose(); ho_Cross2.Dispose(); ho_ContCircle.Dispose(); HOperatorSet.CloseFramegrabber(hv_AcqHandleCam1); // Open the thread DOOR _waitHandleCam1.Set(); }
/// <summary> /// 轮廓点拟合直线 /// </summary> /// <param name="ho_Line"></param> /// <param name="hv_Rows"></param> /// <param name="hv_Cols"></param> /// <param name="hv_ActiveNum"></param> /// <param name="hv_Row1"></param> /// <param name="hv_Column1"></param> /// <param name="hv_Row2"></param> /// <param name="hv_Column2"></param> public static void pts_to_best_line(out HObject ho_Line, HTuple hv_Rows, HTuple hv_Cols, HTuple hv_ActiveNum, out HTuple hv_Row1, out HTuple hv_Column1, out HTuple hv_Row2, out HTuple hv_Column2) { // Local iconic variables HObject ho_Contour = null; // Local control variables HTuple hv_Length = null, hv_Nr = new HTuple(); HTuple hv_Nc = new HTuple(), hv_Dist = new HTuple(), hv_Length1 = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Line); HOperatorSet.GenEmptyObj(out ho_Contour); try { //初始化 hv_Row1 = 0; hv_Column1 = 0; hv_Row2 = 0; hv_Column2 = 0; //产生一个空的直线对象,用于保存拟合后的直线 ho_Line.Dispose(); HOperatorSet.GenEmptyObj(out ho_Line); //计算边缘数量 HOperatorSet.TupleLength(hv_Cols, out hv_Length); //当边缘数量不小于有效点数时进行拟合 if ((int)((new HTuple(hv_Length.TupleGreaterEqual(hv_ActiveNum))).TupleAnd( new HTuple(hv_ActiveNum.TupleGreater(1)))) != 0) { //halcon的拟合是基于xld的,需要把边缘连接成xld ho_Contour.Dispose(); HOperatorSet.GenContourPolygonXld(out ho_Contour, hv_Rows, hv_Cols); //拟合直线。使用的算法是'tukey',其他算法请参考fit_line_contour_xld的描述部分。 HOperatorSet.FitLineContourXld(ho_Contour, "tukey", -1, 0, 5, 2, out hv_Row1, out hv_Column1, out hv_Row2, out hv_Column2, out hv_Nr, out hv_Nc, out hv_Dist); //判断拟合结果是否有效:如果拟合成功,数组中元素的数量大于0 HOperatorSet.TupleLength(hv_Dist, out hv_Length1); if ((int)(new HTuple(hv_Length1.TupleLess(1))) != 0) { ho_Contour.Dispose(); return; } //根据拟合结果,产生直线xld ho_Line.Dispose(); HOperatorSet.GenContourPolygonXld(out ho_Line, hv_Row1.TupleConcat(hv_Row2), hv_Column1.TupleConcat(hv_Column2)); } ho_Contour.Dispose(); return; } catch (HalconException HDevExpDefaultException) { ho_Contour.Dispose(); throw HDevExpDefaultException; } }