public void do_inspect1(HObject ho_Image, HTuple hv_RightModelPath, HTuple hv_TestModelPath, out HTuple hv_outport_result) { // Local iconic variables HObject ho_UpRectangle = null, ho_UpImageReduced = null; HObject ho_DownRectangle = null, ho_DownImageReduced = null; HObject ho_UpSuccessRegions = null, ho_UpSuccessConnectedRegions = null; HObject ho_UpSuccessSelectedRegions = null, ho_UpSuccessSelectedRegions1 = null; HObject ho_UpFailRegions = null, ho_UpFailConnectedRegions = null; HObject ho_UpFailSelectedRegions = null, ho_UpFailSelectedRegions1 = null; HObject ho_DownSuccessRegions = null, ho_DownSuccessConnectedRegions = null; HObject ho_DownSuccessSelectedRegions = null, ho_DownSuccessSelectedRegions1 = null; HObject ho_DownFailRegions = null, ho_DownFailConnectedRegions = null; HObject ho_DownFailSelectedRegions = null, ho_DownFailSelectedRegions1 = null; // Local control variables HTuple hv_Width, hv_Height, hv_RightModelID; HTuple hv_RightModelRow, hv_RightModelColumn, hv_RightModelAngle; HTuple hv_RightModelScore, hv_TestModelID = new HTuple(); HTuple hv_UpTestRow = new HTuple(), hv_UpTestColumn = new HTuple(); HTuple hv_UpTestAngle = new HTuple(), hv_UpTestScore = new HTuple(); HTuple hv_DownTestRow = new HTuple(), hv_DownTestColumn = new HTuple(); HTuple hv_DownTestAngle = new HTuple(), hv_DownTestScore = new HTuple(); HTuple hv_upStartStateArea = new HTuple(), hv_upStartStateRow = new HTuple(); HTuple hv_upStartStateColumn = new HTuple(), hv_UpSuccessArea = new HTuple(); HTuple hv_UpSuccessRow = new HTuple(), hv_UpSuccessColumn = new HTuple(); HTuple hv_UpFailArea = new HTuple(), hv_UpFailRow = new HTuple(); HTuple hv_UpFailColumn = new HTuple(), hv_downStartStateArea = new HTuple(); HTuple hv_downStartStateRow = new HTuple(), hv_downStartStateColumn = new HTuple(); HTuple hv_DownSuccessArea = new HTuple(), hv_DownSuccessRow = new HTuple(); HTuple hv_DownSuccessColumn = new HTuple(), hv_DownFailArea = new HTuple(); HTuple hv_DownFailRow = new HTuple(), hv_DownFailColumn = new HTuple(); HTuple hv_outport_upresult = new HTuple(), hv_outport_downresult = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_UpRectangle); HOperatorSet.GenEmptyObj(out ho_UpImageReduced); HOperatorSet.GenEmptyObj(out ho_DownRectangle); HOperatorSet.GenEmptyObj(out ho_DownImageReduced); HOperatorSet.GenEmptyObj(out ho_UpSuccessRegions); HOperatorSet.GenEmptyObj(out ho_UpSuccessConnectedRegions); HOperatorSet.GenEmptyObj(out ho_UpSuccessSelectedRegions); HOperatorSet.GenEmptyObj(out ho_UpSuccessSelectedRegions1); HOperatorSet.GenEmptyObj(out ho_UpFailRegions); HOperatorSet.GenEmptyObj(out ho_UpFailConnectedRegions); HOperatorSet.GenEmptyObj(out ho_UpFailSelectedRegions); HOperatorSet.GenEmptyObj(out ho_UpFailSelectedRegions1); HOperatorSet.GenEmptyObj(out ho_DownSuccessRegions); HOperatorSet.GenEmptyObj(out ho_DownSuccessConnectedRegions); HOperatorSet.GenEmptyObj(out ho_DownSuccessSelectedRegions); HOperatorSet.GenEmptyObj(out ho_DownSuccessSelectedRegions1); HOperatorSet.GenEmptyObj(out ho_DownFailRegions); HOperatorSet.GenEmptyObj(out ho_DownFailConnectedRegions); HOperatorSet.GenEmptyObj(out ho_DownFailSelectedRegions); HOperatorSet.GenEmptyObj(out ho_DownFailSelectedRegions1); hv_outport_result = new HTuple(); //read_image (Image, fileName) HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height); HOperatorSet.ReadNccModel(hv_RightModelPath, out hv_RightModelID); HOperatorSet.FindNccModel(ho_Image, hv_RightModelID, 0, 0, 0.5, 1, 0.5, "true", 0, out hv_RightModelRow, out hv_RightModelColumn, out hv_RightModelAngle, out hv_RightModelScore); if ((int)((new HTuple((new HTuple(hv_RightModelScore.TupleLength())).TupleEqual( 0))).TupleOr(new HTuple(((hv_RightModelScore.TupleSelect(0))).TupleLess(0.75)))) != 0) { //û�ҵ���λ�����Ҳ����ť�� hv_outport_result = new HTuple(); hv_outport_result[0] = 4; hv_outport_result[1] = 4; } else { ho_UpRectangle.Dispose(); HOperatorSet.GenRectangle1(out ho_UpRectangle, (hv_RightModelRow.TupleSelect( 0)) - 305, (hv_RightModelColumn.TupleSelect(0)) - 815, (hv_RightModelRow.TupleSelect( 0)) - 50, (hv_RightModelColumn.TupleSelect(0)) - 70); ho_UpImageReduced.Dispose(); HOperatorSet.ReduceDomain(ho_Image, ho_UpRectangle, out ho_UpImageReduced); ho_DownRectangle.Dispose(); HOperatorSet.GenRectangle1(out ho_DownRectangle, (hv_RightModelRow.TupleSelect( 0)) - 30, (hv_RightModelColumn.TupleSelect(0)) - 815, (hv_RightModelRow.TupleSelect( 0)) + 230, (hv_RightModelColumn.TupleSelect(0)) - 70); ho_DownImageReduced.Dispose(); HOperatorSet.ReduceDomain(ho_Image, ho_DownRectangle, out ho_DownImageReduced ); HOperatorSet.ReadNccModel(hv_TestModelPath, out hv_TestModelID); HOperatorSet.FindNccModel(ho_UpImageReduced, hv_TestModelID, 0, 0, 0.5, 1, 0.5, "true", 0, out hv_UpTestRow, out hv_UpTestColumn, out hv_UpTestAngle, out hv_UpTestScore); HOperatorSet.FindNccModel(ho_DownImageReduced, hv_TestModelID, 0, 0, 0.5, 1, 0.5, "true", 0, out hv_DownTestRow, out hv_DownTestColumn, out hv_DownTestAngle, out hv_DownTestScore); ho_UpSuccessRegions.Dispose(); HOperatorSet.Threshold(ho_UpImageReduced, out ho_UpSuccessRegions, 0, 2); HOperatorSet.AreaCenter(ho_UpSuccessRegions, out hv_upStartStateArea, out hv_upStartStateRow, out hv_upStartStateColumn); ho_UpSuccessConnectedRegions.Dispose(); HOperatorSet.Connection(ho_UpSuccessRegions, out ho_UpSuccessConnectedRegions ); ho_UpSuccessSelectedRegions.Dispose(); HOperatorSet.SelectShape(ho_UpSuccessConnectedRegions, out ho_UpSuccessSelectedRegions, "rectangularity", "and", 0.8, 1); ho_UpSuccessSelectedRegions1.Dispose(); HOperatorSet.SelectShape(ho_UpSuccessSelectedRegions, out ho_UpSuccessSelectedRegions1, "area", "and", 10000, 158720); HOperatorSet.AreaCenter(ho_UpSuccessSelectedRegions1, out hv_UpSuccessArea, out hv_UpSuccessRow, out hv_UpSuccessColumn); ho_UpFailRegions.Dispose(); HOperatorSet.Threshold(ho_UpImageReduced, out ho_UpFailRegions, 138, 140); ho_UpFailConnectedRegions.Dispose(); HOperatorSet.Connection(ho_UpFailRegions, out ho_UpFailConnectedRegions); ho_UpFailSelectedRegions.Dispose(); HOperatorSet.SelectShape(ho_UpFailConnectedRegions, out ho_UpFailSelectedRegions, "rectangularity", "and", 0.8, 1); ho_UpFailSelectedRegions1.Dispose(); HOperatorSet.SelectShape(ho_UpFailSelectedRegions, out ho_UpFailSelectedRegions1, "area", "and", 10000, 158720); HOperatorSet.AreaCenter(ho_UpFailSelectedRegions1, out hv_UpFailArea, out hv_UpFailRow, out hv_UpFailColumn); ho_DownSuccessRegions.Dispose(); HOperatorSet.Threshold(ho_DownImageReduced, out ho_DownSuccessRegions, 0, 2); HOperatorSet.AreaCenter(ho_DownSuccessRegions, out hv_downStartStateArea, out hv_downStartStateRow, out hv_downStartStateColumn); ho_DownSuccessConnectedRegions.Dispose(); HOperatorSet.Connection(ho_DownSuccessRegions, out ho_DownSuccessConnectedRegions ); ho_DownSuccessSelectedRegions.Dispose(); HOperatorSet.SelectShape(ho_DownSuccessConnectedRegions, out ho_DownSuccessSelectedRegions, "rectangularity", "and", 0.8, 1); ho_DownSuccessSelectedRegions1.Dispose(); HOperatorSet.SelectShape(ho_DownSuccessSelectedRegions, out ho_DownSuccessSelectedRegions1, "area", "and", 10000, 158720); HOperatorSet.AreaCenter(ho_DownSuccessSelectedRegions1, out hv_DownSuccessArea, out hv_DownSuccessRow, out hv_DownSuccessColumn); ho_DownFailRegions.Dispose(); HOperatorSet.Threshold(ho_DownImageReduced, out ho_DownFailRegions, 138, 140); ho_DownFailConnectedRegions.Dispose(); HOperatorSet.Connection(ho_DownFailRegions, out ho_DownFailConnectedRegions ); ho_DownFailSelectedRegions.Dispose(); HOperatorSet.SelectShape(ho_DownFailConnectedRegions, out ho_DownFailSelectedRegions, "rectangularity", "and", 0.8, 1); ho_DownFailSelectedRegions1.Dispose(); HOperatorSet.SelectShape(ho_DownFailSelectedRegions, out ho_DownFailSelectedRegions1, "area", "and", 10000, 158720); HOperatorSet.AreaCenter(ho_DownFailSelectedRegions1, out hv_DownFailArea, out hv_DownFailRow, out hv_DownFailColumn); if ((int)((new HTuple((new HTuple(hv_UpTestScore.TupleLength())).TupleEqual( 0))).TupleOr(new HTuple(((hv_UpTestScore.TupleSelect(0))).TupleLess(0.75)))) != 0) { if ((int)((new HTuple((new HTuple(hv_upStartStateArea.TupleLength())).TupleEqual( 0))).TupleOr(new HTuple(hv_upStartStateArea.TupleEqual(0)))) != 0) { //��ʼ״̬ hv_outport_upresult = 0; } else { //������ hv_outport_upresult = 1; } } else { if ((int)(new HTuple((new HTuple(hv_UpSuccessArea.TupleLength())).TupleGreater( 0))) != 0) { //�Ͽ���Գɹ� hv_outport_upresult = 2; } else if ((int)(new HTuple((new HTuple(hv_UpFailArea.TupleLength() )).TupleGreater(0))) != 0) { //�Ͽ����ʧ�� hv_outport_upresult = 3; } else { //�ҵ����Խ�����ʶ����֪���Dz��Գɹ����Dz���ʧ�� hv_outport_upresult = 4; } } if ((int)((new HTuple((new HTuple(hv_DownTestScore.TupleLength())).TupleEqual( 0))).TupleOr(new HTuple(((hv_DownTestScore.TupleSelect(0))).TupleLess(0.75)))) != 0) { //������ if ((int)((new HTuple((new HTuple(hv_downStartStateArea.TupleLength())).TupleEqual( 0))).TupleOr(new HTuple(hv_downStartStateArea.TupleEqual(0)))) != 0) { //��ʼ״̬ hv_outport_downresult = 0; } else { //������ hv_outport_downresult = 1; } } else { if ((int)(new HTuple((new HTuple(hv_DownSuccessArea.TupleLength())).TupleGreater( 0))) != 0) { //�¿���Գɹ� hv_outport_downresult = 2; } else if ((int)(new HTuple((new HTuple(hv_DownFailArea.TupleLength() )).TupleGreater(0))) != 0) { //�¿����ʧ�� hv_outport_downresult = 3; } else { //�ҵ����Խ�����ʶ����֪���Dz��Գɹ����Dz���ʧ�� hv_outport_downresult = 4; } } hv_outport_result[0] = hv_outport_upresult.TupleSelect(0); hv_outport_result[1] = hv_outport_downresult.TupleSelect(0); HOperatorSet.ClearNccModel(hv_TestModelID); } HOperatorSet.ClearNccModel(hv_RightModelID); ho_UpRectangle.Dispose(); ho_UpImageReduced.Dispose(); ho_DownRectangle.Dispose(); ho_DownImageReduced.Dispose(); ho_UpSuccessRegions.Dispose(); ho_UpSuccessConnectedRegions.Dispose(); ho_UpSuccessSelectedRegions.Dispose(); ho_UpSuccessSelectedRegions1.Dispose(); ho_UpFailRegions.Dispose(); ho_UpFailConnectedRegions.Dispose(); ho_UpFailSelectedRegions.Dispose(); ho_UpFailSelectedRegions1.Dispose(); ho_DownSuccessRegions.Dispose(); ho_DownSuccessConnectedRegions.Dispose(); ho_DownSuccessSelectedRegions.Dispose(); ho_DownSuccessSelectedRegions1.Dispose(); ho_DownFailRegions.Dispose(); ho_DownFailConnectedRegions.Dispose(); ho_DownFailSelectedRegions.Dispose(); ho_DownFailSelectedRegions1.Dispose(); return; }
private void action() { // Stack for temporary objects HObject[] OTemp = new HObject[20]; // Local iconic variables HObject ho_Rectangle, ho_ImageReduced; HObject ho_Region, ho_RegionLines, ho_RegionUnion1, ho_RegionUnion2; HObject ho_RegionUnion3, ho_Region1, ho_ConnectedRegions; HObject ho_RegionFillUp, ho_SelectedRegions, ho_SortedRegions; HObject ho_ObjectSelected = null, ho_Rectangle1 = null, ho_ImageReduced1 = null; HObject ho_Circle1 = null, ho_Circle2 = null, ho_Circle3 = null; HObject ho_Circle4 = null, ho_RegionUnionc1 = null, ho_RegionUnionc2 = null; HObject ho_RegionUnionc3 = null, ho_ConnectedRegionsc = null; HObject ho_SortedRegions1 = null, ho_ContoursL = null, ho_RegionLinesL = null; HObject ho_RegionLinesL1 = null, ho_RegionUnionL = null, ho_ConnectedRegionsL = null; HObject ho_SelectedRegionsL = null, ho_RegionFillUpL = null; HObject ho_ContoursSplitL = null, ho_SelectedContoursL = null; HObject ho_UnionContoursL = null, ho_RegionL = null, ho_RegionDifferenceL = null; HObject ho_ContoursR = null, ho_RegionLinesR = null, ho_RegionLinesR1 = null; HObject ho_RegionUnionR = null, ho_ConnectedRegionsR = null; HObject ho_SelectedRegionsR = null, ho_RegionFillUpR = null; HObject ho_ContoursSplitR = null, ho_SelectedContoursR = null; HObject ho_UnionContoursR = null, ho_RegionR = null, ho_RegionDifferenceR = null; HObject ho_ConnectedRegions1, ho_ObjectSelected1 = null; // Local control variables HTuple hv_Width = null, hv_Height = null, hv_Row11 = null; HTuple hv_Column11 = null, hv_Row21 = null, hv_Column21 = null; HTuple hv_Row12 = null, hv_Column12 = null, hv_Row22 = null; HTuple hv_Column22 = null, hv_Number = null, hv_h = null; HTuple hv_w = null, hv_i = null, hv_Row = new HTuple(); HTuple hv_Column = new HTuple(), hv_Phi = new HTuple(); HTuple hv_Length1 = new HTuple(), hv_Length2 = new HTuple(); HTuple hv_Cos = new HTuple(), hv_Sin = new HTuple(), hv_RT_X = new HTuple(); HTuple hv_RT_Y = new HTuple(), hv_AX = new HTuple(), hv_AY = new HTuple(); HTuple hv_RB_X = new HTuple(), hv_RB_Y = new HTuple(); HTuple hv_BX = new HTuple(), hv_BY = new HTuple(), hv_LB_X = new HTuple(); HTuple hv_LB_Y = new HTuple(), hv_CX = new HTuple(), hv_CY = new HTuple(); HTuple hv_LT_X = new HTuple(), hv_LT_Y = new HTuple(); HTuple hv_DX = new HTuple(), hv_DY = new HTuple(), hv_Number1 = new HTuple(); HTuple hv_Area = new HTuple(), hv_Row1 = new HTuple(); HTuple hv_Column1 = new HTuple(), hv_Distance = new HTuple(); HTuple hv_Distance1 = new HTuple(), hv_shapeParam = new HTuple(); HTuple hv_MetrologyHandleL = new HTuple(), hv_Index = new HTuple(); HTuple hv_RowL = new HTuple(), hv_ColumnL = new HTuple(); HTuple hv_l = new HTuple(), hv_NumberL = new HTuple(); HTuple hv_MetrologyHandleR = new HTuple(), hv_RowR = new HTuple(); HTuple hv_ColumnR = new HTuple(), hv_r = new HTuple(); HTuple hv_NumberR = new HTuple(), hv_AreaL = new HTuple(); HTuple hv_AreaR = new HTuple(), hv_Area1 = null, hv_Row2 = null; HTuple hv_Column2 = null, hv_Area2 = null, hv_Row3 = null; HTuple hv_Column3 = null, hv_hm = null, hv_wm = null, hv_Row13 = null; HTuple hv_Column13 = null, hv_Row23 = null, hv_Column23 = null; HTuple hv_zh = null, hv_w1 = new HTuple(), hv_Row4 = new HTuple(), hv_Column4 = new HTuple(); HTuple hv_Phi1 = new HTuple(), hv_Length11 = new HTuple(), hv_Length21 = new HTuple(), hv_Concat = new HTuple(); // 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_RegionLines); HOperatorSet.GenEmptyObj(out ho_RegionUnion1); HOperatorSet.GenEmptyObj(out ho_RegionUnion2); HOperatorSet.GenEmptyObj(out ho_RegionUnion3); HOperatorSet.GenEmptyObj(out ho_Region1); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions); HOperatorSet.GenEmptyObj(out ho_RegionFillUp); HOperatorSet.GenEmptyObj(out ho_SelectedRegions); HOperatorSet.GenEmptyObj(out ho_SortedRegions); HOperatorSet.GenEmptyObj(out ho_ObjectSelected); HOperatorSet.GenEmptyObj(out ho_Rectangle1); HOperatorSet.GenEmptyObj(out ho_ImageReduced1); HOperatorSet.GenEmptyObj(out ho_Circle1); HOperatorSet.GenEmptyObj(out ho_Circle2); HOperatorSet.GenEmptyObj(out ho_Circle3); HOperatorSet.GenEmptyObj(out ho_Circle4); HOperatorSet.GenEmptyObj(out ho_RegionUnionc1); HOperatorSet.GenEmptyObj(out ho_RegionUnionc2); HOperatorSet.GenEmptyObj(out ho_RegionUnionc3); HOperatorSet.GenEmptyObj(out ho_ConnectedRegionsc); HOperatorSet.GenEmptyObj(out ho_SortedRegions1); HOperatorSet.GenEmptyObj(out ho_ContoursL); HOperatorSet.GenEmptyObj(out ho_RegionLinesL); HOperatorSet.GenEmptyObj(out ho_RegionLinesL1); HOperatorSet.GenEmptyObj(out ho_RegionUnionL); HOperatorSet.GenEmptyObj(out ho_ConnectedRegionsL); HOperatorSet.GenEmptyObj(out ho_SelectedRegionsL); HOperatorSet.GenEmptyObj(out ho_RegionFillUpL); HOperatorSet.GenEmptyObj(out ho_ContoursSplitL); HOperatorSet.GenEmptyObj(out ho_SelectedContoursL); HOperatorSet.GenEmptyObj(out ho_UnionContoursL); HOperatorSet.GenEmptyObj(out ho_RegionL); HOperatorSet.GenEmptyObj(out ho_RegionDifferenceL); HOperatorSet.GenEmptyObj(out ho_ContoursR); HOperatorSet.GenEmptyObj(out ho_RegionLinesR); HOperatorSet.GenEmptyObj(out ho_RegionLinesR1); HOperatorSet.GenEmptyObj(out ho_RegionUnionR); HOperatorSet.GenEmptyObj(out ho_ConnectedRegionsR); HOperatorSet.GenEmptyObj(out ho_SelectedRegionsR); HOperatorSet.GenEmptyObj(out ho_RegionFillUpR); HOperatorSet.GenEmptyObj(out ho_ContoursSplitR); HOperatorSet.GenEmptyObj(out ho_SelectedContoursR); HOperatorSet.GenEmptyObj(out ho_UnionContoursR); HOperatorSet.GenEmptyObj(out ho_RegionR); HOperatorSet.GenEmptyObj(out ho_RegionDifferenceR); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions1); HOperatorSet.GenEmptyObj(out ho_ObjectSelected1); HOperatorSet.Union1(algorithm.Region, out RegionToDisp); try { 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.GetImageSize(Image, out hv_Width, out hv_Height); HOperatorSet.Threshold(ho_ImageReduced, out ho_Region, 128, 255); HOperatorSet.SmallestRectangle1(ho_Region, out hv_Row12, out hv_Column12, out hv_Row22, out hv_Column22); ho_RegionLines.Dispose(); HOperatorSet.GenRegionLine(out ho_RegionLines, (hv_Row12 + hv_Row22) / 2, hv_Column12, ((hv_Row12 + hv_Row22) / 2) + 1, hv_Column12); ho_RegionUnion1.Dispose(); HOperatorSet.Union1(ho_RegionLines, out ho_RegionUnion1); ho_RegionUnion2.Dispose(); HOperatorSet.Union1(ho_RegionLines, out ho_RegionUnion2); ho_RegionUnion3.Dispose(); HOperatorSet.Union1(ho_RegionLines, out ho_RegionUnion3); ho_Region1.Dispose(); HOperatorSet.Threshold(ho_ImageReduced, out ho_Region1, 128, 255); ho_ConnectedRegions.Dispose(); HOperatorSet.Connection(ho_Region1, out ho_ConnectedRegions); ho_RegionFillUp.Dispose(); HOperatorSet.FillUp(ho_ConnectedRegions, out ho_RegionFillUp); ho_SelectedRegions.Dispose(); HOperatorSet.SelectShape(ho_RegionFillUp, out ho_SelectedRegions, "area", "and", 500, 99999000); ho_SortedRegions.Dispose(); HOperatorSet.SortRegion(ho_SelectedRegions, out ho_SortedRegions, "upper_left", "true", "column"); HOperatorSet.CountObj(ho_SortedRegions, out hv_Number); // stop(); only in hdevelop // stop(); only in hdevelop hv_h = new HTuple(); hv_w = new HTuple(); hv_w1 = new HTuple(); ho_ObjectSelected1.Dispose(); HOperatorSet.SelectObj(ho_SortedRegions, out ho_ObjectSelected1, 1); HOperatorSet.SmallestRectangle2(ho_ObjectSelected1, out hv_Row4, out hv_Column4, out hv_Phi1, out hv_Length11, out hv_Length21); hv_w1 = hv_w1.TupleConcat(hv_Length21 * 2); HTuple end_val40 = hv_Number - 1; HTuple step_val40 = 1; for (hv_i = 2; hv_i.Continue(end_val40, step_val40); hv_i = hv_i.TupleAdd(step_val40)) { ho_ObjectSelected.Dispose(); HOperatorSet.SelectObj(ho_SortedRegions, out ho_ObjectSelected, hv_i); HOperatorSet.SmallestRectangle2(ho_ObjectSelected, out hv_Row, out hv_Column, out hv_Phi, out hv_Length1, out hv_Length2); //if (Length1>(Row22-Row12)*0.25) ho_Rectangle1.Dispose(); HOperatorSet.GenRectangle2(out ho_Rectangle1, hv_Row, hv_Column, hv_Phi, hv_Length1 * 0.85, hv_Length2); ho_ImageReduced1.Dispose(); HOperatorSet.ReduceDomain(ho_ImageReduced, ho_Rectangle1, out ho_ImageReduced1 ); //*矩形4个角点 HOperatorSet.TupleCos(hv_Phi, out hv_Cos); HOperatorSet.TupleSin(hv_Phi, out hv_Sin); //*dev_set_color('green') hv_RT_X = (((-hv_Length1) * 0.85) * hv_Cos) - (hv_Length2 * hv_Sin); hv_RT_Y = (((-hv_Length1) * 0.85) * hv_Sin) + (hv_Length2 * hv_Cos); ho_Circle1.Dispose(); HOperatorSet.GenCircle(out ho_Circle1, hv_Row - hv_RT_Y, hv_Column + hv_RT_X, 0.5); //*最小矩形的顶点A hv_AX = (((-hv_Length1) * 0.85) * hv_Cos) - (hv_Length2 * hv_Sin); hv_AY = (((-hv_Length1) * 0.85) * hv_Sin) + (hv_Length2 * hv_Cos); //*dev_set_color('red') hv_RB_X = ((hv_Length1 * 0.85) * hv_Cos) - (hv_Length2 * hv_Sin); hv_RB_Y = ((hv_Length1 * 0.85) * hv_Sin) + (hv_Length2 * hv_Cos); ho_Circle2.Dispose(); HOperatorSet.GenCircle(out ho_Circle2, hv_Row - hv_RB_Y, hv_Column + hv_RB_X, 0.5); //*最小矩形的顶点B hv_BX = ((hv_Length1 * 0.85) * hv_Cos) - (hv_Length2 * hv_Sin); hv_BY = ((hv_Length1 * 0.85) * hv_Sin) + (hv_Length2 * hv_Cos); //*dev_set_color('yellow') hv_LB_X = ((hv_Length1 * 0.85) * hv_Cos) + (hv_Length2 * hv_Sin); hv_LB_Y = ((hv_Length1 * 0.85) * hv_Sin) - (hv_Length2 * hv_Cos); ho_Circle3.Dispose(); HOperatorSet.GenCircle(out ho_Circle3, hv_Row - hv_LB_Y, hv_Column + hv_LB_X, 0.5); //*最小矩形的顶点C hv_CX = ((hv_Length1 * 0.85) * hv_Cos) + (hv_Length2 * hv_Sin); hv_CY = ((hv_Length1 * 0.85) * hv_Sin) - (hv_Length2 * hv_Cos); //*dev_set_color('pink') hv_LT_X = (((-hv_Length1) * 0.85) * hv_Cos) + (hv_Length2 * hv_Sin); hv_LT_Y = (((-hv_Length1) * 0.85) * hv_Sin) - (hv_Length2 * hv_Cos); ho_Circle4.Dispose(); HOperatorSet.GenCircle(out ho_Circle4, hv_Row - hv_LT_Y, hv_Column + hv_LT_X, 0.5); //*最小矩形的顶点D hv_DX = (((-hv_Length1) * 0.85) * hv_Cos) + (hv_Length2 * hv_Sin); hv_DY = (((-hv_Length1) * 0.85) * hv_Sin) - (hv_Length2 * hv_Cos); //stop () ho_RegionUnionc1.Dispose(); HOperatorSet.Union2(ho_Circle1, ho_Circle2, out ho_RegionUnionc1); ho_RegionUnionc2.Dispose(); HOperatorSet.Union2(ho_RegionUnionc1, ho_Circle3, out ho_RegionUnionc2); ho_RegionUnionc3.Dispose(); HOperatorSet.Union2(ho_RegionUnionc2, ho_Circle4, out ho_RegionUnionc3); ho_ConnectedRegionsc.Dispose(); HOperatorSet.Connection(ho_RegionUnionc3, out ho_ConnectedRegionsc); //count_obj (RegionUnionc3, Number1) ho_SortedRegions1.Dispose(); HOperatorSet.SortRegion(ho_ConnectedRegionsc, out ho_SortedRegions1, "upper_left", "true", "row"); HOperatorSet.AreaCenter(ho_SortedRegions1, out hv_Area, out hv_Row1, out hv_Column1); HOperatorSet.DistancePp(hv_Row1.TupleSelect(0), hv_Column1.TupleSelect( 0), hv_Row1.TupleSelect(1), hv_Column1.TupleSelect(1), out hv_Distance); HOperatorSet.DistancePl(hv_Row1.TupleSelect(0), hv_Column1.TupleSelect( 0), hv_Row1.TupleSelect(2), hv_Column1.TupleSelect(2), hv_Row1.TupleSelect( 3), hv_Column1.TupleSelect(3), out hv_Distance1); //if (i>1) hv_h = hv_h.TupleConcat((hv_Distance1 * 4) / 3); //endif hv_w = hv_w.TupleConcat(hv_Distance); //gen_region_line (RegionLines2, (Row1[0]+Row1[1])/2, (Column1[0]+Column1[1])/2, (Row1[2]+Row1[3])/2, (Column1[2]+Column1[3])/2) hv_shapeParam = new HTuple(); hv_shapeParam = hv_shapeParam.TupleConcat(((hv_Row1.TupleSelect( 0)) + (hv_Row1.TupleSelect(1))) / 2); hv_shapeParam = hv_shapeParam.TupleConcat(((hv_Column1.TupleSelect( 0)) + (hv_Column1.TupleSelect(1))) / 2); hv_shapeParam = hv_shapeParam.TupleConcat(((hv_Row1.TupleSelect( 2)) + (hv_Row1.TupleSelect(3))) / 2); hv_shapeParam = hv_shapeParam.TupleConcat(((hv_Column1.TupleSelect( 2)) + (hv_Column1.TupleSelect(3))) / 2); //shapeParam := [Row12,(Column22+Column12)/2,Row22,(Column22+Column12)/2] //找左侧点 HOperatorSet.CreateMetrologyModel(out hv_MetrologyHandleL); HOperatorSet.SetMetrologyModelImageSize(hv_MetrologyHandleL, hv_Width, hv_Height); HOperatorSet.AddMetrologyObjectGeneric(hv_MetrologyHandleL, "line", hv_shapeParam, hv_Distance / 2, 1, 1, 60, new HTuple(), new HTuple(), out hv_Index); //设置参数 HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandleL, "all", "measure_transition", "negative"); HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandleL, "all", "num_measures", 150); HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandleL, "all", "num_instances", 1); HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandleL, "all", "measure_select", "last"); //开始找边缘 HOperatorSet.ApplyMetrologyModel(ho_ImageReduced1, hv_MetrologyHandleL); ho_ContoursL.Dispose(); HOperatorSet.GetMetrologyObjectMeasures(out ho_ContoursL, hv_MetrologyHandleL, "all", "all", out hv_RowL, out hv_ColumnL); if (HDevWindowStack.IsOpen()) { //dev_set_color ('red') } //disp_cross (3600, RowL, ColumnL, 6, Phi) //左侧点,用一Row,只取最左边点 //gen_cross_contour_xld (CrossL, RowL, ColumnL, 6, 0) ///释放测量句柄 HOperatorSet.ClearMetrologyModel(hv_MetrologyHandleL); //gen_region_line (RegionLines, Row11, Column11, Row11+1, Column11) //union1 (RegionLines, RegionUnion1) for (hv_l = 0; (int)hv_l <= (int)((new HTuple(hv_RowL.TupleLength())) - 2); hv_l = (int)hv_l + 1) { ho_RegionLinesL.Dispose(); HOperatorSet.GenRegionLine(out ho_RegionLinesL, hv_RowL.TupleSelect(hv_l), hv_ColumnL.TupleSelect(hv_l), hv_RowL.TupleSelect(hv_l + 1), hv_ColumnL.TupleSelect( hv_l + 1)); { HObject ExpTmpOutVar_0; HOperatorSet.Union2(ho_RegionUnion1, ho_RegionLinesL, out ExpTmpOutVar_0 ); ho_RegionUnion1.Dispose(); ho_RegionUnion1 = ExpTmpOutVar_0; } } ho_RegionLinesL1.Dispose(); HOperatorSet.GenRegionLine(out ho_RegionLinesL1, hv_RowL.TupleSelect(0), hv_ColumnL.TupleSelect(0), hv_RowL.TupleSelect((new HTuple(hv_RowL.TupleLength() )) - 1), hv_ColumnL.TupleSelect((new HTuple(hv_RowL.TupleLength())) - 1)); ho_RegionUnionL.Dispose(); HOperatorSet.Union2(ho_RegionUnion1, ho_RegionLinesL1, out ho_RegionUnionL ); ho_ConnectedRegionsL.Dispose(); HOperatorSet.Connection(ho_RegionUnionL, out ho_ConnectedRegionsL); ho_SelectedRegionsL.Dispose(); HOperatorSet.SelectShapeStd(ho_ConnectedRegionsL, out ho_SelectedRegionsL, "max_area", 70); ho_RegionFillUpL.Dispose(); HOperatorSet.FillUp(ho_SelectedRegionsL, out ho_RegionFillUpL); ho_ContoursL.Dispose(); HOperatorSet.GenContourRegionXld(ho_RegionFillUpL, out ho_ContoursL, "border"); ho_ContoursSplitL.Dispose(); HOperatorSet.SegmentContoursXld(ho_ContoursL, out ho_ContoursSplitL, "lines_circles", 5, 8, 3.5); ho_SelectedContoursL.Dispose(); HOperatorSet.SelectContoursXld(ho_ContoursSplitL, out ho_SelectedContoursL, "contour_length", 70, 2000, -0.5, 0.5); //*** ho_UnionContoursL.Dispose(); HOperatorSet.UnionAdjacentContoursXld(ho_SelectedContoursL, out ho_UnionContoursL, 10, 1, "attr_keep"); ho_RegionL.Dispose(); HOperatorSet.GenRegionContourXld(ho_UnionContoursL, out ho_RegionL, "filled"); ho_RegionDifferenceL.Dispose(); HOperatorSet.Difference(ho_RegionFillUpL, ho_RegionL, out ho_RegionDifferenceL ); HOperatorSet.CountObj(ho_RegionDifferenceL, out hv_NumberL); //* //找右侧点 HOperatorSet.CreateMetrologyModel(out hv_MetrologyHandleR); HOperatorSet.SetMetrologyModelImageSize(hv_MetrologyHandleR, hv_Width, hv_Height); HOperatorSet.AddMetrologyObjectGeneric(hv_MetrologyHandleR, "line", hv_shapeParam, hv_Distance / 2, 1, 1, 60, new HTuple(), new HTuple(), out hv_Index); //设置参数 HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandleR, "all", "measure_transition", "positive"); HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandleR, "all", "num_measures", 100); HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandleR, "all", "num_instances", 1); HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandleR, "all", "measure_select", "first"); //开始找边缘 HOperatorSet.ApplyMetrologyModel(ho_ImageReduced1, hv_MetrologyHandleR); ho_ContoursR.Dispose(); HOperatorSet.GetMetrologyObjectMeasures(out ho_ContoursR, hv_MetrologyHandleR, "all", "all", out hv_RowR, out hv_ColumnR); //disp_obj (Image, 3600) if (HDevWindowStack.IsOpen()) { //dev_set_color ('red') } //disp_cross (3600, RowR, ColumnR, 6, Phi) //*右侧点,用一Row,只取最右边点 //gen_cross_contour_xld (CrossR, RowR, ColumnR, 6, 0) ///释放测量句柄 HOperatorSet.ClearMetrologyModel(hv_MetrologyHandleR); //close_measure (MeasureHandle1) //stop () //gen_region_line (RegionLines, Row11, Column11, Row11+1, Column11) //union1 (RegionLines, RegionUnion1) for (hv_r = 0; (int)hv_r <= (int)((new HTuple(hv_RowR.TupleLength())) - 2); hv_r = (int)hv_r + 1) { ho_RegionLinesR.Dispose(); HOperatorSet.GenRegionLine(out ho_RegionLinesR, hv_RowR.TupleSelect(hv_r), hv_ColumnR.TupleSelect(hv_r), hv_RowR.TupleSelect(hv_r + 1), hv_ColumnR.TupleSelect( hv_r + 1)); { HObject ExpTmpOutVar_0; HOperatorSet.Union2(ho_RegionUnion2, ho_RegionLinesR, out ExpTmpOutVar_0 ); ho_RegionUnion2.Dispose(); ho_RegionUnion2 = ExpTmpOutVar_0; } } ho_RegionLinesR1.Dispose(); HOperatorSet.GenRegionLine(out ho_RegionLinesR1, hv_RowR.TupleSelect(0), hv_ColumnR.TupleSelect(0), hv_RowR.TupleSelect((new HTuple(hv_RowR.TupleLength() )) - 1), hv_ColumnR.TupleSelect((new HTuple(hv_RowR.TupleLength())) - 1)); ho_RegionUnionR.Dispose(); HOperatorSet.Union2(ho_RegionUnion2, ho_RegionLinesR1, out ho_RegionUnionR ); ho_ConnectedRegionsR.Dispose(); HOperatorSet.Connection(ho_RegionUnionR, out ho_ConnectedRegionsR); ho_SelectedRegionsR.Dispose(); HOperatorSet.SelectShapeStd(ho_ConnectedRegionsR, out ho_SelectedRegionsR, "max_area", 70); ho_RegionFillUpR.Dispose(); HOperatorSet.FillUp(ho_SelectedRegionsR, out ho_RegionFillUpR); ho_ContoursR.Dispose(); HOperatorSet.GenContourRegionXld(ho_RegionFillUpR, out ho_ContoursR, "border"); ho_ContoursSplitR.Dispose(); HOperatorSet.SegmentContoursXld(ho_ContoursR, out ho_ContoursSplitR, "lines_circles", 5, 8, 3.5); ho_SelectedContoursR.Dispose(); HOperatorSet.SelectContoursXld(ho_ContoursSplitR, out ho_SelectedContoursR, "contour_length", 70, 2000, -0.5, 0.5); ho_UnionContoursR.Dispose(); HOperatorSet.UnionAdjacentContoursXld(ho_SelectedContoursR, out ho_UnionContoursR, 10, 1, "attr_keep"); ho_RegionR.Dispose(); HOperatorSet.GenRegionContourXld(ho_UnionContoursR, out ho_RegionR, "filled"); ho_RegionDifferenceR.Dispose(); HOperatorSet.Difference(ho_RegionFillUpR, ho_RegionR, out ho_RegionDifferenceR ); HOperatorSet.CountObj(ho_RegionDifferenceR, out hv_NumberR); //stop () if ((int)(new HTuple(hv_NumberL.TupleGreater(0))) != 0) { HOperatorSet.AreaCenter(ho_RegionDifferenceL, out hv_AreaL, out hv_RowL, out hv_ColumnL); { HObject ExpTmpOutVar_0; HOperatorSet.Union2(ho_RegionUnion3, ho_RegionDifferenceL, out ExpTmpOutVar_0 ); ho_RegionUnion3.Dispose(); ho_RegionUnion3 = ExpTmpOutVar_0; } } if ((int)(new HTuple(hv_NumberR.TupleGreater(0))) != 0) { HOperatorSet.AreaCenter(ho_RegionDifferenceR, out hv_AreaR, out hv_RowR, out hv_ColumnR); { HObject ExpTmpOutVar_0; HOperatorSet.Union2(ho_RegionUnion3, ho_RegionDifferenceR, out ExpTmpOutVar_0 ); ho_RegionUnion3.Dispose(); ho_RegionUnion3 = ExpTmpOutVar_0; } } //union2 (RegionDifferenceL, RegionDifferenceR, RegionUnionLR) //union2 (RegionUnion3, RegionUnionLR, RegionUnion3) // stop(); only in hdevelop //endif } HOperatorSet.AreaCenter(ho_RegionUnion3, out hv_Area1, out hv_Row2, out hv_Column2); ho_ConnectedRegions1.Dispose(); HOperatorSet.Connection(ho_RegionUnion3, out ho_ConnectedRegions1); HOperatorSet.AreaCenter(ho_ConnectedRegions1, out hv_Area2, out hv_Row3, out hv_Column3); HOperatorSet.TupleConcat(hv_w1, hv_w, out hv_Concat); hv_hm = (hv_h.TupleMin()) / (hv_h.TupleMean()); hv_wm = (hv_Concat.TupleMax()) / (hv_Concat.TupleMean()); ho_ObjectSelected.Dispose(); HOperatorSet.SelectObj(ho_SortedRegions, out ho_ObjectSelected, hv_Number); HOperatorSet.SmallestRectangle1(ho_ObjectSelected, out hv_Row13, out hv_Column13, out hv_Row23, out hv_Column23); hv_zh = hv_Column23 - hv_Column13; HOperatorSet.Union1(ho_ConnectedRegions1, out RegionToDisp); HTuple hv_result = GetHv_result(); hv_result = hv_result.TupleConcat("最短比值"); hv_result = hv_result.TupleConcat(hv_hm.D); hv_result = hv_result.TupleConcat("最宽比值"); hv_result = hv_result.TupleConcat(hv_wm.D); hv_result = hv_result.TupleConcat("缺陷总面积"); hv_result = hv_result.TupleConcat(hv_Area1.D); hv_result = hv_result.TupleConcat("最大缺陷面积"); hv_result = hv_result.TupleConcat(hv_Area2.D); hv_result = hv_result.TupleConcat("宽度"); hv_result = hv_result.TupleConcat(hv_zh.D); result = hv_result.Clone(); ho_Rectangle.Dispose(); ho_ImageReduced.Dispose(); ho_Region.Dispose(); ho_RegionLines.Dispose(); ho_RegionUnion1.Dispose(); ho_RegionUnion2.Dispose(); ho_RegionUnion3.Dispose(); ho_Region1.Dispose(); ho_ConnectedRegions.Dispose(); ho_RegionFillUp.Dispose(); ho_SelectedRegions.Dispose(); ho_SortedRegions.Dispose(); ho_ObjectSelected.Dispose(); ho_Rectangle1.Dispose(); ho_ImageReduced1.Dispose(); ho_Circle1.Dispose(); ho_Circle2.Dispose(); ho_Circle3.Dispose(); ho_Circle4.Dispose(); ho_RegionUnionc1.Dispose(); ho_RegionUnionc2.Dispose(); ho_RegionUnionc3.Dispose(); ho_ConnectedRegionsc.Dispose(); ho_SortedRegions1.Dispose(); ho_ContoursL.Dispose(); ho_RegionLinesL.Dispose(); ho_RegionLinesL1.Dispose(); ho_RegionUnionL.Dispose(); ho_ConnectedRegionsL.Dispose(); ho_SelectedRegionsL.Dispose(); ho_RegionFillUpL.Dispose(); ho_ContoursSplitL.Dispose(); ho_SelectedContoursL.Dispose(); ho_UnionContoursL.Dispose(); ho_RegionL.Dispose(); ho_RegionDifferenceL.Dispose(); ho_ContoursR.Dispose(); ho_RegionLinesR.Dispose(); ho_RegionLinesR1.Dispose(); ho_RegionUnionR.Dispose(); ho_ConnectedRegionsR.Dispose(); ho_SelectedRegionsR.Dispose(); ho_RegionFillUpR.Dispose(); ho_ContoursSplitR.Dispose(); ho_SelectedContoursR.Dispose(); ho_UnionContoursR.Dispose(); ho_RegionR.Dispose(); ho_RegionDifferenceR.Dispose(); ho_ConnectedRegions1.Dispose(); ho_ObjectSelected1.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(999999); hv_result = hv_result.TupleConcat("最大缺陷面积"); hv_result = hv_result.TupleConcat(999999); hv_result = hv_result.TupleConcat("宽度"); hv_result = hv_result.TupleConcat(999999); result = hv_result.Clone(); ho_Rectangle.Dispose(); ho_ImageReduced.Dispose(); ho_Region.Dispose(); ho_RegionLines.Dispose(); ho_RegionUnion1.Dispose(); ho_RegionUnion2.Dispose(); ho_RegionUnion3.Dispose(); ho_Region1.Dispose(); ho_ConnectedRegions.Dispose(); ho_RegionFillUp.Dispose(); ho_SelectedRegions.Dispose(); ho_SortedRegions.Dispose(); ho_ObjectSelected.Dispose(); ho_Rectangle1.Dispose(); ho_ImageReduced1.Dispose(); ho_Circle1.Dispose(); ho_Circle2.Dispose(); ho_Circle3.Dispose(); ho_Circle4.Dispose(); ho_RegionUnionc1.Dispose(); ho_RegionUnionc2.Dispose(); ho_RegionUnionc3.Dispose(); ho_ConnectedRegionsc.Dispose(); ho_SortedRegions1.Dispose(); ho_ContoursL.Dispose(); ho_RegionLinesL.Dispose(); ho_RegionLinesL1.Dispose(); ho_RegionUnionL.Dispose(); ho_ConnectedRegionsL.Dispose(); ho_SelectedRegionsL.Dispose(); ho_RegionFillUpL.Dispose(); ho_ContoursSplitL.Dispose(); ho_SelectedContoursL.Dispose(); ho_UnionContoursL.Dispose(); ho_RegionL.Dispose(); ho_RegionDifferenceL.Dispose(); ho_ContoursR.Dispose(); ho_RegionLinesR.Dispose(); ho_RegionLinesR1.Dispose(); ho_RegionUnionR.Dispose(); ho_ConnectedRegionsR.Dispose(); ho_SelectedRegionsR.Dispose(); ho_RegionFillUpR.Dispose(); ho_ContoursSplitR.Dispose(); ho_SelectedContoursR.Dispose(); ho_UnionContoursR.Dispose(); ho_RegionR.Dispose(); ho_RegionDifferenceR.Dispose(); ho_ConnectedRegions1.Dispose(); ho_ObjectSelected1.Dispose(); algorithm.Region.Dispose(); } finally { ho_Rectangle.Dispose(); ho_ImageReduced.Dispose(); ho_Region.Dispose(); ho_RegionLines.Dispose(); ho_RegionUnion1.Dispose(); ho_RegionUnion2.Dispose(); ho_RegionUnion3.Dispose(); ho_Region1.Dispose(); ho_ConnectedRegions.Dispose(); ho_RegionFillUp.Dispose(); ho_SelectedRegions.Dispose(); ho_SortedRegions.Dispose(); ho_ObjectSelected.Dispose(); ho_Rectangle1.Dispose(); ho_ImageReduced1.Dispose(); ho_Circle1.Dispose(); ho_Circle2.Dispose(); ho_Circle3.Dispose(); ho_Circle4.Dispose(); ho_RegionUnionc1.Dispose(); ho_RegionUnionc2.Dispose(); ho_RegionUnionc3.Dispose(); ho_ConnectedRegionsc.Dispose(); ho_SortedRegions1.Dispose(); ho_ContoursL.Dispose(); ho_RegionLinesL.Dispose(); ho_RegionLinesL1.Dispose(); ho_RegionUnionL.Dispose(); ho_ConnectedRegionsL.Dispose(); ho_SelectedRegionsL.Dispose(); ho_RegionFillUpL.Dispose(); ho_ContoursSplitL.Dispose(); ho_SelectedContoursL.Dispose(); ho_UnionContoursL.Dispose(); ho_RegionL.Dispose(); ho_RegionDifferenceL.Dispose(); ho_ContoursR.Dispose(); ho_RegionLinesR.Dispose(); ho_RegionLinesR1.Dispose(); ho_RegionUnionR.Dispose(); ho_ConnectedRegionsR.Dispose(); ho_SelectedRegionsR.Dispose(); ho_RegionFillUpR.Dispose(); ho_ContoursSplitR.Dispose(); ho_SelectedContoursR.Dispose(); ho_UnionContoursR.Dispose(); ho_RegionR.Dispose(); ho_RegionDifferenceR.Dispose(); ho_ConnectedRegions1.Dispose(); ho_ObjectSelected1.Dispose(); algorithm.Region.Dispose(); } }
private void OnImageProcessedEvent(CCamera instance, HObject ho_Image) { try { if (InvokeRequired) { Invoke(new CCamera.OnImageProcessedEventHandler(OnImageProcessedEvent), new object[] { instance, ho_Image }); return; } kk++; //Console.WriteLine("kk:" +kk); instance.tempImage.Dispose(); HOperatorSet.CopyImage(instance.Image, out instance.tempImage); HTuple cwindow = new HTuple(); switch (instance.logicName) { case "CCD1": cwindow = hWindowControl1.HalconWindow; break; case "CCD2": cwindow = hWindowControl2.HalconWindow; break; case "CCD3": cwindow = hWindowControl3.HalconWindow; break; case "CCD4": cwindow = hWindowControl4.HalconWindow; break; case "CCD5": cwindow = hWindowControl5.HalconWindow; break; //case "CCD6": cwindow = hWindowControl6.HalconWindow; // break; } for (int i = 0; i < 6; i++) { if (instance.logicName == "CCD" + i.ToString()) { HOperatorSet.SetColor(cwindow, "green"); HOperatorSet.SetDraw(cwindow, "margin"); HTuple w, h; HOperatorSet.GetImageSize(ho_Image, out w, out h); HOperatorSet.SetPart(cwindow, 0, 0, h, w); HOperatorSet.DispObj(ho_Image, cwindow); if (instance.RegionToDisp.IsInitialized() && instance.resultHTuple.Length > 0) { HOperatorSet.DispObj(instance.RegionToDisp, cwindow); HalconHelp.set_display_font(cwindow, 14, "courier", "false", "false"); HalconHelp.disp_message(cwindow, instance.resultHTuple, "window", 10, 10, "green", "false"); } } } switch (instance.logicName) { case "CCD1": cwindow = hWindowControl6.HalconWindow; break; case "CCD2": cwindow = hWindowControl7.HalconWindow; break; case "CCD3": cwindow = hWindowControl8.HalconWindow; break; case "CCD4": cwindow = hWindowControl9.HalconWindow; break; case "CCD5": cwindow = hWindowControl10.HalconWindow; break; } for (int i = 0; i < 6; i++) { if (instance.logicName == "CCD" + i.ToString()) { HOperatorSet.SetColor(cwindow, "green"); HOperatorSet.SetDraw(cwindow, "margin"); HTuple w, h; HOperatorSet.GetImageSize(ho_Image, out w, out h); HOperatorSet.SetPart(cwindow, 0, 0, h, w); HOperatorSet.DispObj(ho_Image, cwindow); if (instance.RegionToDisp.IsInitialized() && instance.resultHTuple.Length > 0) { HOperatorSet.DispObj(instance.RegionToDisp, cwindow); //if (instance.logicName == "CCD1") //{ // HalconHelp.set_display_font(cwindow, 14, "courier", "false", "false"); // HalconHelp.disp_message(cwindow, instance.resultHTuple, "window", 2, 2, "green", "false"); //} } } } DataRowCollection drc = ds.Tables["detailTable"].Rows; int rs = 0; string shijian = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString(); string path = PathHelper.currentProductPath + @"\" + shijian + ".txt"; foreach (DataRow dr in drc) { string s = dr[0].ToString(); if (dr[0].ToString() == instance.logicName) { if (instance.result.resultToShow.Count > rs) { double cl = double.Parse(instance.result.resultToShow[rs].data); double xz = (double)dr[2]; dr[5] = Math.Round((cl + xz), 3); if (double.Parse(dr[5].ToString()) <= double.Parse(dr[3].ToString()) && double.Parse(dr[5].ToString()) >= double.Parse(dr[4].ToString())) { dr[6] = "OK"; } else { dr[6] = "NG"; } if (instance.goodcountlist.Count() != 0) { dr[7] = Math.Round((double)(instance.goodcountlist[rs] / (double)Turntable.Instance.pn.totalCount * 100), 2).ToString() + "%"; //Console.WriteLine("" + instance.goodcountlist[rs] + "---" + (double)Turntable.Instance.pn.totalCount); } rs++; } else { dr[5] = 0; } // File.AppendAllText(path,dr[1].ToString() + " " + dr[5].ToString(), Encoding.Default); } } //File.AppendAllText(path,Environment.NewLine, Encoding.Default); DataHelper.CheckData(ds, instance.logicName, instance); } catch (Exception e) { MyDebug.ShowMessage("界面图像处" + e.Message); } finally { ho_Image.Dispose(); instance.RegionToDisp.Dispose(); instance.Image.Dispose(); instance.resultHTuple = new HTuple(); //UpdateProInfo(); } }
public MeasureResult Action() { #region 輸出結果 DistanceResult mResult = null; #endregion HTuple hv_STD_Row; HTuple hv_STD_Col, hv_Img_Row, hv_Img_Col, hv_Img_Rotate_Angle; HTuple hv_OffsetRow, hv_OffsetCol; HOperatorSet.SetSystem("border_shape_models", "false"); //STD 中心點 hv_STD_Row = 839.5; hv_STD_Col = 1046.5; //目前圖形 中心點 hv_Img_Row = hv_AllModelRow.Clone(); hv_Img_Col = hv_AllModelColumn.Clone(); //目前圖形 Rotate Angle hv_Img_Rotate_Angle = hv_AllModelAngle.Clone(); //目前圖形偏移量 hv_OffsetRow = hv_Img_Row - hv_STD_Row; hv_OffsetCol = hv_Img_Col - hv_STD_Col; //第一個 線段 ROI HTuple f_ROI_Row = 353.060546875; HTuple f_ROI_Col = 831.539215686274; HTuple f_angle = 1.5707963267949; HTuple f_ROI_Length1 = 43.041015625; HTuple f_ROI_Length2 = 176.091503267974; HTuple f_angle_offset = f_angle - hv_Img_Rotate_Angle; HTuple f_ROI_Cur_Row, f_ROI_Cur_Col; PositionLocater.ReLocater(hv_STD_Row, hv_STD_Col, hv_AllModelAngle, hv_OffsetRow, hv_OffsetCol, f_ROI_Row, f_ROI_Col, out f_ROI_Cur_Row, out f_ROI_Cur_Col); //第二個 線段 ROI HTuple s_ROI_Row = 856.97265625; HTuple s_ROI_Col = 712.908496732026; HTuple s_angle = -1.5707963267949; HTuple s_ROI_Length1 = 34.48828125; HTuple s_ROI_Length2 = 51.6617647058824; HTuple s_angle_offset = s_angle - hv_Img_Rotate_Angle; HTuple s_ROI_Cur_Row, s_ROI_Cur_Col; PositionLocater.ReLocater(hv_STD_Row, hv_STD_Col, hv_AllModelAngle, hv_OffsetRow, hv_OffsetCol , s_ROI_Row, s_ROI_Col, out s_ROI_Cur_Row, out s_ROI_Cur_Col); /**/ #region Measure var cROIController = new ROIController(); var cAssistant = new MeasureAssistant(cROIController); var hImage = ho_Image as HImage; cAssistant.setImage(hImage); /*參數值*/ cAssistant.mThresh = 40.0; cAssistant.mSigma = 1.0; cAssistant.mRoiWidth = 10; cAssistant.mInterpolation = "nearest_neighbor"; cAssistant.mSelPair = false; cAssistant.mTransition = "all"; cAssistant.mPosition = "all"; cAssistant.mDispEdgeLength = 30; cAssistant.mDispROIWidth = true; cAssistant.setUnit("cm"); cAssistant.mInitThresh = 40.0; cAssistant.mInitSigma = 1.0; cAssistant.mInitRoiWidth = 10; var roiF = new ROIRectangle2() { ROIMeasureType = MeasureType.Line }; //roiF.MakeROI(416, 998, 0, 26.5, 71.2); roiF.MakeROI(f_ROI_Cur_Row, f_ROI_Cur_Col, f_angle_offset, f_ROI_Length1, f_ROI_Length2); var roiS = new ROIRectangle2() { ROIMeasureType = MeasureType.Line }; //roiS.MakeROI(400, 1041, 0, 13.3, 75.7); roiS.MakeROI(s_ROI_Cur_Row, s_ROI_Cur_Col, s_angle_offset, s_ROI_Length1, s_ROI_Length2); var lineF = new MeasurementEdge(roiF, cAssistant); var lineS = new MeasurementEdge(roiS, cAssistant); mResult = DistanceHelper.LineToLine(lineF, lineS, this.hv_AllModelAngle, LineDirection.Vertical); #endregion return(mResult); }
// Main procedure private void action() { // Local iconic variables HObject ho_Rectangle, ho_ImageReduced; HObject ho_Region, ho_Circle; // Local control variables HTuple hv_Row1 = null; HTuple hv_Column1 = null, hv_Radius = 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_Circle); HOperatorSet.Union1(algorithm.Region, out RegionToDisp); try { ho_Rectangle.Dispose(); HOperatorSet.GenRectangle2(out ho_Rectangle, DRow1m, DCol1m, DPhi, DLength1, DLength2); ho_ImageReduced.Dispose(); HOperatorSet.ReduceDomain(Image, ho_Rectangle, out ho_ImageReduced); // ho_ImageMean.Dispose(); // HOperatorSet.MeanImage(ho_ImageReduced, out ho_ImageMean, 30, 30); // ho_RegionDynThresh.Dispose(); // HOperatorSet.DynThreshold(ho_ImageReduced, ho_ImageMean, out ho_RegionDynThresh, // 70, "dark"); ho_Region.Dispose(); HOperatorSet.Threshold(ho_ImageReduced, out ho_Region, 0, 128); HOperatorSet.SmallestCircle(ho_Region, out hv_Row1, out hv_Column1, out hv_Radius); ho_Circle.Dispose(); HOperatorSet.GenCircle(out ho_Circle, hv_Row1, hv_Column1, hv_Radius); HOperatorSet.Union1(ho_Region, out RegionToDisp); HTuple hv_result = GetHv_result(); hv_result = hv_result.TupleConcat("直径"); hv_result = hv_result.TupleConcat(hv_Radius.D * 2 * pixeldist); result = hv_result.Clone(); ho_Rectangle.Dispose(); ho_ImageReduced.Dispose(); ho_Region.Dispose(); ho_Circle.Dispose(); algorithm.Region.Dispose(); } catch { HTuple hv_result = GetHv_result(); 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_Circle.Dispose(); algorithm.Region.Dispose(); } finally { ho_Rectangle.Dispose(); ho_ImageReduced.Dispose(); ho_Region.Dispose(); ho_Circle.Dispose(); algorithm.Region.Dispose(); } }
private void ModelWrite_Click(object sender, EventArgs e) { HObject ImageReduced; HOperatorSet.GenEmptyObj(out ImageReduced); try { hWindowControl1.Focus(); HOperatorSet.DispObj(m_Image, m_hWindowHandle); HTuple Row, Column, Phi, Length1, Length2; HOperatorSet.GenEmptyObj(out ImageReduced); //判断图像是否为空 if (!m_Image.IsInitialized()) { return; } //Model = Vision.Model; //模板不为空,释放掉 vision.Model.ClearShapeModel(ref vision.Model.m_ModelID); //刷新图形 vision.UpdateImage(m_Image, ref m_objDisp, m_hWindowHandle, true); //提示信息 vision.disp_message(m_hWindowHandle, "画模板区域,点击鼠标右键确认", "window", 20, 20, "red", "false"); //画并产生模板区域 HOperatorSet.DrawRectangle2(m_hWindowHandle, out Row, out Column, out Phi, out Length1, out Length2); vision.Model.m_ModelRegion.Dispose(); HOperatorSet.GenRectangle2(out vision.Model.m_ModelRegion, Row, Column, Phi, Length1, Length2); ImageReduced.Dispose(); HOperatorSet.ReduceDomain(m_Image, vision.Model.m_ModelRegion, out ImageReduced); vision.Concat_Obj(ref m_objDisp, ref vision.Model.m_ModelRegion, ref m_objDisp); // m_objDisp.ConcatObj(Vision.Model.m_ModelRegion); //裁剪模板区域图像 // reduce_domain(m_Image,theApp.m_ModelRegion,&ImageReduced); //添加模板区域到显示图形 // concat_obj(m_objDisp,theApp.m_ModelRegion,&m_objDisp); //创建模板 vision.Model.ClearShapeModel(ref vision.Model.m_ModelID); HOperatorSet.CreateShapeModel(ImageReduced, "auto", new HTuple(-180).TupleRad(), new HTuple(360).TupleRad(), "auto", "auto", "use_polarity", "auto", "auto", out vision.Model.m_ModelID); HOperatorSet.DispObj(m_objDisp, m_hWindowHandle); //刷新图形 vision.UpdateImage(m_Image, ref m_objDisp, m_hWindowHandle, false); //提示信息 if (vision.Model.m_ModelID > -1) { vision.disp_message(m_hWindowHandle, "创建模板成功!", "window", 20, 20, "green", "false"); } else { vision.disp_message(m_hWindowHandle, "创建模板失败!", "window", 20, 20, "red", "false"); } } catch (HalconException HDevExpDefaultException) { ImageReduced.Dispose(); vision.UpdateImage(m_Image, ref m_objDisp, m_hWindowHandle, true); vision.disp_message(m_hWindowHandle, "创建模板过程失败!", "window", 20, 20, "red", "false"); // throw HDevExpDefaultException; } ImageReduced.Dispose(); }
//DateTime t1, t2, t3, t4,t5,t6,t7; private void action() { HObject ho_Region = null, ho_RegionClosing = null; HObject ho_RegionErosion = null, ho_ImageReduced = null, ho_Edges = null; HObject ho_SelectedContours = null, ho_SelectedContours1 = null; HObject ho_SelectedContours2 = null, ho_ObjectsConcat = null; HObject ho_Region1 = null, ho_RegionUnion = null, ho_RegionClosing1 = null; HObject ho_ConnectedRegions = null, ho_SelectedRegions = null; HObject ho_Rectangle = null, ho_Rectangle1 = null, ho_ImageReduced1 = null; HObject ho_Edges2 = null, ho_ContoursSplit = null, ho_UnionContours = null; HObject ho_RegionLines = null; // Local control variables HTuple hv_Row = new HTuple(), hv_i = new HTuple(), hv_Sorted = new HTuple(); HTuple hv_Column = new HTuple(), hv_Phi = new HTuple(); HTuple hv_Length1 = new HTuple(), hv_Length2 = new HTuple(); HTuple hv_RowBegin = new HTuple(), hv_ColBegin = new HTuple(); HTuple hv_RowEnd = new HTuple(), hv_ColEnd = new HTuple(); HTuple hv_Nr = new HTuple(), hv_Nc = new HTuple(), hv_Dist = new HTuple(); HTuple hv_RowBeginOut = new HTuple(), hv_ColBeginOut = new HTuple(); HTuple hv_RowEndOut = new HTuple(), hv_ColEndOut = new HTuple(); HTuple hv_Distance = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Region); HOperatorSet.GenEmptyObj(out ho_RegionClosing); HOperatorSet.GenEmptyObj(out ho_RegionErosion); HOperatorSet.GenEmptyObj(out ho_ImageReduced); HOperatorSet.GenEmptyObj(out ho_Edges); HOperatorSet.GenEmptyObj(out ho_SelectedContours); HOperatorSet.GenEmptyObj(out ho_SelectedContours1); HOperatorSet.GenEmptyObj(out ho_SelectedContours2); HOperatorSet.GenEmptyObj(out ho_ObjectsConcat); HOperatorSet.GenEmptyObj(out ho_Region1); HOperatorSet.GenEmptyObj(out ho_RegionUnion); HOperatorSet.GenEmptyObj(out ho_RegionClosing1); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions); HOperatorSet.GenEmptyObj(out ho_SelectedRegions); HOperatorSet.GenEmptyObj(out ho_Rectangle); HOperatorSet.GenEmptyObj(out ho_Rectangle1); HOperatorSet.GenEmptyObj(out ho_ImageReduced1); HOperatorSet.GenEmptyObj(out ho_Edges2); HOperatorSet.GenEmptyObj(out ho_ContoursSplit); HOperatorSet.GenEmptyObj(out ho_UnionContours); HOperatorSet.GenEmptyObj(out ho_RegionLines); HOperatorSet.Union1(algorithm.Region, out RegionToDisp); //t3 = DateTime.Now; try { ho_Region.Dispose(); HOperatorSet.Threshold(Image, out ho_Region, 0, 128); ho_RegionClosing.Dispose(); HOperatorSet.ClosingCircle(ho_Region, out ho_RegionClosing, 33.5); ho_RegionErosion.Dispose(); HOperatorSet.ErosionCircle(ho_RegionClosing, out ho_RegionErosion, 13.5); ho_ImageReduced.Dispose(); HOperatorSet.ReduceDomain(Image, ho_RegionErosion, out ho_ImageReduced); ho_Edges.Dispose(); HOperatorSet.EdgesSubPix(ho_ImageReduced, out ho_Edges, "canny", 1, 20, 20); ho_SelectedContours.Dispose(); HOperatorSet.SelectContoursXld(ho_Edges, out ho_SelectedContours, "contour_length", 10, 400, -0.5, 0.5); ho_SelectedContours1.Dispose(); HOperatorSet.SelectContoursXld(ho_SelectedContours, out ho_SelectedContours1, "direction", (new HTuple(20)).TupleRad(), (new HTuple(70)).TupleRad(), -0.5, 0.5); ho_SelectedContours2.Dispose(); HOperatorSet.SelectContoursXld(ho_SelectedContours, out ho_SelectedContours2, "direction", (new HTuple(110)).TupleRad(), (new HTuple(160)).TupleRad() , -0.5, 0.5); ho_ObjectsConcat.Dispose(); HOperatorSet.ConcatObj(ho_SelectedContours1, ho_SelectedContours2, out ho_ObjectsConcat ); ho_Region1.Dispose(); HOperatorSet.GenRegionContourXld(ho_ObjectsConcat, out ho_Region1, "filled"); ho_RegionUnion.Dispose(); HOperatorSet.Union1(ho_Region1, out ho_RegionUnion); ho_RegionClosing1.Dispose(); HOperatorSet.ClosingCircle(ho_RegionUnion, out ho_RegionClosing1, 15); ho_ConnectedRegions.Dispose(); HOperatorSet.Connection(ho_RegionClosing1, out ho_ConnectedRegions); ho_SelectedRegions.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, "area", "and", 1500, 999990); HOperatorSet.SmallestRectangle2(ho_SelectedRegions, out hv_Row, out hv_Column, out hv_Phi, out hv_Length1, out hv_Length2); if ((int)(new HTuple((new HTuple(hv_Row.TupleLength())).TupleGreater(0))) != 0) { ho_Rectangle.Dispose(); HOperatorSet.GenRectangle2(out ho_Rectangle, hv_Row, hv_Column, hv_Phi, hv_Length1, hv_Length2); ho_Rectangle1.Dispose(); HOperatorSet.GenRectangle2(out ho_Rectangle1, hv_Row1, hv_Column1, hv_Phi1, hv_Length11, hv_Length21); ho_ImageReduced1.Dispose(); HOperatorSet.ReduceDomain(Image, ho_Rectangle1, out ho_ImageReduced1); ho_Edges2.Dispose(); HOperatorSet.EdgesSubPix(ho_ImageReduced1, out ho_Edges2, "canny", 1, 20, 20); ho_ContoursSplit.Dispose(); HOperatorSet.SegmentContoursXld(ho_Edges2, out ho_ContoursSplit, "lines_circles", 5, 4, 2); ho_UnionContours.Dispose(); HOperatorSet.UnionCollinearContoursXld(ho_ContoursSplit, out ho_UnionContours, 1000, 2, 11, 0.1, "attr_keep"); HOperatorSet.FitLineContourXld(ho_UnionContours, "tukey", -1, 0, 5, 2, out hv_RowBegin, out hv_ColBegin, out hv_RowEnd, out hv_ColEnd, out hv_Nr, out hv_Nc, out hv_Dist); if (hv_ColEnd.TupleLength() > 0) { HOperatorSet.SelectLinesLongest(hv_RowBegin, hv_ColBegin, hv_RowEnd, hv_ColEnd, 1, out hv_RowBeginOut, out hv_ColBeginOut, out hv_RowEndOut, out hv_ColEndOut); HOperatorSet.DistancePl(hv_Row, hv_Column, hv_RowBeginOut, hv_ColBeginOut, hv_RowEndOut, hv_ColEndOut, out hv_Distance); ho_RegionLines.Dispose(); HOperatorSet.GenRegionLine(out ho_RegionLines, hv_RowBeginOut, hv_ColBeginOut, hv_RowEndOut, hv_ColEndOut); HOperatorSet.Union2(ho_RegionLines, ho_Rectangle, out RegionToDisp); HOperatorSet.TupleSort(hv_Distance, out hv_Sorted); HTuple hv_result = GetHv_result(); for (hv_i = 0; (int)hv_i <= (int)((new HTuple(hv_Length1.TupleLength())) - 1); hv_i = (int)hv_i + 1) { hv_result = hv_result.TupleConcat("位置" + hv_i.I.ToString()); hv_result = hv_result.TupleConcat(hv_Sorted.TupleSelect(hv_i) * pixeldist); } result = hv_result.Clone(); } ho_Region.Dispose(); ho_RegionClosing.Dispose(); ho_RegionErosion.Dispose(); ho_ImageReduced.Dispose(); ho_Edges.Dispose(); ho_SelectedContours.Dispose(); ho_SelectedContours1.Dispose(); ho_SelectedContours2.Dispose(); ho_ObjectsConcat.Dispose(); ho_Region1.Dispose(); ho_RegionUnion.Dispose(); ho_RegionClosing1.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions.Dispose(); ho_Rectangle.Dispose(); ho_Rectangle1.Dispose(); ho_ImageReduced1.Dispose(); ho_Edges2.Dispose(); ho_ContoursSplit.Dispose(); ho_UnionContours.Dispose(); ho_RegionLines.Dispose(); algorithm.Region.Dispose(); //t4 = DateTime.Now; } else { HTuple hv_result = GetHv_result(); for (hv_i = 0; (int)hv_i <= 10; hv_i = (int)hv_i + 1) { hv_result = hv_result.TupleConcat("位置" + hv_i.I.ToString()); hv_result = hv_result.TupleConcat(0); } result = hv_result.Clone(); ho_Region.Dispose(); ho_RegionClosing.Dispose(); ho_RegionErosion.Dispose(); ho_ImageReduced.Dispose(); ho_Edges.Dispose(); ho_SelectedContours.Dispose(); ho_SelectedContours1.Dispose(); ho_SelectedContours2.Dispose(); ho_ObjectsConcat.Dispose(); ho_Region1.Dispose(); ho_RegionUnion.Dispose(); ho_RegionClosing1.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions.Dispose(); ho_Rectangle.Dispose(); ho_Rectangle1.Dispose(); ho_ImageReduced1.Dispose(); ho_Edges2.Dispose(); ho_ContoursSplit.Dispose(); ho_UnionContours.Dispose(); ho_RegionLines.Dispose(); } } catch { HTuple hv_result = GetHv_result(); for (hv_i = 0; (int)hv_i <= 10; hv_i = (int)hv_i + 1) { hv_result = hv_result.TupleConcat("位置" + hv_i.I.ToString()); hv_result = hv_result.TupleConcat(0); } result = hv_result.Clone(); ho_Region.Dispose(); ho_RegionClosing.Dispose(); ho_RegionErosion.Dispose(); ho_ImageReduced.Dispose(); ho_Edges.Dispose(); ho_SelectedContours.Dispose(); ho_SelectedContours1.Dispose(); ho_SelectedContours2.Dispose(); ho_ObjectsConcat.Dispose(); ho_Region1.Dispose(); ho_RegionUnion.Dispose(); ho_RegionClosing1.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions.Dispose(); ho_Rectangle.Dispose(); ho_Rectangle1.Dispose(); ho_ImageReduced1.Dispose(); ho_Edges2.Dispose(); ho_ContoursSplit.Dispose(); ho_UnionContours.Dispose(); ho_RegionLines.Dispose(); } }
public RectData FindRectNew(HObject ho_Image, double calival) { RectData myResult = new RectData(); myResult.Found = false; try { HTuple hv_Width, hv_Height, hv_Mean, hv_Deviation; HObject ho_Rect, ho_EmptyImage, hv_selectedShape, ho_ConnectedRegion, ho_ShapeModelRegion, hV_reducedImg; HObject ho_ShapeModel; HTuple hv_RowCheck = new HTuple(), hv_ColumnCheck = new HTuple(); HTuple hv_AngleCheck = new HTuple(), hv_ScaleCheck = new HTuple(); HTuple hv_Score = new HTuple(), hv_j = new HTuple(), hv_MovementOfObject = new HTuple(); HTuple hv_MoveAndScaleOfObject = new HTuple(); hv_Mean = new HTuple(); hv_Deviation = new HTuple(); HTuple hv_Y, hv_X, hv_AngRad, hv_HalfWidth, hv_HalfLength, hv_PtOrder; HObject ho_Rectangle; hv_Width = new HTuple(); hv_Height = new HTuple(); hv_Y = new HTuple(); hv_X = new HTuple(); hv_AngRad = new HTuple(); hv_HalfWidth = new HTuple(); hv_HalfLength = new HTuple(); hv_PtOrder = new HTuple(); HTuple hv_Number = new HTuple(); //Init Variable HOperatorSet.GenEmptyObj(out ho_Rect); HOperatorSet.GenEmptyObj(out ho_EmptyImage); HOperatorSet.GenEmptyObj(out hv_selectedShape); HOperatorSet.GenEmptyObj(out ho_ConnectedRegion); HOperatorSet.GenEmptyObj(out ho_ShapeModelRegion); HOperatorSet.GenEmptyObj(out ho_ShapeModel); HOperatorSet.GenEmptyObj(out hV_reducedImg); //HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height); //HOperatorSet.SetWindowAttr("background_color", "black"); HOperatorSet.Threshold(ho_Image, out ho_ShapeModelRegion, 53, 255); HOperatorSet.Connection(ho_ShapeModelRegion, out ho_ConnectedRegion); //HOperatorSet.CountObj(ho_ConnectedRegion, out hv_Number); HOperatorSet.SelectShape(ho_ConnectedRegion, out hv_selectedShape, "area", "and", 150000, 330000); //Alvin 28July16 2500 HOperatorSet.SmallestRectangle2(hv_selectedShape, out hv_Y, out hv_X, out hv_AngRad, out hv_HalfWidth, out hv_HalfLength); if (hv_X.Length != 0) { //20161224@Brando int i = 0; HTuple h_temp = 0; for (int t = 0; t < hv_X.Length; t++) { if (hv_Y[t] > h_temp) { h_temp = hv_Y[t]; i = t; } } HOperatorSet.GenRectangle2(out ho_Rectangle, hv_Y[i].D, hv_X[i].D, hv_AngRad[i].D, hv_HalfWidth[i].D, hv_HalfLength[i].D); HOperatorSet.Intensity(ho_Rectangle, ho_Image, out hv_Mean, out hv_Deviation); myResult.Means = hv_Mean.D; //20161027 HOperatorSet.ReduceDomain(ho_Image, ho_Rectangle, out hV_reducedImg); HOperatorSet.CropDomain(hV_reducedImg, out myResult.InspectedImage); if ((myResult.Means > 90) && (myResult.Means < 160))//20161101 FROM 220 TO 230 { myResult.Found = true; myResult.X = hv_X[i].D; myResult.Y = hv_Y[i].D; myResult.Angle = hv_AngRad[i].D; myResult.Width = hv_HalfWidth[i].D * 2; myResult.Height = hv_HalfLength[i].D * 2; myResult.isCircle = false; //myResult.rect_border = ho_Rectangle;//hv_selectedShape; if (Para.isWidth818) { if ((myResult.X < 200) || (myResult.X - hv_HalfWidth[i].D) < (0.2 / calival) || (myResult.X + hv_HalfWidth[i].D + (0.2 / calival)) > 2583 || (myResult.Height < 150) || (myResult.Y < 300) || (myResult.Width < (7.721 / calival)) || (myResult.Width > (8.639 / calival)) || (myResult.Angle * 180 / 3.14 > 10) || (myResult.Angle * 180 / 3.14 < -10)) { myResult.Found = false; } } else { if ((myResult.X < 200) || (myResult.X - hv_HalfWidth[i].D) < (0.2 / calival) || (myResult.X + hv_HalfWidth[i].D + (0.2 / calival)) > 2583 || (myResult.Height < 150) || (myResult.Y < 300) || (myResult.Width < (8.74 / calival)) || (myResult.Width > 9.66 / calival) || (myResult.Angle * 180 / 3.14 > 10) || (myResult.Angle * 180 / 3.14 < -10)) { myResult.Found = false; } } } } } catch (Exception ex) { } return(myResult); }
public RectData FindCircle(HObject ho_Image) { RectData myResult = new RectData(); HTuple hv_Width, hv_Height, hv_Mean, hv_Deviation; HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height); HOperatorSet.SetWindowAttr("background_color", "black"); HTuple hv_RadiusCircle, hv_SizeSynthImage; HObject ho_Circle, ho_EmptyImage, ho_SyntheticModelImage, ho_ShapeModelImage, ho_ShapeModelRegion; HObject ho_ShapeModel; HTuple hv_ModelID, hv_RowCheck = new HTuple(), hv_ColumnCheck = new HTuple(); HTuple hv_AngleCheck = new HTuple(), hv_ScaleCheck = new HTuple(); HTuple hv_Score = new HTuple(), hv_j = new HTuple(), hv_MovementOfObject = new HTuple(); HTuple hv_MoveAndScaleOfObject = new HTuple(); hv_Mean = new HTuple(); hv_Deviation = new HTuple(); HObject hV_reducedImg; //Init Variable HOperatorSet.GenEmptyObj(out ho_Circle); HOperatorSet.GenEmptyObj(out ho_EmptyImage); HOperatorSet.GenEmptyObj(out ho_SyntheticModelImage); HOperatorSet.GenEmptyObj(out ho_ShapeModelImage); HOperatorSet.GenEmptyObj(out ho_ShapeModelRegion); HOperatorSet.GenEmptyObj(out ho_ShapeModel); HOperatorSet.GenEmptyObj(out hV_reducedImg); //step 1: Generate Default Circle Shape hv_RadiusCircle = 190; hv_SizeSynthImage = (2 * hv_RadiusCircle) + 10; ho_Circle.Dispose(); HOperatorSet.GenEllipseContourXld(out ho_Circle, hv_SizeSynthImage / 2, hv_SizeSynthImage / 2, 0, hv_RadiusCircle, hv_RadiusCircle, 0, 6.28318, "positive", 1.5); //step 2: create an image and insert the XLD ho_EmptyImage.Dispose(); HOperatorSet.GenImageConst(out ho_EmptyImage, "byte", hv_SizeSynthImage, hv_SizeSynthImage); ho_SyntheticModelImage.Dispose(); HOperatorSet.PaintXld(ho_Circle, ho_EmptyImage, out ho_SyntheticModelImage, 128); //step 3: create the model ho_ShapeModelImage.Dispose(); ho_ShapeModelRegion.Dispose(); HOperatorSet.InspectShapeModel(ho_SyntheticModelImage, out ho_ShapeModelImage, out ho_ShapeModelRegion, 1, 30); HOperatorSet.CreateScaledShapeModel(ho_SyntheticModelImage, "auto", 0, 0, 0.01, 0.8, 1.2, "auto", "none", "use_polarity", 30, 10, out hv_ModelID); ho_ShapeModel.Dispose(); HOperatorSet.GetShapeModelContours(out ho_ShapeModel, hv_ModelID, 1); //Step 4 : Find the Circle HOperatorSet.FindScaledShapeModel(ho_Image, hv_ModelID, 0, 0, 0.4, 1.6, 0.6, 0, 0.5, "least_squares", 3, 0, out hv_RowCheck, out hv_ColumnCheck, out hv_AngleCheck, out hv_ScaleCheck, out hv_Score); List <DPoint> CirCtr = new List <DPoint>(); if ((hv_Score.Length != 0) && (hv_RadiusCircle > 100)) { for (int i = 0; i < hv_Score.Length; i++) { CirCtr.Add(new DPoint(hv_ColumnCheck[i].D, hv_RowCheck[i].D)); HObject ho_Rect = new HObject(); HOperatorSet.GenCircle(out ho_Rect, hv_RowCheck[i].D, hv_ColumnCheck[i].D, hv_RadiusCircle * hv_ScaleCheck[i].D); HOperatorSet.Intensity(ho_Rect, ho_Image, out hv_Mean, out hv_Deviation); //myResult.Means = hv_Mean.D; //HOperatorSet.RegionToLabel(ho_Rect, out myResult.InspectedImage, "byte", hv_RadiusCircle * hv_ScaleCheck[i].D * 2, hv_RadiusCircle * hv_ScaleCheck[i].D * 2); //string DataFileName = @"D:\"; //string temp1 = DataFileName + "Test"; //HOperatorSet.WriteImage(myResult.InspectedImage, "bmp", 0, temp1); if ((hv_Mean.D > 100))//(myResult.Means < 220) && { HOperatorSet.ReduceDomain(ho_Image, ho_Rect, out hV_reducedImg); HOperatorSet.CropDomain(hV_reducedImg, out myResult.InspectedImage); myResult.Found = true; myResult.X = hv_ColumnCheck[i].D; myResult.Y = hv_RowCheck[i].D; myResult.Radius = hv_RadiusCircle * hv_ScaleCheck[i].D; myResult.isCircle = true; myResult.Means = hv_Mean.D; //break; } //myResult.InspectedImage = ho_Rect; } } //if (myResult.Found) //{ // if (CirCtr.Count == 2) // { // myResult.Angle = Helper.GetRadianAngleBetween(CirCtr[0], CirCtr[1]); // } //} return(myResult); }
/// <summary> /// 黑点检测20171010 /// </summary> /// <param name="barcode"></param> /// <param name="ho_Image"></param> /// <param name="pixel_MM"></param> /// <returns></returns> public BlackParaList BlackDotInspect(string barcode, string modle, HObject ho_Image, double pixel_MM, string ImagePath) { BlackParaList blackParaReturn = new BlackParaList(); // Local iconic variables HObject ho_Domain11, ho_ImageScaled; HObject ho_Regions, ho_RegionFillUp, ho_SelectObjregion; HObject ho_RegionErosion, ho_ImageReduced1, ho_ImageEmphasize; HObject ho_Region2, ho_ConnectedRegions, ho_SelectedRegions; HObject ho_RegionDilation = null, ho_Circle = null, ho_ImageResult = null; // Local control variables HTuple hv_AbsoluteHisto, hv_RelativeHisto; HTuple hv_Max, hv_maxGrayValue; HTuple hv_NumDot = null, hv_Name = null, hv_Width = null, hv_RowY = null, hv_ColumnX = null, hv_Area1 = null; HTuple hv_Height = null, hv_radius_MM = null, hv_radius_Pixel = null; HTuple hv_area_Pixel = null, hv_Number = null, hv_Row = new HTuple(); HTuple hv_Column = new HTuple(), hv_Radius = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_SelectObjregion); HOperatorSet.GenEmptyObj(out ho_Regions); HOperatorSet.GenEmptyObj(out ho_RegionFillUp); HOperatorSet.GenEmptyObj(out ho_RegionErosion); HOperatorSet.GenEmptyObj(out ho_ImageReduced1); HOperatorSet.GenEmptyObj(out ho_ImageEmphasize); HOperatorSet.GenEmptyObj(out ho_Region2); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions); HOperatorSet.GenEmptyObj(out ho_SelectedRegions); HOperatorSet.GenEmptyObj(out ho_RegionDilation); HOperatorSet.GenEmptyObj(out ho_Circle); HOperatorSet.GenEmptyObj(out ho_ImageResult); HOperatorSet.GenEmptyObj(out ho_Domain11); HOperatorSet.GenEmptyObj(out ho_ImageScaled); hv_NumDot = 0; hv_Name = barcode; HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height); ho_Domain11.Dispose(); HOperatorSet.GetDomain(ho_Image, out ho_Domain11); HOperatorSet.GrayHisto(ho_Domain11, ho_Image, out hv_AbsoluteHisto, out hv_RelativeHisto); HOperatorSet.TupleMax(hv_AbsoluteHisto, out hv_Max); hv_maxGrayValue = hv_AbsoluteHisto.TupleFind(hv_Max); ho_ImageScaled.Dispose(); HOperatorSet.ScaleImage(ho_Image, out ho_ImageScaled, 1, 140 - hv_maxGrayValue[0]); ho_ImageEmphasize.Dispose(); HOperatorSet.Emphasize(ho_ImageScaled, out ho_ImageEmphasize, 39, 39, 2); ho_Regions.Dispose(); HOperatorSet.Threshold(ho_ImageEmphasize, out ho_Regions, 50, 232); ho_RegionFillUp.Dispose(); HOperatorSet.FillUp(ho_Regions, out ho_RegionFillUp); ho_RegionErosion.Dispose(); HOperatorSet.ErosionCircle(ho_RegionFillUp, out ho_RegionErosion, 1); ho_ImageReduced1.Dispose(); HOperatorSet.ReduceDomain(ho_ImageEmphasize, ho_RegionErosion, out ho_ImageReduced1); ho_Region2.Dispose(); HOperatorSet.VarThreshold(ho_ImageReduced1, out ho_Region2, hv_Width, hv_Height, 2, 100, "dark"); ho_ConnectedRegions.Dispose(); HOperatorSet.Connection(ho_Region2, out ho_ConnectedRegions); hv_radius_MM = pixel_MM; hv_radius_Pixel = 20 / hv_radius_MM; hv_area_Pixel = 0.005 / (pixel_MM * pixel_MM); ho_SelectedRegions.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, "area", "and", hv_area_Pixel, 99999); HOperatorSet.CountObj(ho_SelectedRegions, out hv_Number); hv_NumDot = hv_Number.Clone(); if (hv_NumDot.I > 5) { blackParaReturn.blackCounts = 5; } else { blackParaReturn.blackCounts = hv_NumDot.I; } if ((int)(new HTuple(hv_NumDot.TupleGreater(0))) != 0) { ho_RegionDilation.Dispose(); HOperatorSet.DilationCircle(ho_SelectedRegions, out ho_RegionDilation, 5); HOperatorSet.SmallestCircle(ho_RegionDilation, out hv_Row, out hv_Column, out hv_Radius); ho_Circle.Dispose(); HOperatorSet.GenCircle(out ho_Circle, hv_Row, hv_Column, hv_Radius); ho_ImageResult.Dispose(); HOperatorSet.PaintRegion(ho_Circle, ho_Image, out ho_ImageResult, 0, "margin"); string fileName = ImagePath + "\\" + barcode + ".bmp"; HOperatorSet.WriteImage(ho_ImageResult, "bmp", 0, fileName); string fileName1 = ImagePath + "\\" + "Original" + barcode + ".bmp"; HOperatorSet.WriteImage(ho_Image, "bmp", 0, fileName1); if (hv_NumDot.I > 5) { for (int j = 0; j < 5; j++) { ho_SelectObjregion.Dispose(); HOperatorSet.SelectObj(ho_SelectedRegions, out ho_SelectObjregion, j + 1); HOperatorSet.AreaCenter(ho_SelectObjregion, out hv_RowY, out hv_ColumnX, out hv_Area1); blackParaReturn.blackX[j] = (float)Math.Round(hv_ColumnX.D * pixel_MM, 3); blackParaReturn.blackY[j] = (float)Math.Round(hv_RowY.D * pixel_MM, 3); blackParaReturn.blackArea[j] = (float)Math.Round(hv_Area1.D * pixel_MM * pixel_MM, 3); } } else { for (int j = 0; j < hv_NumDot.I; j++) { ho_SelectObjregion.Dispose(); HOperatorSet.SelectObj(ho_SelectedRegions, out ho_SelectObjregion, j + 1); HOperatorSet.AreaCenter(ho_SelectObjregion, out hv_RowY, out hv_ColumnX, out hv_Area1); blackParaReturn.blackX[j] = (float)Math.Round(hv_ColumnX.D * pixel_MM, 3); blackParaReturn.blackY[j] = (float)Math.Round(hv_RowY.D * pixel_MM, 3); blackParaReturn.blackArea[j] = (float)Math.Round(hv_Area1.D * pixel_MM * pixel_MM, 3); } } } ho_SelectObjregion.Dispose(); ho_Regions.Dispose(); ho_RegionFillUp.Dispose(); ho_RegionErosion.Dispose(); ho_ImageReduced1.Dispose(); ho_ImageEmphasize.Dispose(); ho_Region2.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions.Dispose(); ho_RegionDilation.Dispose(); ho_Circle.Dispose(); ho_ImageResult.Dispose(); ho_Domain11.Dispose(); ho_ImageScaled.Dispose(); return(blackParaReturn); }
public RectData FindRect(HObject ho_Image, int threshold) { RectData myResult = new RectData(); myResult.Found = false; try { HTuple hv_Width, hv_Height, hv_Y, hv_X, hv_AngRad, hv_HalfWidth, hv_HalfLength, hv_PtOrder, hv_Mean, hv_Deviation; HObject hv_border, hv_selectedShape, hv_connection, ho_Rectangle, ho_ImageReduced; hv_Width = new HTuple(); hv_Height = new HTuple(); hv_Y = new HTuple(); hv_X = new HTuple(); hv_AngRad = new HTuple(); hv_HalfWidth = new HTuple(); hv_HalfLength = new HTuple(); hv_PtOrder = new HTuple(); HTuple hv_Number = new HTuple(); hv_Mean = new HTuple(); hv_Deviation = new HTuple(); HOperatorSet.GenEmptyObj(out hv_border); HOperatorSet.GenEmptyObj(out hv_selectedShape); HOperatorSet.GenEmptyObj(out hv_connection); HOperatorSet.GenEmptyObj(out ho_Rectangle); HOperatorSet.GenEmptyObj(out ho_ImageReduced); HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height); HOperatorSet.SetWindowAttr("background_color", "black"); HTuple hv_Row, hv_Column, hv_Phi; HTuple hv_Length1, hv_Length2; //Create template hv_Row = 972; hv_Column = 1290; hv_Phi = 0; hv_Length1 = 1270; hv_Length2 = 500; string DataFileName = @"D:\Images\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\"; //if (!Directory.Exists(DataFileName)) // Directory.CreateDirectory(DataFileName); //string temp1 = DataFileName + "Inspected" + DateTime.Now.ToString("HH_mm_ss"); //HOperatorSet.WriteImage(ho_Image, "bmp", 0, temp1); ho_Rectangle.Dispose(); HOperatorSet.GenRectangle2(out ho_Rectangle, hv_Row, hv_Column, hv_Phi, hv_Length1, hv_Length2); //ho_ImageReduced.Dispose(); //HOperatorSet.ReduceDomain(ho_Image, ho_Rectangle, out ho_ImageReduced); //string temp1 = DataFileName + "ReducedInspected" + DateTime.Now.ToString("HH_mm_ss"); //HOperatorSet.WriteImage(ho_ImageReduced, "bmp", 0, temp1); HOperatorSet.ThresholdSubPix(ho_Image, out hv_border, threshold); //HOperatorSet.EdgesSubPix(ho_Image, out hv_border, "canny", 0.9, 20, 40); HOperatorSet.SelectShapeXld(hv_border, out hv_selectedShape, "area", "and", 250000, 600000); //Alvin 28July16 2500 HOperatorSet.CountObj(hv_selectedShape, out hv_Number); HOperatorSet.FitRectangle2ContourXld(hv_selectedShape, "tukey", -1, 0, 0, 3, 2, out hv_Y, out hv_X, out hv_AngRad, out hv_HalfWidth, out hv_HalfLength, out hv_PtOrder); if (hv_X.Length != 0) { for (int i = 0; i < hv_X.Length; i++) { ho_Rectangle.Dispose(); HOperatorSet.GenRectangle2(out ho_Rectangle, hv_Y[i].D, hv_X[i].D, hv_AngRad[i].D, hv_HalfWidth[i].D, hv_HalfLength[i].D); //HOperatorSet.GenRectangle2(out ho_Rectangle, hv_Y[i], hv_X[i], hv_AngRad[i], hv_HalfWidth[i], hv_HalfLength[i]); //string temp1 = DataFileName + "InspectedRectangle" + DateTime.Now.ToString("HH_mm_ss"); //HOperatorSet.WriteImage(ho_Rectangle, "bmp", 0, temp1); HOperatorSet.Intensity(ho_Rectangle, ho_Image, out hv_Mean, out hv_Deviation); myResult.Means = hv_Mean.D; if (myResult.Means < 220) { myResult.Found = true; myResult.X = hv_X[i].D; myResult.Y = hv_Y[i].D; myResult.Angle = hv_AngRad[i].D; myResult.Width = hv_HalfWidth[i].D * 2; myResult.Height = hv_HalfLength[i].D * 2; myResult.isCircle = false; //myResult.rect_border = ho_Rectangle;//hv_selectedShape; if ((myResult.X < 200) || (myResult.Height < 170) || (myResult.Y < 300)) { myResult.Found = false; } else { break; } } } } } catch (Exception ex) { } return(myResult); //} //catch (HalconException HDevExpDefaultException) //{ // return myResult; //} }
public WhiteParaList WhiteDotInspect1(string barcode, string modle, HObject ho_Image, double pixel_MM, string ImagePath) { WhiteParaList WhiteParaReturn = new WhiteParaList(); // Stack for temporary objects HObject[] OTemp = new HObject[20]; long SP_O = 0; // Local iconic variables // Initialize local and output iconic variables HObject ho_EmptyRegion, ho_Region, ho_SelectObjregion; HObject ho_RegionFillUp, ho_RegionErosion, ho_RegionDifference; HObject ho_ImageReduced, ho_Region1, ho_ConnectedRegions; HObject ho_SelectedRegions, ho_ImageReduced1, ho_ImageEmphasize; HObject ho_Region2, ho_ConnectedRegions1, ho_SelectedRegions1; HObject ho_RegionDilation = null, ho_Circle = null, ho_ImageResult = null; HObject ho_Domain11, ho_ImageScaled; // Local control variables HTuple hv_Width, hv_Height, hv_Mean, hv_Deviation, hv_RowY = null, hv_ColumnX = null, hv_Area1 = null;; HTuple hv_meanResult, hv_Number, hv_Number1, hv_Number2, hv_NumDot = null; HTuple hv_Row = new HTuple(), hv_Column = new HTuple(), hv_Radius = new HTuple(); HTuple hv_Index = new HTuple(); HTuple hv_AbsoluteHisto, hv_RelativeHisto; HTuple hv_Max, hv_maxGrayValue; // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_SelectObjregion); HOperatorSet.GenEmptyObj(out ho_EmptyRegion); HOperatorSet.GenEmptyObj(out ho_Region); HOperatorSet.GenEmptyObj(out ho_RegionFillUp); HOperatorSet.GenEmptyObj(out ho_RegionErosion); HOperatorSet.GenEmptyObj(out ho_RegionDifference); HOperatorSet.GenEmptyObj(out ho_ImageReduced); HOperatorSet.GenEmptyObj(out ho_Region1); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions); HOperatorSet.GenEmptyObj(out ho_SelectedRegions); HOperatorSet.GenEmptyObj(out ho_ImageReduced1); HOperatorSet.GenEmptyObj(out ho_ImageEmphasize); HOperatorSet.GenEmptyObj(out ho_Region2); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions1); HOperatorSet.GenEmptyObj(out ho_SelectedRegions1); HOperatorSet.GenEmptyObj(out ho_RegionDilation); HOperatorSet.GenEmptyObj(out ho_Circle); HOperatorSet.GenEmptyObj(out ho_ImageResult); HOperatorSet.GenEmptyObj(out ho_Domain11); HOperatorSet.GenEmptyObj(out ho_ImageScaled); HTuple hv_radius_MM = null, hv_area_Pixel = null; hv_radius_MM = pixel_MM; hv_area_Pixel = 0.005 / (pixel_MM * pixel_MM); HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height); ho_EmptyRegion.Dispose(); HOperatorSet.GenEmptyRegion(out ho_EmptyRegion); ho_Domain11.Dispose(); HOperatorSet.GetDomain(ho_Image, out ho_Domain11); HOperatorSet.GrayHisto(ho_Domain11, ho_Image, out hv_AbsoluteHisto, out hv_RelativeHisto); HOperatorSet.TupleMax(hv_AbsoluteHisto, out hv_Max); hv_maxGrayValue = hv_AbsoluteHisto.TupleFind(hv_Max); ho_ImageScaled.Dispose(); HOperatorSet.ScaleImage(ho_Image, out ho_ImageScaled, 1, 140 - hv_maxGrayValue[0]); ho_Region.Dispose(); HOperatorSet.Threshold(ho_ImageScaled, out ho_Region, 80, 255); ho_RegionFillUp.Dispose(); HOperatorSet.FillUp(ho_Region, out ho_RegionFillUp); ho_RegionErosion.Dispose(); HOperatorSet.ErosionCircle(ho_RegionFillUp, out ho_RegionErosion, 30); ho_RegionDifference.Dispose(); HOperatorSet.Difference(ho_RegionFillUp, ho_RegionErosion, out ho_RegionDifference ); ho_ImageReduced.Dispose(); HOperatorSet.ReduceDomain(ho_Image, ho_RegionDifference, out ho_ImageReduced); HOperatorSet.Intensity(ho_RegionDifference, ho_ImageReduced, out hv_Mean, out hv_Deviation); hv_meanResult = hv_Mean * 1.6; if ((int)(new HTuple(hv_meanResult.TupleGreater(240))) != 0) { hv_meanResult = 240; } ho_Region1.Dispose(); HOperatorSet.Threshold(ho_ImageReduced, out ho_Region1, hv_meanResult, 255); ho_ConnectedRegions.Dispose(); HOperatorSet.Connection(ho_Region1, out ho_ConnectedRegions); ho_SelectedRegions.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, "area", "and", hv_area_Pixel, 99999); HOperatorSet.CountObj(ho_SelectedRegions, out hv_Number); if ((int)(new HTuple(hv_Number.TupleGreater(0))) != 0) { OTemp[SP_O] = ho_EmptyRegion.CopyObj(1, -1); SP_O++; ho_EmptyRegion.Dispose(); HOperatorSet.ConcatObj(OTemp[SP_O - 1], ho_SelectedRegions, out ho_EmptyRegion ); OTemp[SP_O - 1].Dispose(); SP_O = 0; } ho_ImageReduced1.Dispose(); HOperatorSet.ReduceDomain(ho_Image, ho_RegionErosion, out ho_ImageReduced1); ho_ImageEmphasize.Dispose(); HOperatorSet.Emphasize(ho_ImageReduced1, out ho_ImageEmphasize, 11, 11, 1); ho_Region2.Dispose(); HOperatorSet.VarThreshold(ho_ImageEmphasize, out ho_Region2, hv_Width, hv_Height, 0.2, 120, "light"); ho_ConnectedRegions1.Dispose(); HOperatorSet.Connection(ho_Region2, out ho_ConnectedRegions1); ho_SelectedRegions1.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions1, out ho_SelectedRegions1, "area", "and", hv_area_Pixel, 99999); HOperatorSet.CountObj(ho_SelectedRegions1, out hv_Number1); if ((int)(new HTuple(hv_Number1.TupleGreater(0))) != 0) { OTemp[SP_O] = ho_EmptyRegion.CopyObj(1, -1); SP_O++; ho_EmptyRegion.Dispose(); HOperatorSet.ConcatObj(OTemp[SP_O - 1], ho_SelectedRegions1, out ho_EmptyRegion ); OTemp[SP_O - 1].Dispose(); SP_O = 0; } HOperatorSet.CountObj(ho_EmptyRegion, out hv_Number2); hv_NumDot = hv_Number2 - 1; if (hv_NumDot.I > 5) { WhiteParaReturn.whiteCounts = 5; } else { WhiteParaReturn.whiteCounts = hv_NumDot.I; } if ((int)(new HTuple(hv_Number2.TupleGreater(1))) != 0) { ho_RegionDilation.Dispose(); HOperatorSet.DilationCircle(ho_EmptyRegion, out ho_RegionDilation, 5); HOperatorSet.SmallestCircle(ho_RegionDilation, out hv_Row, out hv_Column, out hv_Radius); ho_Circle.Dispose(); HOperatorSet.GenCircle(out ho_Circle, hv_Row, hv_Column, hv_Radius); ho_ImageResult.Dispose(); HOperatorSet.PaintRegion(ho_Circle, ho_Image, out ho_ImageResult, 0, "margin"); string fileName = ImagePath + "\\" + barcode + ".bmp"; HOperatorSet.WriteImage(ho_ImageResult, "bmp", 0, fileName); string fileName1 = ImagePath + "\\" + "Original" + barcode + ".bmp"; HOperatorSet.WriteImage(ho_Image, "bmp", 0, fileName1); if (hv_NumDot.I > 5) { for (int j = 0; j < 5; j++) { ho_SelectObjregion.Dispose(); HOperatorSet.SelectObj(ho_EmptyRegion, out ho_SelectObjregion, j + 2); HOperatorSet.AreaCenter(ho_SelectObjregion, out hv_RowY, out hv_ColumnX, out hv_Area1); WhiteParaReturn.whiteX[j] = (float)Math.Round(hv_ColumnX.D * pixel_MM, 3); WhiteParaReturn.whiteY[j] = (float)Math.Round(hv_RowY.D * pixel_MM, 3); WhiteParaReturn.whiteArea[j] = (float)Math.Round(hv_Area1.D * pixel_MM * pixel_MM, 3); } } else { for (int j = 0; j < hv_NumDot.I; j++) { ho_SelectObjregion.Dispose(); HOperatorSet.SelectObj(ho_EmptyRegion, out ho_SelectObjregion, j + 2); HOperatorSet.AreaCenter(ho_SelectObjregion, out hv_RowY, out hv_ColumnX, out hv_Area1); WhiteParaReturn.whiteX[j] = (float)Math.Round(hv_ColumnX.D * pixel_MM, 3); WhiteParaReturn.whiteY[j] = (float)Math.Round(hv_RowY.D * pixel_MM, 3); WhiteParaReturn.whiteArea[j] = (float)Math.Round(hv_Area1.D * pixel_MM * pixel_MM, 3); } } } ho_SelectObjregion.Dispose(); ho_EmptyRegion.Dispose(); ho_Region.Dispose(); ho_RegionFillUp.Dispose(); ho_RegionErosion.Dispose(); ho_RegionDifference.Dispose(); ho_ImageReduced.Dispose(); ho_Region1.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions.Dispose(); ho_ImageReduced1.Dispose(); ho_ImageEmphasize.Dispose(); ho_Region2.Dispose(); ho_ConnectedRegions1.Dispose(); ho_SelectedRegions1.Dispose(); ho_RegionDilation.Dispose(); ho_Circle.Dispose(); ho_ImageResult.Dispose(); ho_Domain11.Dispose(); ho_ImageScaled.Dispose(); return(WhiteParaReturn); }
/// <summary> /// 白点检测20171010 /// </summary> /// <param name="barcode"></param> /// <param name="ho_Image"></param> /// <param name="pixel_MM"></param> /// <returns></returns> public WhiteParaList WhiteDotInspect(string barcode, string modle, HObject ho_Image, double pixel_MM, string ImagePath) { WhiteParaList WhiteParaReturn = new WhiteParaList(); // Local iconic variables HObject ho_Domain, ho_ImageScaled = null, ho_SelectObjregion; HObject ho_ImageInvert, ho_Region2, ho_ConnectedRegions; HObject ho_SelectedRegions, ho_RegionDilation = null, ho_Circle = null; HObject ho_ImageResult = null; // Local control variables HTuple hv_Name = null, hv_Width = null, hv_Height = null, hv_RowY = null, hv_ColumnX = null, hv_Area1 = null; HTuple hv_Index1 = null, hv_Mean1 = new HTuple(), hv_Deviation1 = new HTuple(); HTuple hv_radius_MM = null, hv_radius_Pixel = null, hv_area_Pixel = null; HTuple hv_Number = null, hv_NumDot = null, hv_Row = new HTuple(); HTuple hv_Column = new HTuple(), hv_Radius = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_SelectObjregion); HOperatorSet.GenEmptyObj(out ho_Domain); HOperatorSet.GenEmptyObj(out ho_ImageScaled); HOperatorSet.GenEmptyObj(out ho_ImageInvert); HOperatorSet.GenEmptyObj(out ho_Region2); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions); HOperatorSet.GenEmptyObj(out ho_SelectedRegions); HOperatorSet.GenEmptyObj(out ho_RegionDilation); HOperatorSet.GenEmptyObj(out ho_Circle); HOperatorSet.GenEmptyObj(out ho_ImageResult); hv_Name = barcode; hv_NumDot = 0; HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height); ho_Domain.Dispose(); HOperatorSet.GetDomain(ho_Image, out ho_Domain); for (hv_Index1 = 0; (int)hv_Index1 <= 255; hv_Index1 = (int)hv_Index1 + 1) { ho_ImageScaled.Dispose(); HOperatorSet.ScaleImage(ho_Image, out ho_ImageScaled, 1.6, -hv_Index1); HOperatorSet.Intensity(ho_Domain, ho_ImageScaled, out hv_Mean1, out hv_Deviation1); if ((int)((new HTuple(hv_Mean1.TupleGreater(20))).TupleAnd(new HTuple(hv_Mean1.TupleLess( 30)))) != 0) { break; } } ho_ImageInvert.Dispose(); HOperatorSet.InvertImage(ho_ImageScaled, out ho_ImageInvert); ho_Region2.Dispose(); HOperatorSet.VarThreshold(ho_ImageInvert, out ho_Region2, hv_Width, hv_Height, 2, 100, "dark"); ho_ConnectedRegions.Dispose(); HOperatorSet.Connection(ho_Region2, out ho_ConnectedRegions); hv_radius_MM = pixel_MM * 1000; hv_radius_Pixel = 20 / hv_radius_MM; hv_area_Pixel = (3.14 * hv_radius_Pixel) * hv_radius_Pixel; ho_SelectedRegions.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, "area", "and", hv_area_Pixel, 99999); HOperatorSet.CountObj(ho_SelectedRegions, out hv_Number); hv_NumDot = hv_Number.Clone(); if (hv_NumDot.I > 5) { WhiteParaReturn.whiteCounts = 5; } else { WhiteParaReturn.whiteCounts = hv_NumDot.I; } if ((int)(new HTuple(hv_NumDot.TupleGreater(0))) != 0) { ho_RegionDilation.Dispose(); HOperatorSet.DilationCircle(ho_SelectedRegions, out ho_RegionDilation, 5); HOperatorSet.SmallestCircle(ho_RegionDilation, out hv_Row, out hv_Column, out hv_Radius); ho_Circle.Dispose(); HOperatorSet.GenCircle(out ho_Circle, hv_Row, hv_Column, hv_Radius); ho_ImageResult.Dispose(); HOperatorSet.PaintRegion(ho_Circle, ho_Image, out ho_ImageResult, 0, "margin"); string fileName = ImagePath + "\\" + barcode + ".bmp"; HOperatorSet.WriteImage(ho_ImageResult, "bmp", 0, fileName); string fileName1 = ImagePath + "\\" + "Original" + barcode + ".bmp"; HOperatorSet.WriteImage(ho_Image, "bmp", 0, fileName1); if (hv_NumDot.I > 5) { for (int j = 0; j < 5; j++) { ho_SelectObjregion.Dispose(); HOperatorSet.SelectObj(ho_SelectedRegions, out ho_SelectObjregion, j + 1); HOperatorSet.AreaCenter(ho_SelectObjregion, out hv_RowY, out hv_ColumnX, out hv_Area1); WhiteParaReturn.whiteX[j] = (float)Math.Round(hv_ColumnX.D * pixel_MM, 3); WhiteParaReturn.whiteY[j] = (float)Math.Round(hv_RowY.D * pixel_MM, 3); WhiteParaReturn.whiteArea[j] = (float)Math.Round(hv_Area1.D * pixel_MM * pixel_MM, 3); } } else { for (int j = 0; j < hv_NumDot.I; j++) { ho_SelectObjregion.Dispose(); HOperatorSet.SelectObj(ho_SelectedRegions, out ho_SelectObjregion, j + 1); HOperatorSet.AreaCenter(ho_SelectObjregion, out hv_RowY, out hv_ColumnX, out hv_Area1); WhiteParaReturn.whiteX[j] = (float)Math.Round(hv_ColumnX.D * pixel_MM, 3); WhiteParaReturn.whiteY[j] = (float)Math.Round(hv_RowY.D * pixel_MM, 3); WhiteParaReturn.whiteArea[j] = (float)Math.Round(hv_Area1.D * pixel_MM * pixel_MM, 3); } } } //else //{ // string path = "G:\\BlackAndWhiteDotImage"; // if (!Directory.Exists(path)) // { // Directory.CreateDirectory(path); // } // string s_FileName = path + "\\" + DateTime.Now.ToString("yyyyMMdd"); // if (!Directory.Exists(s_FileName)) // { // Directory.CreateDirectory(s_FileName); // } // string FileName = s_FileName + "\\" + "WhiteDotImage"; // if (!Directory.Exists(FileName)) // { // Directory.CreateDirectory(FileName); // } // string fileName = FileName + "\\" + barcode + ".bmp"; // HOperatorSet.WriteImage(ho_Image, "bmp", 0, fileName); //} ho_SelectObjregion.Dispose(); ho_Domain.Dispose(); ho_ImageScaled.Dispose(); ho_ImageInvert.Dispose(); ho_Region2.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions.Dispose(); ho_RegionDilation.Dispose(); ho_Circle.Dispose(); ho_ImageResult.Dispose(); return(WhiteParaReturn); }
// Procedures public void mia_cwdl(HObject ho_Image, HTuple hv_WindowHandle, HTuple hv_signLocRightX, HTuple hv_signLocLeftX, HTuple hv_signLocRightY, HTuple hv_signLocLeftY, out HTuple hv_DecodedDataStrings, out HTuple hv_sign) { // Local iconic variables HObject ho_SymbolRegions, ho_ImageAffineTrans; // Local control variables HTuple hv_BarCodeHandle = new HTuple(), hv_someitem = new HTuple(); HTuple hv_SignWidth = new HTuple(), hv_HeadSignScale = new HTuple(); HTuple hv_HeadSignRow = new HTuple(), hv_HeadSignCol = new HTuple(); HTuple hv_Phi = new HTuple(), hv_HomMat2D = new HTuple(); HTuple hv_HomMat2DRotate = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_SymbolRegions); HOperatorSet.GenEmptyObj(out ho_ImageAffineTrans); hv_DecodedDataStrings = new HTuple(); hv_sign = new HTuple(); //*** //** INIT //* INIT BARCODE hv_BarCodeHandle.Dispose(); HOperatorSet.CreateBarCodeModel(new HTuple(), new HTuple(), out hv_BarCodeHandle); HOperatorSet.SetBarCodeParam(hv_BarCodeHandle, "quiet_zone", "true"); //** RECOGNITION //* BARCODE ho_SymbolRegions.Dispose(); hv_DecodedDataStrings.Dispose(); hv_someitem.Dispose(); image_get_bar(ho_Image, out ho_SymbolRegions, hv_BarCodeHandle, hv_WindowHandle, out hv_DecodedDataStrings, out hv_someitem); //* Sign //* 制单人: 1120 186 signLocLeftX signLocLeftY //* 科室收货人 1110 2400 signLocRightX signLocRightY //signLocLeftX := 1120 //signLocLeftY := 186 //signLocRightX := 1110 //signLocRightY := 2400 hv_SignWidth.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_SignWidth = hv_signLocRightY - hv_signLocLeftY; } hv_HeadSignScale.Dispose(); hv_HeadSignScale = 1; hv_HeadSignRow.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_HeadSignRow = (hv_signLocLeftX + hv_signLocRightX) / 2; } hv_HeadSignCol.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_HeadSignCol = (hv_signLocLeftY + hv_signLocRightY) / 2; } using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_Phi.Dispose(); HOperatorSet.TupleAtan2(hv_signLocRightX - hv_signLocLeftX, hv_signLocRightY - hv_signLocLeftY, out hv_Phi); } hv_HomMat2D.Dispose(); HOperatorSet.HomMat2dIdentity(out hv_HomMat2D); hv_HomMat2DRotate.Dispose(); HOperatorSet.HomMat2dRotate(hv_HomMat2D, hv_Phi, hv_HeadSignRow, hv_HeadSignCol, out hv_HomMat2DRotate); ho_ImageAffineTrans.Dispose(); HOperatorSet.AffineTransImage(ho_Image, out ho_ImageAffineTrans, hv_HomMat2DRotate, "constant", "false"); hv_sign.Dispose(); mia_sign(ho_ImageAffineTrans, hv_HeadSignRow, hv_HeadSignCol, hv_WindowHandle, hv_SignWidth, out hv_sign); ho_SymbolRegions.Dispose(); ho_ImageAffineTrans.Dispose(); hv_BarCodeHandle.Dispose(); hv_someitem.Dispose(); hv_SignWidth.Dispose(); hv_HeadSignScale.Dispose(); hv_HeadSignRow.Dispose(); hv_HeadSignCol.Dispose(); hv_Phi.Dispose(); hv_HomMat2D.Dispose(); hv_HomMat2DRotate.Dispose(); return; }
/// <summary> /// Recalculates the shape of the ROI. Translation is /// performed at the active handle of the ROI object /// for the image coordinate (x,y) /// </summary> public override void moveByHandle(double newX, double newY) { HTuple distance; double dirX, dirY, prior, next, valMax, valMin; switch (activeHandleIdx) { case 0: // midpoint dirY = midR - newY; dirX = midC - newX; midR = newY; midC = newX; sizeR -= dirY; sizeC -= dirX; determineArcHandles(); break; case 1: // handle at circle border sizeR = newY; sizeC = newX; HOperatorSet.DistancePp(new HTuple(sizeR), new HTuple(sizeC), new HTuple(midR), new HTuple(midC), out distance); radius = distance[0].D; determineArcHandles(); break; case 2: // start handle for arc dirY = newY - midR; dirX = newX - midC; startPhi = Math.Atan2(-dirY, dirX); if (startPhi < 0) { startPhi = PI + (startPhi + PI); } setStartHandle(); prior = extentPhi; extentPhi = HMisc.AngleLl(midR, midC, startR, startC, midR, midC, extentR, extentC); if (extentPhi < 0 && prior > PI * 0.8) { extentPhi = (PI + extentPhi) + PI; } else if (extentPhi > 0 && prior < -PI * 0.7) { extentPhi = -PI - (PI - extentPhi); } break; case 3: // end handle for arc dirY = newY - midR; dirX = newX - midC; prior = extentPhi; next = Math.Atan2(-dirY, dirX); if (next < 0) { next = PI + (next + PI); } if (circDir == "positive" && startPhi >= next) { extentPhi = (next + TwoPI) - startPhi; } else if (circDir == "positive" && next > startPhi) { extentPhi = next - startPhi; } else if (circDir == "negative" && startPhi >= next) { extentPhi = -1.0 * (startPhi - next); } else if (circDir == "negative" && next > startPhi) { extentPhi = -1.0 * (startPhi + TwoPI - next); } valMax = Math.Max(Math.Abs(prior), Math.Abs(extentPhi)); valMin = Math.Min(Math.Abs(prior), Math.Abs(extentPhi)); if ((valMax - valMin) >= PI) { extentPhi = (circDir == "positive") ? -1.0 * valMin : valMin; } setExtentHandle(); break; } circDir = (extentPhi < 0) ? "negative" : "positive"; updateArrowHandle(); }
public void disp_message(HTuple hv_WindowHandle, HTuple hv_String, HTuple hv_CoordSystem, HTuple hv_Row, HTuple hv_Column, HTuple hv_Color, HTuple hv_Box) { // Local control variables HTuple hv_Red, hv_Green, hv_Blue, hv_Row1Part; HTuple hv_Column1Part, hv_Row2Part, hv_Column2Part, hv_RowWin; HTuple hv_ColumnWin, hv_WidthWin, hv_HeightWin, hv_MaxAscent; HTuple hv_MaxDescent, hv_MaxWidth, hv_MaxHeight, hv_R1 = new HTuple(); HTuple hv_C1 = new HTuple(), hv_FactorRow = new HTuple(), hv_FactorColumn = new HTuple(); HTuple hv_Width = new HTuple(), hv_Index = new HTuple(), hv_Ascent = new HTuple(); HTuple hv_Descent = new HTuple(), hv_W = new HTuple(), hv_H = new HTuple(); HTuple hv_FrameHeight = new HTuple(), hv_FrameWidth = new HTuple(); HTuple hv_R2 = new HTuple(), hv_C2 = new HTuple(), hv_DrawMode = new HTuple(); HTuple hv_Exception = new HTuple(), hv_CurrentColor = new HTuple(); HTuple hv_Color_COPY_INP_TMP = hv_Color.Clone(); HTuple hv_Column_COPY_INP_TMP = hv_Column.Clone(); HTuple hv_Row_COPY_INP_TMP = hv_Row.Clone(); HTuple hv_String_COPY_INP_TMP = hv_String.Clone(); //prepare window HOperatorSet.GetRgb(hv_WindowHandle, out hv_Red, out hv_Green, out hv_Blue); HOperatorSet.GetPart(hv_WindowHandle, out hv_Row1Part, out hv_Column1Part, out hv_Row2Part, out hv_Column2Part); HOperatorSet.GetWindowExtents(hv_WindowHandle, out hv_RowWin, out hv_ColumnWin, out hv_WidthWin, out hv_HeightWin); HOperatorSet.SetPart(hv_WindowHandle, 0, 0, hv_HeightWin - 1, hv_WidthWin - 1); // //default settings if ((int)(new HTuple(hv_Row_COPY_INP_TMP.TupleEqual(-1))) != 0) { hv_Row_COPY_INP_TMP = 12; } if ((int)(new HTuple(hv_Column_COPY_INP_TMP.TupleEqual(-1))) != 0) { hv_Column_COPY_INP_TMP = 12; } if ((int)(new HTuple(hv_Color_COPY_INP_TMP.TupleEqual(new HTuple()))) != 0) { hv_Color_COPY_INP_TMP = ""; } // hv_String_COPY_INP_TMP = ((("" + hv_String_COPY_INP_TMP) + "")).TupleSplit("\n"); // //Estimate extentions of text depending on font size. HOperatorSet.GetFontExtents(hv_WindowHandle, out hv_MaxAscent, out hv_MaxDescent, out hv_MaxWidth, out hv_MaxHeight); if ((int)(new HTuple(hv_CoordSystem.TupleEqual("window"))) != 0) { hv_R1 = hv_Row_COPY_INP_TMP.Clone(); hv_C1 = hv_Column_COPY_INP_TMP.Clone(); } else { //transform image to window coordinates hv_FactorRow = (1.0 * hv_HeightWin) / ((hv_Row2Part - hv_Row1Part) + 1); hv_FactorColumn = (1.0 * hv_WidthWin) / ((hv_Column2Part - hv_Column1Part) + 1); hv_R1 = ((hv_Row_COPY_INP_TMP - hv_Row1Part) + 0.5) * hv_FactorRow; hv_C1 = ((hv_Column_COPY_INP_TMP - hv_Column1Part) + 0.5) * hv_FactorColumn; } // //display text box depending on text size if ((int)(new HTuple(hv_Box.TupleEqual("true"))) != 0) { //calculate box extents hv_String_COPY_INP_TMP = (" " + hv_String_COPY_INP_TMP) + " "; hv_Width = new HTuple(); for (hv_Index = 0; (int)hv_Index <= (int)((new HTuple(hv_String_COPY_INP_TMP.TupleLength() )) - 1); hv_Index = (int)hv_Index + 1) { HOperatorSet.GetStringExtents(hv_WindowHandle, hv_String_COPY_INP_TMP.TupleSelect( hv_Index), out hv_Ascent, out hv_Descent, out hv_W, out hv_H); hv_Width = hv_Width.TupleConcat(hv_W); } hv_FrameHeight = hv_MaxHeight * (new HTuple(hv_String_COPY_INP_TMP.TupleLength() )); hv_FrameWidth = (((new HTuple(0)).TupleConcat(hv_Width))).TupleMax(); hv_R2 = hv_R1 + hv_FrameHeight; hv_C2 = hv_C1 + hv_FrameWidth; //display rectangles HOperatorSet.GetDraw(hv_WindowHandle, out hv_DrawMode); HOperatorSet.SetDraw(hv_WindowHandle, "fill"); HOperatorSet.SetColor(hv_WindowHandle, "light gray"); HOperatorSet.DispRectangle1(hv_WindowHandle, hv_R1 + 3, hv_C1 + 3, hv_R2 + 3, hv_C2 + 3); HOperatorSet.SetColor(hv_WindowHandle, "white"); HOperatorSet.DispRectangle1(hv_WindowHandle, hv_R1, hv_C1, hv_R2, hv_C2); HOperatorSet.SetDraw(hv_WindowHandle, hv_DrawMode); } else if ((int)(new HTuple(hv_Box.TupleNotEqual("false"))) != 0) { hv_Exception = "Wrong value of control parameter Box"; throw new HalconException(hv_Exception); } //Write text. for (hv_Index = 0; (int)hv_Index <= (int)((new HTuple(hv_String_COPY_INP_TMP.TupleLength() )) - 1); hv_Index = (int)hv_Index + 1) { hv_CurrentColor = hv_Color_COPY_INP_TMP.TupleSelect(hv_Index % (new HTuple(hv_Color_COPY_INP_TMP.TupleLength() ))); if ((int)((new HTuple(hv_CurrentColor.TupleNotEqual(""))).TupleAnd(new HTuple(hv_CurrentColor.TupleNotEqual( "auto")))) != 0) { HOperatorSet.SetColor(hv_WindowHandle, hv_CurrentColor); } else { HOperatorSet.SetRgb(hv_WindowHandle, hv_Red, hv_Green, hv_Blue); } hv_Row_COPY_INP_TMP = hv_R1 + (hv_MaxHeight * hv_Index); HOperatorSet.SetTposition(hv_WindowHandle, hv_Row_COPY_INP_TMP, hv_C1); HOperatorSet.WriteString(hv_WindowHandle, hv_String_COPY_INP_TMP.TupleSelect( hv_Index)); } //reset changed window settings HOperatorSet.SetRgb(hv_WindowHandle, hv_Red, hv_Green, hv_Blue); HOperatorSet.SetPart(hv_WindowHandle, hv_Row1Part, hv_Column1Part, hv_Row2Part, hv_Column2Part); return; }
private void TIS_ImageAvailable(object sender, ICImagingControl.ImageAvailableEventArgs e) { try { //Util.Notify(string.Format("相机{0}收到图像", cameraIndex)); if (ignoreImage) { return; } //HTuple startTime; HOperatorSet.CountSeconds(out startTime); // Acquire the image from the camera. Only show the latest image. The camera may acquire images faster than the images can be displayed. ImageBuffer ImgBuffer = e.ImageBuffer; // Reduce the number of displayed images to a reasonable amount if the camera is acquiring images very fast. //if (!stopWatch.IsRunning || stopWatch.ElapsedMilliseconds > 33) { //stopWatch.Restart(); //if (hPylonImage != null && hPylonImage.IsInitialized()) //{ // hPylonImage.Dispose(); //} hPylonImage = new HImage(); if (ImgBuffer.GetIntPtr() == IntPtr.Zero) { Util.Notify(string.Format("相机{0}数据损坏,采集失败", cameraIndex)); return; } if (camera.MemoryCurrentGrabberColorformat == ICImagingControlColorformats.ICY8) { hPylonImage.GenImage1("byte", ImgBuffer.Size.Width, ImgBuffer.Size.Height, ImgBuffer.GetImageDataPtr()); HImage imgTmp = hPylonImage.MirrorImage("row"); hPylonImage.Dispose(); hPylonImage = imgTmp; } else if (camera.MemoryCurrentGrabberColorformat == ICImagingControlColorformats.ICRGB32) { //allocate the m_stream_size amount of bytes in non-managed environment hPylonImage.GenImageInterleaved(ImgBuffer.GetImageDataPtr(), "rgb", ImgBuffer.Size.Width, ImgBuffer.Size.Height, -1, "byte", ImgBuffer.Size.Width, ImgBuffer.Size.Height, 0, 0, -1, 0); } else { Util.Notify(string.Format("相机{0}编码格式不正确", cameraIndex)); } TrigerImageEvent(); } } catch (System.ArgumentException ex) { Util.WriteLog(this.GetType(), ex); Util.Notify(string.Format("相机{0}图像数据包丢失", cameraIndex)); } catch (Exception ex) { Util.WriteLog(this.GetType(), ex); Util.Notify(string.Format("相机{0}图像数据返回出现异常", cameraIndex)); } }
// Procedures public void image_judge_sign_judge(HObject ho_RoiSign, HObject ho_OriImage, out HObject ho_SignFeat, out HTuple hv_sign) { // Stack for temporary objects HObject[] OTemp = new HObject[20]; // Local iconic variables HObject ho_GrayImage, ho_ObjectSelected = null; HObject ho_ImageReduced = null, ho_Edges = null; // Local control variables HTuple hv_SignNum = new HTuple(), hv_SignThreshold = new HTuple(); HTuple hv_Index = new HTuple(), hv_Length = new HTuple(); HTuple hv_Length1 = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_SignFeat); HOperatorSet.GenEmptyObj(out ho_GrayImage); HOperatorSet.GenEmptyObj(out ho_ObjectSelected); HOperatorSet.GenEmptyObj(out ho_ImageReduced); HOperatorSet.GenEmptyObj(out ho_Edges); hv_sign = new HTuple(); //** Porg //* Pre ho_GrayImage.Dispose(); HOperatorSet.Rgb1ToGray(ho_OriImage, out ho_GrayImage); //get_region_convex (ROI_0, Rows, Columns) //* Judgement ho_SignFeat.Dispose(); HOperatorSet.GenEmptyObj(out ho_SignFeat); //SignNum := 4 hv_SignNum.Dispose(); HOperatorSet.CountObj(ho_RoiSign, out hv_SignNum); hv_SignThreshold.Dispose(); hv_SignThreshold = 5.0; HTuple end_val12 = hv_SignNum; HTuple step_val12 = 1; for (hv_Index = 1; hv_Index.Continue(end_val12, step_val12); hv_Index = hv_Index.TupleAdd(step_val12)) { ho_ObjectSelected.Dispose(); HOperatorSet.SelectObj(ho_RoiSign, out ho_ObjectSelected, hv_Index); //截取对应区域图片 ho_ImageReduced.Dispose(); HOperatorSet.ReduceDomain(ho_GrayImage, ho_ObjectSelected, out ho_ImageReduced ); //区域图片映射为轮廓 ho_Edges.Dispose(); HOperatorSet.EdgesSubPix(ho_ImageReduced, out ho_Edges, "canny", 1, 20, 40); { HObject ExpTmpOutVar_0; HOperatorSet.ConcatObj(ho_Edges, ho_SignFeat, out ExpTmpOutVar_0); ho_SignFeat.Dispose(); ho_SignFeat = ExpTmpOutVar_0; } //得到轮廓长度数组 hv_Length.Dispose(); HOperatorSet.LengthXld(ho_Edges, out hv_Length); //云团数目大于五则有签字 hv_Length1.Dispose(); HOperatorSet.TupleLength(hv_Length, out hv_Length1); if ((int)(new HTuple(hv_Length1.TupleGreater(hv_SignThreshold))) != 0) { if (hv_sign == null) { hv_sign = new HTuple(); } hv_sign[hv_Index - 1] = 1; } else { if (hv_sign == null) { hv_sign = new HTuple(); } hv_sign[hv_Index - 1] = 0; } } ho_GrayImage.Dispose(); ho_ObjectSelected.Dispose(); ho_ImageReduced.Dispose(); ho_Edges.Dispose(); hv_SignNum.Dispose(); hv_SignThreshold.Dispose(); hv_Index.Dispose(); hv_Length.Dispose(); hv_Length1.Dispose(); return; }
private void Window_ContentRendered(object sender, EventArgs e) { HOperatorSet.OpenWindow(0, 0, 1920, 1080, 0, "buffer", "", out BufferWindow); }
/// <summary> /// If calibration data is available and valid, then transform the /// distance between measure result edges into world coordinates, /// else leave them the same. /// </summary> public HTuple Distance(HTuple row1, HTuple col1, HTuple row2, HTuple col2, int shift) { HTuple rows, cols, rowRect, colRect; HTuple distance = new HTuple(); HXLDCont contour; if (shift == 0) { if (mROIType == ROI.ROI_TYPE_CIRCLEARC) { double cRow, cCol, radius, extent, phi1, phi2, phi, res, length, tmp; cRow = mROICoord[0].D; cCol = mROICoord[1].D; radius = mROICoord[2].D; extent = mROICoord[4].D; HOperatorSet.TupleGenConst(new HTuple(row1.Length), 0.0, out distance); for (int i = 0; i < distance.Length; i++) { phi1 = HMisc.AngleLx(cRow, cCol, row1[i].D, col1[i].D); phi2 = HMisc.AngleLx(cRow, cCol, row2[i].D, col2[i].D); if (extent < 0) { tmp = phi1; phi1 = phi2; phi2 = tmp; } phi = phi2 - phi1; if (phi < 0) { phi += 2 * Math.PI; } res = 0.05 * 24.0 / (radius * phi); contour = new HXLDCont(); contour.GenEllipseContourXld(cRow, cCol, 0, radius, radius, phi1, phi2, "positive", res); contour.GetContourXld(out rows, out cols); Rectify(rows, cols, out rowRect, out colRect); contour.Dispose(); contour.GenContourPolygonXld(rowRect, colRect); length = contour.LengthXld(); distance[i].D = length; contour.Dispose(); } } else if (mROIType == ROI.ROI_TYPE_LINE) { HTuple rRect1, cRect1, rRect2, cRect2; Rectify(row1, col1, out rRect1, out cRect1); Rectify(row2, col2, out rRect2, out cRect2); distance = HMisc.DistancePp(rRect1, cRect1, rRect2, cRect2); } return(distance); } else { HTuple rClip1, cClip1, rShift2, cShift2; rClip1 = row1.TupleSelectRange(new HTuple(0), new HTuple(row1.Length - shift - 1)); cClip1 = col1.TupleSelectRange(new HTuple(0), new HTuple(col1.Length - shift - 1)); rShift2 = row2.TupleSelectRange(new HTuple(shift), new HTuple(row2.Length - 1)); cShift2 = col2.TupleSelectRange(new HTuple(shift), new HTuple(col2.Length - 1)); return(this.Distance(rClip1, cClip1, rShift2, cShift2, 0)); } }
public MeasureResult Action() { #region 輸出結果 CircleResult mResult = null; #endregion HTuple hv_STD_Row; HTuple hv_STD_Col, hv_Img_Row, hv_Img_Col, hv_Img_Rotate_Angle; HTuple hv_OffsetRow, hv_OffsetCol; HOperatorSet.SetSystem("border_shape_models", "false"); //STD 中心點 hv_STD_Row = 839.5; hv_STD_Col = 1046.5; //目前圖形 中心點 hv_Img_Row = hv_AllModelRow.Clone(); hv_Img_Col = hv_AllModelColumn.Clone(); //目前圖形 Rotate Angle hv_Img_Rotate_Angle = hv_AllModelAngle.Clone(); //目前圖形偏移量 hv_OffsetRow = hv_Img_Row - hv_STD_Row; hv_OffsetCol = hv_Img_Col - hv_STD_Col; //圓ROI HTuple f_ROI_Row = 386.41015625; HTuple f_ROI_Col = 795.529411764706; HTuple f_radius = 42.0323369109; //重定位 HTuple f_ROI_Cur_Row, f_ROI_Cur_Col; PositionLocater.ReLocater(hv_STD_Row, hv_STD_Col, hv_AllModelAngle, hv_OffsetRow, hv_OffsetCol, f_ROI_Row, f_ROI_Col, out f_ROI_Cur_Row, out f_ROI_Cur_Col); /**/ #region Measure var cROIController = new ROIController(); var cAssistant = new MeasureAssistant(cROIController); var hImage = ho_Image as HImage; cAssistant.setImage(hImage); /*參數值*/ cAssistant.mThresh = 40.0; cAssistant.mSigma = 1.0; cAssistant.mRoiWidth = 10; cAssistant.mInterpolation = "nearest_neighbor"; cAssistant.mSelPair = false; cAssistant.mTransition = "all"; cAssistant.mPosition = "all"; cAssistant.mDispEdgeLength = 30; cAssistant.mDispROIWidth = true; cAssistant.setUnit("cm"); cAssistant.mInitThresh = 40.0; cAssistant.mInitSigma = 1.0; cAssistant.mInitRoiWidth = 10; var roiF = new ROICircle() { ROIMeasureType = MeasureType.Circle }; //roiF.MakeROI(416, 998, 0, 26.5, 71.2); roiF.MakeROI(f_ROI_Cur_Row, f_ROI_Cur_Col, f_radius); double inc = 0.3; double miniRadius = 0.7; double maxRadius = 0.9; double currentRadius = 0; int doingCount = 0; //,0.2,0.4,0.6 //0.2,0.4,0.6 //0.7,0.8,0.9 MeasureViewModel model = null; var inBoundry = false; do { roiF.MakeROI(f_ROI_Cur_Row, f_ROI_Cur_Col, f_radius); var fitCircle = new MeasurementCircle(roiF, cAssistant); model = fitCircle.GetViewModel(); if (model.Distance != null && model.Distance.TupleLength() > 0) { currentRadius = CameraSystem.ToRealWorldValue(model.Distance.D); inBoundry = (miniRadius <= currentRadius && currentRadius <= maxRadius); if (inBoundry) { mResult = new CircleResult() { Row = new HTuple(model.Row1), Col = new HTuple(model.Col1), Radius = new HTuple(model.Distance), StartPhi = new HTuple(model.StartPhi), EndPhi = new HTuple(model.EndPhi), PointOrder = new HTuple(model.PointOrder), }; break; } } if (currentRadius < miniRadius) { f_radius += inc; } else { f_radius -= inc; } doingCount++; if (doingCount > 15) { break; } }while (!inBoundry); #endregion return(mResult); }
public bool FindShapeModel(HObject srcImg, RectangleF searchArea, out MatchingResult result) { bool isSuccess = true; result = new MatchingResult(); result.mScore = new HTuple(); HObject reducedImage = new HObject(); HObject roi = new HObject(); HOperatorSet.GenEmptyObj(out roi); HOperatorSet.GenEmptyObj(out reducedImage); try { if (srcImg == null) { m_MatchAssistant.setImage(); } else { double NowScale = m_MatchingParam.mImageSizeScale; HOperatorSet.GenRectangle1(out roi, searchArea.Y * NowScale, searchArea.X * NowScale, (searchArea.Y + searchArea.Height) * NowScale, (searchArea.X + searchArea.Width) * NowScale); HObject ScaleImg = new HObject(); HOperatorSet.ZoomImageFactor(srcImg, out ScaleImg, NowScale, NowScale, "constant"); HOperatorSet.ReduceDomain(ScaleImg, roi, out reducedImage); m_MatchAssistant.setTestImage(reducedImage); } // m_MatchAssistant.setImage(new HImage(srcImg)); isSuccess = m_MatchAssistant.applyFindModel(); if (isSuccess) { result = m_MatchAssistant.getMatchingResults(); if (result.count < 1) { Logger.PopError("找模板失败"); isSuccess = false; } } } catch (Exception ex) { if (reducedImage != null) { reducedImage.Dispose(); } if (roi != null) { roi.Dispose(); } isSuccess = false; Logger.PopError("找模板失败:" + ex.Message.ToString()); } if (isSuccess) { //string ccdName = CameraTest.Instance.GetCCDName(true, true, 1); //ViewControl view = DisplaySystem.GetViewControl(ccdName); //HImage img = m_MatchAssistant.getCurrTestImage(); //view.AddViewImage(img); //HXLD contour; //GetDetectionContour(out contour); //view.AddViewObject(contour); //view.AddViewCross(2048/2, 2448 / 2, 2048, 0); //view.AddViewLine(0, 2448 / 2, 2048,2448/2); //view.AddViewLine(2048 / 2, 0, 2048/2, 2448); //view.ShowAiming(); //view.Repaint(); //string str = string.Format("匹配度:{0}%", (100 * result.mScore.D).ToString("f2")); //view.SetString(20, 50, "red", str); } else { if (srcImg == null) { return(false); } //HOperatorSet.WriteImage(srcImg, "bmp", 0, "D:\\ReducedImage\\Model_SrcImage_" + SharpImageNumber.ToString() + ".bmp"); //HOperatorSet.WriteImage(reducedImage, "bmp", 0, "D:\\ReducedImage\\Model_ReducedImage_" + SharpImageNumber.ToString() + ".bmp"); if (reducedImage != null) { reducedImage.Dispose(); } if (roi != null) { roi.Dispose(); } SharpImageNumber++; } return(isSuccess); }
public xuanxiang() { //RegionToDisp = Image; HOperatorSet.GenEmptyObj(out RegionToDisp); RegionToDisp.Dispose(); }
// Main procedure private void action() { // Local iconic variables HObject ho_Image, ho_GrayImage3, ho_ImageGauss; HObject ho_ModelContours = null, ho_TransContours = null, ho_Rectangle = null; HObject ho_ImageReduced = null; // Local control variables HTuple hv_T1 = null, hv_CheckNO = null, hv_GODS = null; HTuple hv_Minspec = null, hv_Setnumber = null, hv_ocvgod = null; HTuple hv_RowPlus = null, hv_ColPlus = null, hv_path = null; HTuple hv_FileHandle = null, hv_OutLine = null, hv_IsEOF = null; HTuple hv_CheckNumber = null, hv_GreedinessNumber = null; HTuple hv_Index = null, hv_checkNO = new HTuple(), hv_gods = new HTuple(); HTuple hv_Mins = new HTuple(), hv_Setn = new HTuple(); HTuple hv_ocvgodfile = new HTuple(), hv_Setocvchar = new HTuple(); HTuple hv_ocvchar = new HTuple(), hv_Setrowplus = new HTuple(); HTuple hv_Setcolplus = new HTuple(), hv_ModelID1 = null; HTuple hv_ModelID2 = null, hv_ModelID3 = null, hv_ModelID4 = null; HTuple hv_ModelID5 = null, hv_ModelID6 = null, hv_ModelIDs = null; HTuple hv_Width = null, hv_Height = null, hv_WindowHandle = new HTuple(); HTuple hv_Index2 = null, hv_Row1 = new HTuple(), hv_Column1 = new HTuple(); HTuple hv_Row2 = new HTuple(), hv_Column2 = new HTuple(); HTuple hv_RefRow = new HTuple(), hv_RefColumn = new HTuple(); HTuple hv_HomMat2D = new HTuple(), hv_Row = new HTuple(); HTuple hv_Column = new HTuple(), hv_Angle = new HTuple(); HTuple hv_Score = new HTuple(), hv_I = new HTuple(), hv_OCVHandle = new HTuple(); HTuple hv_Quality = new HTuple(), hv_Index1 = new HTuple(); HTuple hv_T2 = null; // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Image); HOperatorSet.GenEmptyObj(out ho_GrayImage3); HOperatorSet.GenEmptyObj(out ho_ImageGauss); HOperatorSet.GenEmptyObj(out ho_ModelContours); HOperatorSet.GenEmptyObj(out ho_TransContours); HOperatorSet.GenEmptyObj(out ho_Rectangle); HOperatorSet.GenEmptyObj(out ho_ImageReduced); HOperatorSet.CountSeconds(out hv_T1); //**外部控制参数读入*** hv_CheckNO = new HTuple(); hv_GODS = new HTuple(); hv_Minspec = new HTuple(); hv_Setnumber = new HTuple(); hv_ocvgod = new HTuple(); hv_RowPlus = new HTuple(); hv_ColPlus = new HTuple(); hv_path = "matchingpara_fengwu_hougai.txt"; HOperatorSet.OpenFile(hv_path, "input", out hv_FileHandle); HOperatorSet.FreadLine(hv_FileHandle, out hv_OutLine, out hv_IsEOF); HOperatorSet.TupleNumber(((hv_OutLine.TupleSplit(new HTuple(",,,")))).TupleSelect( 0), out hv_CheckNumber); HOperatorSet.TupleNumber(((hv_OutLine.TupleSplit(new HTuple(",,,")))).TupleSelect( 1), out hv_GreedinessNumber); HTuple end_val15 = hv_CheckNumber - 1; HTuple step_val15 = 1; for (hv_Index = 0; hv_Index.Continue(end_val15, step_val15); hv_Index = hv_Index.TupleAdd(step_val15)) { HOperatorSet.FreadLine(hv_FileHandle, out hv_OutLine, out hv_IsEOF); HOperatorSet.TupleNumber(((hv_OutLine.TupleSplit(new HTuple(",,,")))).TupleSelect( 0), out hv_checkNO); if (hv_CheckNO == null) { hv_CheckNO = new HTuple(); } hv_CheckNO[hv_Index] = hv_checkNO; HOperatorSet.TupleNumber(((hv_OutLine.TupleSplit(new HTuple(",,,")))).TupleSelect( 1), out hv_gods); if (hv_GODS == null) { hv_GODS = new HTuple(); } hv_GODS[hv_Index] = hv_gods; HOperatorSet.TupleNumber(((hv_OutLine.TupleSplit(new HTuple(",,,")))).TupleSelect( 2), out hv_Mins); if (hv_Minspec == null) { hv_Minspec = new HTuple(); } hv_Minspec[hv_Index] = hv_Mins; HOperatorSet.TupleNumber(((hv_OutLine.TupleSplit(new HTuple(",,,")))).TupleSelect( 3), out hv_Setn); if (hv_Setnumber == null) { hv_Setnumber = new HTuple(); } hv_Setnumber[hv_Index] = hv_Setn; HOperatorSet.TupleNumber(((hv_OutLine.TupleSplit(new HTuple(",,,")))).TupleSelect( 4), out hv_ocvgodfile); if (hv_ocvgod == null) { hv_ocvgod = new HTuple(); } hv_ocvgod[hv_Index] = hv_ocvgodfile; HOperatorSet.TupleNumber(((hv_OutLine.TupleSplit(new HTuple(",,,")))).TupleSelect( 5), out hv_Setocvchar); if (hv_ocvchar == null) { hv_ocvchar = new HTuple(); } hv_ocvchar[hv_Index] = hv_Setocvchar; HOperatorSet.TupleNumber(((hv_OutLine.TupleSplit(new HTuple(",,,")))).TupleSelect( 6), out hv_Setrowplus); if (hv_RowPlus == null) { hv_RowPlus = new HTuple(); } hv_RowPlus[hv_Index] = hv_Setrowplus; HOperatorSet.TupleNumber(((hv_OutLine.TupleSplit(new HTuple(",,,")))).TupleSelect( 7), out hv_Setcolplus); if (hv_ColPlus == null) { hv_ColPlus = new HTuple(); } hv_ColPlus[hv_Index] = hv_Setcolplus; } HOperatorSet.CloseFile(hv_FileHandle); //**Log 文件创建*** HOperatorSet.OpenFile("matching_fengwu_result.csv", "output", out hv_FileHandle); //**模板读入*** HOperatorSet.ReadShapeModel("god_fengwu/01_MOVIE_O.shm", out hv_ModelID1); HOperatorSet.ReadShapeModel("god_fengwu/02_MENU_M.shm", out hv_ModelID2); HOperatorSet.ReadShapeModel("god_fengwu/03_MOVIE_E.shm", out hv_ModelID3); HOperatorSet.ReadShapeModel("god_fengwu/04_jiajian.shm", out hv_ModelID4); HOperatorSet.ReadShapeModel("god_fengwu/05_C.shm", out hv_ModelID5); HOperatorSet.ReadShapeModel("god_fengwu/06_MOVIE_V.shm", out hv_ModelID6); hv_ModelIDs = new HTuple(); hv_ModelIDs = hv_ModelIDs.TupleConcat(hv_ModelID1); hv_ModelIDs = hv_ModelIDs.TupleConcat(hv_ModelID2); hv_ModelIDs = hv_ModelIDs.TupleConcat(hv_ModelID3); hv_ModelIDs = hv_ModelIDs.TupleConcat(hv_ModelID4); hv_ModelIDs = hv_ModelIDs.TupleConcat(hv_ModelID5); hv_ModelIDs = hv_ModelIDs.TupleConcat(hv_ModelID6); ho_Image.Dispose(); HOperatorSet.ReadImage(out ho_Image, "fw10.bmp"); HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height); dev_open_window_fit_image(ho_Image, 0, 0, -1, -1, out hv_WindowHandle); HOperatorSet.DispObj(ho_Image, hv_ExpDefaultWinHandle); ho_GrayImage3.Dispose(); HOperatorSet.Rgb1ToGray(ho_Image, out ho_GrayImage3); ho_ImageGauss.Dispose(); HOperatorSet.GaussImage(ho_Image, out ho_ImageGauss, 5); HTuple end_val61 = hv_CheckNumber - 1; HTuple step_val61 = 1; int idx = 0; for (hv_Index2 = 0; hv_Index2.Continue(end_val61, step_val61); hv_Index2 = hv_Index2.TupleAdd(step_val61)) { //Matching 01: ************************************************ //Matching 01: BEGIN of generated code for model initialization //Matching 01: ************************************************ HOperatorSet.SetSystem("border_shape_models", "false"); // //Matching 01: Read the shape model from file // //Matching 01: Get the model contour for transforming it later into the image ho_ModelContours.Dispose(); HOperatorSet.GetShapeModelContours(out ho_ModelContours, hv_ModelIDs.TupleSelect( hv_Index2), 1); // //Matching 01: Set a reference position to show the model HOperatorSet.SmallestRectangle1Xld(ho_ModelContours, out hv_Row1, out hv_Column1, out hv_Row2, out hv_Column2); hv_RefRow = ((hv_Row2.TupleMax()) - (hv_Row1.TupleMin())) / 2; hv_RefColumn = ((hv_Column2.TupleMax()) - (hv_Column1.TupleMin())) / 2; HOperatorSet.VectorAngleToRigid(0, 0, 0, hv_RefRow, hv_RefColumn, 0, out hv_HomMat2D); ho_TransContours.Dispose(); HOperatorSet.AffineTransContourXld(ho_ModelContours, out ho_TransContours, hv_HomMat2D); // //Matching 01: Display the model contours HOperatorSet.SetColor(hv_ExpDefaultWinHandle, "green"); HOperatorSet.SetDraw(hv_ExpDefaultWinHandle, "margin"); HOperatorSet.DispObj(ho_TransContours, hv_ExpDefaultWinHandle); // //Matching 01: END of generated code for model initialization //Matching 01: * * * * * * * * * * * * * * * * * * * * * * * //Matching 01: BEGIN of generated code for model application // //Matching 01: Loop over all specified test images //Matching 01: Find the model HOperatorSet.FindShapeModel(ho_ImageGauss, hv_ModelIDs.TupleSelect(hv_Index2), (new HTuple(0)).TupleRad(), (new HTuple(360)).TupleRad(), hv_Minspec.TupleSelect( hv_Index2), hv_Setnumber.TupleSelect(hv_Index2), 0.5, "least_squares", (new HTuple(3)).TupleConcat(1), hv_GreedinessNumber, out hv_Row, out hv_Column, out hv_Angle, out hv_Score); // //Matching 01: Transform the model contours into the detected positions HOperatorSet.DispObj(ho_Image, hv_ExpDefaultWinHandle); for (hv_I = 0; (int)hv_I <= (int)((new HTuple(hv_Score.TupleLength())) - 1); hv_I = (int)hv_I + 1) { HOperatorSet.HomMat2dIdentity(out hv_HomMat2D); HOperatorSet.HomMat2dRotate(hv_HomMat2D, hv_Angle.TupleSelect(hv_I), 0, 0, out hv_HomMat2D); HOperatorSet.HomMat2dTranslate(hv_HomMat2D, hv_Row.TupleSelect(hv_I), hv_Column.TupleSelect( hv_I), out hv_HomMat2D); ho_TransContours.Dispose(); HOperatorSet.AffineTransContourXld(ho_ModelContours, out ho_TransContours, hv_HomMat2D); //HOperatorSet.SetColor(hv_ExpDefaultWinHandle, "green"); // HOperatorSet.DispObj(ho_TransContours, hv_ExpDefaultWinHandle); } // //Matching 01: Clear model when done HOperatorSet.ClearShapeModel(hv_ModelIDs.TupleSelect(hv_Index2)); //Matching 01: ******************************************* //Matching 01: END of generated code for model application //Matching 01: ******************************************* // // //**Matching Log数据写入外部文件*** if ((int)(new HTuple(hv_I.TupleEqual(hv_Setnumber.TupleSelect(hv_Index2)))) != 0) { HOperatorSet.ReadOcv(hv_ocvgod.TupleSelect(hv_Index2), out hv_OCVHandle); ho_Rectangle.Dispose(); HOperatorSet.GenRectangle1(out ho_Rectangle, hv_Row - (hv_RowPlus.TupleSelect( hv_Index2)), hv_Column - (hv_ColPlus.TupleSelect(hv_Index2)), hv_Row + (hv_RowPlus.TupleSelect( hv_Index2)), hv_Column + (hv_ColPlus.TupleSelect(hv_Index2))); ho_ImageReduced.Dispose(); HOperatorSet.ReduceDomain(ho_ImageGauss, ho_Rectangle, out ho_ImageReduced ); HOperatorSet.DoOcvSimple(ho_ImageReduced, hv_OCVHandle, hv_ocvchar.TupleSelect( hv_Index2), "true", "true", "true", "true", 5, out hv_Quality); cs_Quality[idx] = hv_Quality; cs_x[idx] = hv_Column; cs_y[idx] = hv_Row; idx++; HTuple end_val126 = hv_I; HTuple step_val126 = 1; for (hv_Index1 = 1; hv_Index1.Continue(end_val126, step_val126); hv_Index1 = hv_Index1.TupleAdd(step_val126)) { HOperatorSet.FwriteString(hv_FileHandle, ((((((((((((hv_CheckNO.TupleSelect( hv_Index2)) + new HTuple(",")) + (hv_GODS.TupleSelect(hv_Index2))) + new HTuple(",")) + "OK") + new HTuple(",")) + hv_I) + new HTuple(",")) + (hv_Score.TupleSelect( hv_Index1 - 1))) + new HTuple(",")) + "Quality") + new HTuple(",")) + hv_Quality); HOperatorSet.FnewLine(hv_FileHandle); } } else { HOperatorSet.FwriteString(hv_FileHandle, ((((((((hv_CheckNO.TupleSelect(hv_Index2)) + new HTuple(",")) + (hv_GODS.TupleSelect( hv_Index2))) + new HTuple(",")) + "NG") + new HTuple(",")) + hv_I) + new HTuple(",")) + (hv_Setnumber.TupleSelect( hv_Index2))); HOperatorSet.FnewLine(hv_FileHandle); } } HOperatorSet.CountSeconds(out hv_T2); HOperatorSet.FwriteString(hv_FileHandle, ("执行时间:" + (hv_T2 - hv_T1)) + "S"); HOperatorSet.CloseFile(hv_FileHandle); ho_Image.Dispose(); ho_GrayImage3.Dispose(); ho_ImageGauss.Dispose(); ho_ModelContours.Dispose(); ho_TransContours.Dispose(); ho_Rectangle.Dispose(); ho_ImageReduced.Dispose(); }
public luowenbiaomian5() { //RegionToDisp = Image; HOperatorSet.GenEmptyObj(out RegionToDisp); RegionToDisp.Dispose(); }
// Procedures // Chapter: Develop // Short Description: Open a new graphics window that preserves the aspect ratio of the given image. public void dev_open_window_fit_image(HObject ho_Image, HTuple hv_Row, HTuple hv_Column, HTuple hv_WidthLimit, HTuple hv_HeightLimit, out HTuple hv_WindowHandle) { // Local iconic variables // Local control variables HTuple hv_MinWidth = new HTuple(), hv_MaxWidth = new HTuple(); HTuple hv_MinHeight = new HTuple(), hv_MaxHeight = new HTuple(); HTuple hv_ResizeFactor = null, hv_ImageWidth = null, hv_ImageHeight = null; HTuple hv_TempWidth = null, hv_TempHeight = null, hv_WindowWidth = new HTuple(); HTuple hv_WindowHeight = null; // Initialize local and output iconic variables hv_WindowHandle = new HTuple(); //This procedure opens a new graphics window and adjusts the size //such that it fits into the limits specified by WidthLimit //and HeightLimit, but also maintains the correct image aspect ratio. // //If it is impossible to match the minimum and maximum extent requirements //at the same time (f.e. if the image is very long but narrow), //the maximum value gets a higher priority, // //Parse input tuple WidthLimit if ((int)((new HTuple((new HTuple(hv_WidthLimit.TupleLength())).TupleEqual(0))).TupleOr( new HTuple(hv_WidthLimit.TupleLess(0)))) != 0) { hv_MinWidth = 500; hv_MaxWidth = 800; } else if ((int)(new HTuple((new HTuple(hv_WidthLimit.TupleLength())).TupleEqual( 1))) != 0) { hv_MinWidth = 0; hv_MaxWidth = hv_WidthLimit.Clone(); } else { hv_MinWidth = hv_WidthLimit.TupleSelect(0); hv_MaxWidth = hv_WidthLimit.TupleSelect(1); } //Parse input tuple HeightLimit if ((int)((new HTuple((new HTuple(hv_HeightLimit.TupleLength())).TupleEqual(0))).TupleOr( new HTuple(hv_HeightLimit.TupleLess(0)))) != 0) { hv_MinHeight = 400; hv_MaxHeight = 600; } else if ((int)(new HTuple((new HTuple(hv_HeightLimit.TupleLength())).TupleEqual( 1))) != 0) { hv_MinHeight = 0; hv_MaxHeight = hv_HeightLimit.Clone(); } else { hv_MinHeight = hv_HeightLimit.TupleSelect(0); hv_MaxHeight = hv_HeightLimit.TupleSelect(1); } // //Test, if window size has to be changed. hv_ResizeFactor = 1; HOperatorSet.GetImageSize(ho_Image, out hv_ImageWidth, out hv_ImageHeight); //First, expand window to the minimum extents (if necessary). if ((int)((new HTuple(hv_MinWidth.TupleGreater(hv_ImageWidth))).TupleOr(new HTuple(hv_MinHeight.TupleGreater( hv_ImageHeight)))) != 0) { hv_ResizeFactor = (((((hv_MinWidth.TupleReal()) / hv_ImageWidth)).TupleConcat( (hv_MinHeight.TupleReal()) / hv_ImageHeight))).TupleMax(); } hv_TempWidth = hv_ImageWidth * hv_ResizeFactor; hv_TempHeight = hv_ImageHeight * hv_ResizeFactor; //Then, shrink window to maximum extents (if necessary). if ((int)((new HTuple(hv_MaxWidth.TupleLess(hv_TempWidth))).TupleOr(new HTuple(hv_MaxHeight.TupleLess( hv_TempHeight)))) != 0) { hv_ResizeFactor = hv_ResizeFactor * ((((((hv_MaxWidth.TupleReal()) / hv_TempWidth)).TupleConcat( (hv_MaxHeight.TupleReal()) / hv_TempHeight))).TupleMin()); } hv_WindowWidth = hv_ImageWidth * hv_ResizeFactor; hv_WindowHeight = hv_ImageHeight * hv_ResizeFactor; //Resize window //dev_open_window(...); HOperatorSet.SetPart(hv_ExpDefaultWinHandle, 0, 0, hv_ImageHeight - 1, hv_ImageWidth - 1); return; }
public MainForm() { //将当前线程绑定到指定的cpu核心上 GetCpu.SetThreadAffinityMask(GetCpu.GetCurrentThread(), new UIntPtr(0x0008)); InitializeComponent(); //Control.CheckForIllegalCrossThreadCalls = true; pn = new ProductNum(); isfirstrun = true; //HOperatorSet.GenEmptyObj(out Image1); //HOperatorSet.GenEmptyObj(out Image2); //HOperatorSet.GenEmptyObj(out Image3); //HOperatorSet.GenEmptyObj(out Image4); //Image1.Dispose(); //Image2.Dispose(); //Image3.Dispose(); //Image4.Dispose(); this.gridView1.RowCellStyle += new DevExpress.XtraGrid.Views.Grid.RowCellStyleEventHandler(gridView1_RowCellStyle); HOperatorSet.GenEmptyObj(out ImageTemp); ImageTemp.Dispose(); ccameras = new List <CCamera>(); CCD = new Dictionary <string, CCamera>(); ds = new DataSet(); dt = new DataTable("datacopy"); CurrentCCD = "CCD1"; MSStartTimer.Tick += new EventHandler(MSStartTimer_OnTime); MSStoptTimer.Tick += new EventHandler(MSStoptTimer_OnTime); InitialDataGrid(gridControlResult, ds); ReadCameraSetting(); FormLoadProduct f = new FormLoadProduct(); //Thread th = new Thread(new ThreadStart(DoSplash)); //th.Start(); //Thread.Sleep(3000); //th.Abort(); //Thread.Sleep(1000); //if (splashResult == DialogResult.Cancel) //{ // this.Close(); //} DialogResult dialogr = f.ShowDialog(); if (dialogr == DialogResult.OK) { try { FileHelper.LoadCameraResultToShowData(ccameras, PathHelper.currentProductPath); FileHelper.LoadProductData(gridView1, gridControlResult, ds, PathHelper.currentProductPath); FileHelper.LoadCameraToolsData(ccameras, PathHelper.currentProductPath); labelpname.Text = PathHelper.currentProduct; } catch { MessageBox.Show("相机或产品信息加载错误"); } } else if (dialogr == DialogResult.Cancel) { this.Close(); } string path = @"c:\zyw.txt"; if (!File.Exists(path)) { File.AppendAllText(path, "zhongwen", Encoding.Default); } zyw = File.ReadAllText(path, Encoding.Default); if (zyw == "zhongwen") { label1.Text = "产品名称:"; simpleButton1.Text = "生成报表"; BtnSaveParam.Text = "保存参数"; BtnSaveNewProduct.Text = "保存新产品"; BtnControlSet.Text = "控制设定"; BtnLogin.Text = "登录"; BtnLoadProduct.Text = "计数清零"; BtnSetting.Text = "设定"; BtnStop.Text = "停止"; BtnStart.Text = "启动"; } if (zyw == "yinwen") { label1.Text = "productname:"; simpleButton1.Text = "GenerateReport"; BtnSaveParam.Text = "SaveParameter"; BtnSaveNewProduct.Text = "SaveNewProduct"; BtnControlSet.Text = "ControlSet"; BtnLogin.Text = "Login"; BtnLoadProduct.Text = "ResetAllCounters"; BtnSetting.Text = "Setting"; BtnStop.Text = "Stop"; BtnStart.Text = "Start"; } Turntable.Instance.ReadPos(PathHelper.dataPath + @"\Position.xml"); // Turntable.Instance.OnUpdateProductInfoEvent += new Turntable.UpdateProductInfo(UpdateProInfo); Turntable.Instance.StrongPressEventHandler += new Turntable.StrongPress(Instance_StrongPressEventHandler); Turntable.Instance.wuliao += new Turntable.wuliaohandler(wuliaotingzhiEventHandler); }
public void InitHalcon() { // Default settings used in HDevelop HOperatorSet.SetSystem("width", 512); HOperatorSet.SetSystem("height", 512); }
//DateTime t1, t2, t3, t4,t5,t6,t7; private void action() { HObject ho_Region2 = null, ho_ConnectedRegions4 = null; HObject ho_SelectedRegions1 = null, ho_RegionClosing = null; HObject ho_RegionDifference = null, ho_ConnectedRegions1 = null; HObject ho_ObjectSelected1 = null, ho_Contours = null, ho_RegionErosion1 = null; HObject ho_RegionDilation1 = null, ho_RegionErosion = null; HObject ho_RegionIntersection = null, ho_RegionDilation2 = null; HObject ho_RegionDifference1 = null, ho_ConnectedRegions2 = null; HObject ho_SelectedRegions = null, ho_RegionUnion = null, ho_RegionDilation = null; HObject ho_ImageReduced = null, ho_Region1 = null, ho_ConnectedRegions3 = null; HObject ho_ObjectSelected2 = null, ho_RegionFillUp = null, ho_Circle = null; HObject ho_Circle1 = null, ho_RegionDifference2 = null, ho_RegionUnion1 = null; HObject ho_RegionUnion2 = null; HTuple hv_Area1 = new HTuple(), hv_Row2 = new HTuple(); HTuple hv_Column2 = new HTuple(), hv_Indices1 = new HTuple(); HTuple hv_Row3 = new HTuple(), hv_Column3 = new HTuple(); HTuple hv_Radius1 = new HTuple(), hv_StartPhi = new HTuple(); HTuple hv_EndPhi = new HTuple(), hv_PointOrder = new HTuple(); HTuple hv_Circularity = new HTuple(), hv_Area2 = new HTuple(); HTuple hv_Row5 = new HTuple(), hv_Column5 = new HTuple(); HTuple hv_Area3 = new HTuple(), hv_Row6 = new HTuple(); HTuple hv_Column6 = new HTuple(), hv_Indices2 = new HTuple(); HTuple hv_Row7 = new HTuple(), hv_Column7 = new HTuple(); HTuple hv_Radius2 = new HTuple(), hv_Row8 = new HTuple(); HTuple hv_Column8 = new HTuple(), hv_Radius3 = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Region2); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions4); HOperatorSet.GenEmptyObj(out ho_SelectedRegions1); HOperatorSet.GenEmptyObj(out ho_RegionClosing); HOperatorSet.GenEmptyObj(out ho_RegionDifference); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions1); HOperatorSet.GenEmptyObj(out ho_ObjectSelected1); HOperatorSet.GenEmptyObj(out ho_Contours); HOperatorSet.GenEmptyObj(out ho_RegionErosion1); HOperatorSet.GenEmptyObj(out ho_RegionDilation1); HOperatorSet.GenEmptyObj(out ho_RegionErosion); HOperatorSet.GenEmptyObj(out ho_RegionIntersection); HOperatorSet.GenEmptyObj(out ho_RegionDilation2); HOperatorSet.GenEmptyObj(out ho_RegionDifference1); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions2); HOperatorSet.GenEmptyObj(out ho_SelectedRegions); HOperatorSet.GenEmptyObj(out ho_RegionUnion); HOperatorSet.GenEmptyObj(out ho_RegionDilation); HOperatorSet.GenEmptyObj(out ho_ImageReduced); HOperatorSet.GenEmptyObj(out ho_Region1); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions3); HOperatorSet.GenEmptyObj(out ho_ObjectSelected2); HOperatorSet.GenEmptyObj(out ho_RegionFillUp); HOperatorSet.GenEmptyObj(out ho_Circle); HOperatorSet.GenEmptyObj(out ho_Circle1); HOperatorSet.GenEmptyObj(out ho_RegionDifference2); HOperatorSet.GenEmptyObj(out ho_RegionUnion1); HOperatorSet.GenEmptyObj(out ho_RegionUnion2); HOperatorSet.Union1(algorithm.Region, out RegionToDisp); //t3 = DateTime.Now; try { ho_Region2.Dispose(); HOperatorSet.Threshold(Image, out ho_Region2, 0, thv); ho_ConnectedRegions4.Dispose(); HOperatorSet.Connection(ho_Region2, out ho_ConnectedRegions4); ho_SelectedRegions1.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions4, out ho_SelectedRegions1, "area", "and", mjxx, mjsx); ho_RegionClosing.Dispose(); HOperatorSet.ClosingCircle(ho_SelectedRegions1, out ho_RegionClosing, 700); ho_RegionDifference.Dispose(); HOperatorSet.Difference(ho_RegionClosing, ho_SelectedRegions1, out ho_RegionDifference ); ho_ConnectedRegions1.Dispose(); HOperatorSet.Connection(ho_RegionDifference, out ho_ConnectedRegions1); HOperatorSet.AreaCenter(ho_ConnectedRegions1, out hv_Area1, out hv_Row2, out hv_Column2); HOperatorSet.TupleFind(hv_Area1, hv_Area1.TupleMax(), out hv_Indices1); ho_ObjectSelected1.Dispose(); HOperatorSet.SelectObj(ho_ConnectedRegions1, out ho_ObjectSelected1, hv_Indices1 + 1); ho_Contours.Dispose(); HOperatorSet.GenContourRegionXld(ho_ObjectSelected1, out ho_Contours, "border"); HOperatorSet.FitCircleContourXld(ho_Contours, "algebraic", -1, 0, 0, 3, 2, out hv_Row3, out hv_Column3, out hv_Radius1, out hv_StartPhi, out hv_EndPhi, out hv_PointOrder); ho_RegionErosion1.Dispose(); HOperatorSet.ErosionCircle(ho_ObjectSelected1, out ho_RegionErosion1, 10.5); ho_RegionDilation1.Dispose(); HOperatorSet.DilationCircle(ho_RegionErosion1, out ho_RegionDilation1, 10.5); HOperatorSet.Circularity(ho_RegionDilation1, out hv_Circularity); ho_RegionErosion.Dispose(); HOperatorSet.ErosionCircle(ho_RegionClosing, out ho_RegionErosion, 25.5); ho_RegionIntersection.Dispose(); HOperatorSet.Intersection(ho_RegionDifference, ho_RegionErosion, out ho_RegionIntersection ); ho_RegionDilation2.Dispose(); HOperatorSet.DilationCircle(ho_RegionDilation1, out ho_RegionDilation2, 5.5); ho_RegionDifference1.Dispose(); HOperatorSet.Difference(ho_RegionIntersection, ho_RegionDilation2, out ho_RegionDifference1 ); ho_ConnectedRegions2.Dispose(); HOperatorSet.Connection(ho_RegionDifference1, out ho_ConnectedRegions2); ho_SelectedRegions.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions2, out ho_SelectedRegions, "area", "and", 15, 99999000); ho_RegionUnion.Dispose(); HOperatorSet.Union1(ho_SelectedRegions, out ho_RegionUnion); HOperatorSet.AreaCenter(ho_RegionUnion, out hv_Area2, out hv_Row5, out hv_Column5); ho_RegionDilation.Dispose(); HOperatorSet.DilationCircle(ho_RegionClosing, out ho_RegionDilation, 30); ho_ImageReduced.Dispose(); HOperatorSet.ReduceDomain(Image, ho_RegionDilation, out ho_ImageReduced); ho_Region1.Dispose(); HOperatorSet.Threshold(ho_ImageReduced, out ho_Region1, 170, 255); ho_ConnectedRegions3.Dispose(); HOperatorSet.Connection(ho_Region1, out ho_ConnectedRegions3); HOperatorSet.AreaCenter(ho_ConnectedRegions3, out hv_Area3, out hv_Row6, out hv_Column6); HOperatorSet.TupleFind(hv_Area3, hv_Area3.TupleMax(), out hv_Indices2); ho_ObjectSelected2.Dispose(); HOperatorSet.SelectObj(ho_ConnectedRegions3, out ho_ObjectSelected2, hv_Indices2 + 1); ho_RegionFillUp.Dispose(); HOperatorSet.FillUp(ho_ObjectSelected2, out ho_RegionFillUp); HOperatorSet.SmallestCircle(ho_RegionFillUp, out hv_Row7, out hv_Column7, out hv_Radius2); ho_Circle.Dispose(); HOperatorSet.GenCircle(out ho_Circle, hv_Row7, hv_Column7, hv_Radius2); HOperatorSet.InnerCircle(ho_RegionFillUp, out hv_Row8, out hv_Column8, out hv_Radius3); ho_Circle1.Dispose(); HOperatorSet.GenCircle(out ho_Circle1, hv_Row8, hv_Column8, hv_Radius3); ho_RegionDifference2.Dispose(); HOperatorSet.Difference(ho_Circle, ho_Circle1, out ho_RegionDifference2); ho_RegionUnion1.Dispose(); HOperatorSet.Union2(ho_RegionDifference2, ho_RegionUnion, out ho_RegionUnion1 ); ho_RegionUnion2.Dispose(); HOperatorSet.Union2(ho_RegionUnion1, ho_RegionDilation1, out RegionToDisp ); if (hv_Area2.TupleLength() == 0) { hv_Area2 = 0; } HTuple hv_result = GetHv_result(); hv_result = hv_result.TupleConcat("垫片内孔圆度"); hv_result = hv_result.TupleConcat(hv_Circularity.D); hv_result = hv_result.TupleConcat("垫片内孔直径"); hv_result = hv_result.TupleConcat(hv_Radius1.D * 2 * pixeldist); hv_result = hv_result.TupleConcat("垫片灰尘"); hv_result = hv_result.TupleConcat(hv_Area2.D); hv_result = hv_result.TupleConcat("不圆"); hv_result = hv_result.TupleConcat((hv_Radius2.D - hv_Radius3.D) * pixeldist); result = hv_result.Clone(); //t4 = DateTime.Now; } 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(999999); hv_result = hv_result.TupleConcat("不圆"); hv_result = hv_result.TupleConcat(1000 * pixeldist); result = hv_result.Clone(); } finally { ho_Region2.Dispose(); ho_ConnectedRegions4.Dispose(); ho_SelectedRegions1.Dispose(); ho_RegionClosing.Dispose(); ho_RegionDifference.Dispose(); ho_ConnectedRegions1.Dispose(); ho_ObjectSelected1.Dispose(); ho_Contours.Dispose(); ho_RegionErosion1.Dispose(); ho_RegionDilation1.Dispose(); ho_RegionErosion.Dispose(); ho_RegionIntersection.Dispose(); ho_RegionDilation2.Dispose(); ho_RegionDifference1.Dispose(); ho_ConnectedRegions2.Dispose(); ho_SelectedRegions.Dispose(); ho_RegionUnion.Dispose(); ho_RegionDilation.Dispose(); ho_ImageReduced.Dispose(); ho_Region1.Dispose(); ho_ConnectedRegions3.Dispose(); ho_ObjectSelected2.Dispose(); ho_RegionFillUp.Dispose(); ho_Circle.Dispose(); ho_Circle1.Dispose(); ho_RegionDifference2.Dispose(); ho_RegionUnion1.Dispose(); ho_RegionUnion2.Dispose(); algorithm.Region.Dispose(); } }
public HDevelopExport() { // Default settings used in HDevelop HOperatorSet.SetSystem("do_low_error", "false"); action(); }