public override bool doLocal() { LocalResult TempTwoCirLocalRlt = new LocalResult(); NowResult = new LineCircRectRlt(); try{ MyTempTwoCirLocal.Set(NowImg, NowVisionPara); MyTempTwoCirLocal.doLocal(); TempTwoCirLocalRlt = MyTempTwoCirLocal.GetResult(); HTuple HomMat = new HTuple(); // //计算当前图片到示教图片的偏移矩阵 HOperatorSet.VectorAngleToRigid(TempTwoCirLocalRlt.row, TempTwoCirLocalRlt.col, TempTwoCirLocalRlt.angle, TempTwoCirLocalRlt.TeachRow, TempTwoCirLocalRlt.TeachCol, TempTwoCirLocalRlt.TeachAngle, out HomMat);// HObject AffineImg = new HObject(); //矫正图像位置 HOperatorSet.AffineTransImage(NowImg, out AffineImg, HomMat, "constant", "false"); ((LineCircRectRlt)NowResult).IsOk = LineCircleRectInspBase.LineCircleRectInsp(AffineImg, NowVisionPara.LineCirRectInspParam, out ((LineCircRectRlt)NowResult).DetectContour, out ((LineCircRectRlt)NowResult).NgContour); // HOperatorSet.CopyObj(TempTwoCirLocalRlt.ShowContour, out ((LineCircRectRlt)NowResult).ShowContour, 1, -1); //位置的逆变换 HOperatorSet.VectorAngleToRigid(TempTwoCirLocalRlt.TeachRow, TempTwoCirLocalRlt.TeachCol, TempTwoCirLocalRlt.TeachAngle, TempTwoCirLocalRlt.row, TempTwoCirLocalRlt.col, TempTwoCirLocalRlt.angle, out HomMat);// NowResult.AffineTransResult(HomMat, out NowResult); return(true); } catch (Exception e0) { Logger.PopError1(e0, false, "视觉运行错误日志"); return(false); } }
public int FindModel(HObject ho_inImage, HObject ho_inRegion, double MinScore, HTuple hv_inModelID, out HObject ho_outRectifiedImage, out double Score) { int nRet = 1; Score = 0; HOperatorSet.AreaCenter(ho_inRegion, out _, out HTuple hv_RefRow, out HTuple hv_RefColumn); if (MinScore >= 1 || MinScore <= 0) { MinScore = 0.75; } HOperatorSet.FindShapeModel(ho_inImage, hv_inModelID, (new HTuple(-50)).TupleRad() , (new HTuple(100)).TupleRad(), 0.5, 1, 0, "least_squares", (new HTuple(3)).TupleConcat( 1), MinScore, out HTuple hv_Row, out HTuple hv_Column, out HTuple hv_Angle, out HTuple hv_Score); if (hv_Score.TupleLength() > 0) { HOperatorSet.HomMat2dIdentity(out HTuple hv_RectificationHomMat2D); HOperatorSet.HomMat2dTranslate(hv_RectificationHomMat2D, hv_RefRow - (hv_Row.TupleSelect(0)), hv_RefColumn - (hv_Column.TupleSelect(0)), out hv_RectificationHomMat2D); HOperatorSet.HomMat2dRotate(hv_RectificationHomMat2D, -(hv_Angle.TupleSelect(0)), hv_RefRow, hv_RefColumn, out hv_RectificationHomMat2D); HOperatorSet.AffineTransImage(ho_inImage, out ho_outRectifiedImage, hv_RectificationHomMat2D, "constant", "false"); Score = hv_Score.TupleSelect(0).D; nRet = 0; HOperatorSet.HomMat2dIdentity(out HTuple hv_AlignmentHomMat2D); HOperatorSet.HomMat2dTranslate(hv_AlignmentHomMat2D, -hv_RefRow, -hv_RefColumn, out hv_AlignmentHomMat2D); HOperatorSet.HomMat2dRotate(hv_AlignmentHomMat2D, hv_Angle.TupleSelect(0), 0, 0, out hv_AlignmentHomMat2D); HOperatorSet.HomMat2dTranslate(hv_AlignmentHomMat2D, hv_Row.TupleSelect(0), hv_Column.TupleSelect(0), out homMat2D); } else { HOperatorSet.HomMat2dIdentity(out homMat2D); HOperatorSet.CopyImage(ho_inImage, out ho_outRectifiedImage); } return(nRet); }
public void affineTransImage(ref HObject m_image, ref HTuple image_width, ref HTuple image_height, ref HTuple char_height) { try { //图形变量 Area of text lines. HObject m_trans_region; //数值变量 HTuple row1, col1, row2, col2; HTuple m_orientationAngle, m_HomMat2D; row1 = image_height * 0.1; col1 = image_width * 0.1; row2 = image_height * 0.9; col2 = image_width * 0.9; HOperatorSet.GenEmptyObj(out m_trans_region); m_trans_region.Dispose(); HOperatorSet.GenRectangle1(out m_trans_region, row1, col1, row2, col2); HOperatorSet.TextLineOrientation(m_trans_region, m_image, char_height, -0.523599, 0.523599, out m_orientationAngle); HOperatorSet.VectorAngleToRigid(image_height * 0.5, image_width * 0.5, m_orientationAngle, image_height * 0.5, image_width * 0.5, 0, out m_HomMat2D); HOperatorSet.AffineTransImage(m_image, out m_image, m_HomMat2D, "constant", "false"); //释放 m_trans_region.Dispose(); } catch { } }
public override bool doLocal() { NowResult = new LineCircRectRlt(); BlobLocalRlt myBlobLocalRlt = new BlobLocalRlt(); try { myBlobLocal.Set(NowImg, NowVisionPara); myBlobLocal.doLocal(); myBlobLocalRlt = (BlobLocalRlt)myBlobLocal.GetResult(); HTuple HomMat = new HTuple(); // //计算当前图片到示教图片的偏移矩阵 HOperatorSet.VectorAngleToRigid(myBlobLocalRlt.row, myBlobLocalRlt.col, myBlobLocalRlt.angle, myBlobLocalRlt.TeachRow, myBlobLocalRlt.TeachCol, myBlobLocalRlt.TeachAngle, out HomMat); HObject AffineImg = new HObject(); //矫正图像位置 HOperatorSet.AffineTransImage(NowImg, out AffineImg, HomMat, "constant", "false"); //开始检测 ((LineCircRectRlt)NowResult).IsOk = LineCircleRectInspBase.LineCircleRectInsp(AffineImg, NowVisionPara.LineCirRectInspParam, out ((LineCircRectRlt)NowResult).DetectContour, out ((LineCircRectRlt)NowResult).NgContour); // HOperatorSet.CopyObj(myBlobLocalRlt.ShowContour, out ((LineCircRectRlt)NowResult).ShowContour, 1, -1); //位置的逆变换 HOperatorSet.VectorAngleToRigid(myBlobLocalRlt.TeachRow, myBlobLocalRlt.TeachCol, myBlobLocalRlt.TeachAngle, myBlobLocalRlt.row, myBlobLocalRlt.col, myBlobLocalRlt.angle, out HomMat); NowResult.AffineTransResult(HomMat, out NowResult); return(true); } catch { return(false); } }
public override bool doLocal() { try { NowResult = new LocalResult(); MyTempLocal.Set(NowImg, NowVisionPara); MyTempLocal.doLocal(); LocalResult TempLocalResult = new LocalResult(); TempLocalResult = MyTempLocal.GetResult(); HTuple HomMat = new HTuple(); // //计算当前图片到示教图片的偏移矩阵 HOperatorSet.VectorAngleToRigid(TempLocalResult.row, TempLocalResult.col, TempLocalResult.angle, NowVisionPara.Template.CenterY, NowVisionPara.Template.CenterX, NowVisionPara.Template.TemplateAngle, out HomMat); HObject AffineImg = new HObject(); HOperatorSet.AffineTransImage(NowImg, out AffineImg, HomMat, "constant", "false");//矫正图像位 //计算示教图片到当前图片的偏移矩阵 HTuple ReHomMat = new HTuple(); HOperatorSet.VectorAngleToRigid(NowVisionPara.Template.CenterY, NowVisionPara.Template.CenterX, NowVisionPara.Template.TemplateAngle, TempLocalResult.row, TempLocalResult.col, TempLocalResult.angle, out ReHomMat); MyLineCirLocal.Set(NowImg, NowVisionPara); MyLineCirLocal.doLocal(); LocalResult CircleResult = new LocalResult(); //位置的逆变换 MyLineCirLocal.NowResult.AffineTransResult(ReHomMat, out CircleResult); HOperatorSet.ConcatObj(TempLocalResult.ShowContour, CircleResult.ShowContour, out CircleResult.ShowContour); NowResult = CircleResult; return(true); } catch { return(false); } }
public override bool doLocal() { try { NowResult = new LocalResult(); MyTempLocal.Set(NowImg, NowVisionPara); MyTempLocal.doLocal(); LocalResult TempLocalResult = new LocalResult(); TempLocalResult = MyTempLocal.GetResult(); HTuple HomMat = new HTuple(); // //¼ÆË㵱ǰͼƬµ½Ê¾½ÌͼƬµÄÆ«ÒƾØÕó HOperatorSet.VectorAngleToRigid(TempLocalResult.row, TempLocalResult.col, TempLocalResult.angle, NowVisionPara.Template.CenterY, NowVisionPara.Template.CenterX, NowVisionPara.Template.TemplateAngle, out HomMat); // HObject AffineImg = new HObject(); HOperatorSet.AffineTransImage(NowImg, out AffineImg, HomMat, "constant", "false"); //½ÃÕýͼÏñλÖà MyBlobLocal.Set(AffineImg, NowVisionPara); MyBlobLocal.doLocal(); //¼ÆË㵱ǰʾ½ÌͼƬµ½µ±Ç°Í¼Æ¬µÄÆ«ÒƾØÕó HTuple ReHomMat = new HTuple(); HOperatorSet.VectorAngleToRigid(NowVisionPara.Template.CenterY, NowVisionPara.Template.CenterX, NowVisionPara.Template.TemplateAngle, TempLocalResult.row, TempLocalResult.col, TempLocalResult.angle, out ReHomMat);// MyBlobLocal.NowResult.AffineTransResult(ReHomMat, out NowResult); return(true); } catch { return(false); } }
public override bool doLocal() { try { NowResult = new LocalResult(); myBlobLocal.Set(NowImg, NowVisionPara); myBlobLocal.doLocal(); LocalResult blobLocalRlt = new LocalResult(); blobLocalRlt = myBlobLocal.GetResult(); HTuple HomMat = new HTuple(); // //计算当前图片到示教图片的偏移矩阵 HOperatorSet.VectorAngleToRigid(blobLocalRlt.row, blobLocalRlt.col, blobLocalRlt.angle, blobLocalRlt.TeachRow, blobLocalRlt.TeachCol, blobLocalRlt.TeachAngle, out HomMat); // HObject AffineImg = new HObject(); HOperatorSet.AffineTransImage(NowImg, out AffineImg, HomMat, "constant", "false"); //矫正图像位置 myTwoLineLocal.Set(AffineImg, NowVisionPara); myTwoLineLocal.doLocal(); LocalResult LineLocalResult = new LocalResult(); //计算当前示教图片到当前图片的偏移矩阵 HTuple ReHomMat = new HTuple(); HOperatorSet.VectorAngleToRigid(blobLocalRlt.TeachRow, blobLocalRlt.TeachCol, blobLocalRlt.TeachAngle, blobLocalRlt.row, blobLocalRlt.col, blobLocalRlt.angle, out ReHomMat);// myTwoLineLocal.NowResult.AffineTransResult(ReHomMat, out LineLocalResult); //调整直线定位的位置和 HOperatorSet.ConcatObj(blobLocalRlt.ShowContour, LineLocalResult.ShowContour, out LineLocalResult.ShowContour); NowResult = LineLocalResult; return(true); } catch { return(false); } }
public static void RotateImage(HObject sourceImage, out HObject destImage, HTuple row1, HTuple col1, HTuple row2, HTuple col2) { HTuple linePhi = null; HOperatorSet.LineOrientation(row1, col1, row2, col2, out linePhi); HTuple lineCenterRow = (row1 + row2) / 2.0; HTuple lineCenterCol = (col1 + col2) / 2.0; HTuple hom2d = null, hom2dRotate = null; HOperatorSet.HomMat2dIdentity(out hom2d); HOperatorSet.HomMat2dRotate(hom2d, -linePhi, lineCenterRow, lineCenterCol, out hom2dRotate); destImage = null; HOperatorSet.AffineTransImage(sourceImage, out destImage, hom2dRotate, "bilinear", "false"); }
private void TryDebugBtn_Click(object sender, EventArgs e) { txtFindTime.Clear(); Stopwatch sw = new Stopwatch(); sw.Start(); //HObject LineContourU = new HObject(); //HObject across = new HObject(); //HObject lines = new HObject(); //MyVisionBase.hDispObj(ShowWindow, GrabedImg); //St_LinesParam tempLineParam = new St_LinesParam(TeachLinesPara.Count); //tempLineParam = TeachLinesPara; ////1.0对于新的图片根据模板匹配的VectorAngle和示教模板的VectorAngle调整直线的示教起始点 //St_VectorAngle VectorAngle0 = new St_VectorAngle(LocalPara0.Template.CenterY, LocalPara0.Template.CenterX, LocalPara0.Template.TemplateAngle); //LineTypePos.AdjLineTeachPara(VectorAngle0.Row, VectorAngle0.Col, VectorAngle0.Angle, // TempFindVectorAngle.Row, TempFindVectorAngle.Col, TempFindVectorAngle.Angle, TeachLinesPara, out tempLineParam); ////2.0找出要定位的直线 //LineTypePos.FindLine(tempLineParam, GrabedImg, out OutLineRow1, out OutLineCol1, out OutLineRow2, out OutLineCol2, out across, out LineContourU); ////3.0显示 //HOperatorSet.SetColor(ShowWindow, "blue"); //MyVisionBase.hDispObj(ShowWindow, LineContourU); //HOperatorSet.SetColor(ShowWindow, "red"); //MyVisionBase.hDispObj(ShowWindow, across); //HOperatorSet.SetColor(ShowWindow, "green"); //MyVisionBase.hDispObj(ShowWindow, lines); //if (LineContourU != null) LineContourU.Dispose(); //if (lines != null) lines.Dispose(); //if (across != null) across.Dispose(); HTuple ImgHomMat = new HTuple(); HObject AffineImg = new HObject(); switch (LocalPara0.localSetting.localModel) { case LocalModelEnum.TempTwoLine: case LocalModelEnum.TempThreeLine: case LocalModelEnum.TempFourLine: case LocalModelEnum.TempLineCircle: HOperatorSet.VectorAngleToRigid(TempFindVectorAngle.Row, TempFindVectorAngle.Col, TempFindVectorAngle.Angle , LocalPara0.Template.CenterY, LocalPara0.Template.CenterX, LocalPara0.Template.TemplateAngle, out ImgHomMat); HOperatorSet.AffineTransImage(GrabedImg, out AffineImg, ImgHomMat, "constant", "false"); view1.AddImage(AffineImg); break; } txtFindTime.Text = sw.ElapsedMilliseconds.ToString(); }
private void action() { // Stack for temporary objects HObject[] OTemp = new HObject[20]; // Local iconic variables HObject ho_Rectanglem; HObject ho_Regionm; HObject ho_Regionn, ho_Regiont, ho_ImageAffinTrans = null; HObject ho_ImageReduced = null, ho_Region = null, ho_RegionDilation1 = null; HObject ho_ConnectedRegions2 = null, ho_SelectedRegions2 = null; HObject ho_RegionTrans2 = null, ho_RegionDifference2 = null; HObject ho_RegionErosion1 = null, ho_ConnectedRegions3 = null; HObject ho_SelectedRegions3 = null, ho_RegionTrans3 = null; HObject ho_ImageReduced3 = null, ho_Region3 = null, ho_ConnectedRegions4 = null; HObject ho_SelectedRegions4 = null, ho_RegionErosion = null; HObject ho_RegionDilation = null, ho_RegionClosing = null, ho_ConnectedRegions = null; HObject ho_SelectedRegions = null, ho_ObjectSelected = null; HObject ho_RegionTrans = null, ho_ImageReduced1 = null, ho_Region1 = null; HObject ho_RegionDifference = null, ho_ObjectSelected1 = null; HObject ho_RegionTrans1 = null, ho_ImageReduced2 = null, ho_Region2 = null; HObject ho_RegionDifference1 = null, ho_ConnectedRegions1 = null; HObject ho_SelectedRegions1 = null, ho_RegionAffineTrans = null; // Local control variables HTuple hv_m = null, hv_n = null, hv_m1 = null, hv_n1 = null; HTuple hv_h1 = null, hv_w1 = null, hv_h2 = null, hv_w2 = null; HTuple hv_Row = null, hv_Column = null, hv_Angle = null; HTuple hv_Score = null, hv_HomMat2D = new HTuple(), hv_Area1 = new HTuple(); HTuple hv_Row4 = new HTuple(), hv_Column4 = new HTuple(); HTuple hv_Number = new HTuple(), hv_Row1 = new HTuple(); HTuple hv_Column1 = new HTuple(), hv_Row2 = new HTuple(); HTuple hv_Column2 = new HTuple(), hv_Row11 = new HTuple(); HTuple hv_Column11 = new HTuple(), hv_Row21 = new HTuple(); HTuple hv_Column21 = new HTuple(), hv_Area = new HTuple(); HTuple hv_Row3 = new HTuple(), hv_Column3 = new HTuple(); HTuple hv_HomMat2D1 = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Rectanglem); HOperatorSet.GenEmptyObj(out ho_Regionm); HOperatorSet.GenEmptyObj(out ho_Regionn); HOperatorSet.GenEmptyObj(out ho_Regiont); HOperatorSet.GenEmptyObj(out ho_ImageAffinTrans); HOperatorSet.GenEmptyObj(out ho_ImageReduced); HOperatorSet.GenEmptyObj(out ho_Region); HOperatorSet.GenEmptyObj(out ho_RegionDilation1); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions2); HOperatorSet.GenEmptyObj(out ho_SelectedRegions2); HOperatorSet.GenEmptyObj(out ho_RegionTrans2); HOperatorSet.GenEmptyObj(out ho_RegionDifference2); HOperatorSet.GenEmptyObj(out ho_RegionErosion1); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions3); HOperatorSet.GenEmptyObj(out ho_SelectedRegions3); HOperatorSet.GenEmptyObj(out ho_RegionTrans3); HOperatorSet.GenEmptyObj(out ho_ImageReduced3); HOperatorSet.GenEmptyObj(out ho_Region3); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions4); HOperatorSet.GenEmptyObj(out ho_SelectedRegions4); HOperatorSet.GenEmptyObj(out ho_RegionErosion); HOperatorSet.GenEmptyObj(out ho_RegionDilation); HOperatorSet.GenEmptyObj(out ho_RegionClosing); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions); HOperatorSet.GenEmptyObj(out ho_SelectedRegions); HOperatorSet.GenEmptyObj(out ho_ObjectSelected); HOperatorSet.GenEmptyObj(out ho_RegionTrans); HOperatorSet.GenEmptyObj(out ho_ImageReduced1); HOperatorSet.GenEmptyObj(out ho_Region1); HOperatorSet.GenEmptyObj(out ho_RegionDifference); HOperatorSet.GenEmptyObj(out ho_ObjectSelected1); HOperatorSet.GenEmptyObj(out ho_RegionTrans1); HOperatorSet.GenEmptyObj(out ho_ImageReduced2); HOperatorSet.GenEmptyObj(out ho_Region2); HOperatorSet.GenEmptyObj(out ho_RegionDifference1); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions1); HOperatorSet.GenEmptyObj(out ho_SelectedRegions1); HOperatorSet.GenEmptyObj(out ho_RegionAffineTrans); HOperatorSet.Union1(algorithm.Region, out RegionToDisp); try { hv_m = 0; hv_n = 0; hv_m1 = 0; hv_n1 = 0; hv_h1 = 0; hv_w1 = 0; hv_h2 = 0; hv_w2 = 0; ho_Regionm.Dispose(); HOperatorSet.GenRegionPoints(out ho_Regionm, DRows, DColumns); ho_Regionn.Dispose(); HOperatorSet.GenRegionPoints(out ho_Regionn, DRows, DColumns); ho_Regiont.Dispose(); HOperatorSet.GenRegionPoints(out ho_Regiont, DRows, DColumns); ho_Rectanglem.Dispose(); HOperatorSet.GenRectangle1(out ho_Rectanglem, DRows, DColumns, DLength1s, DLength2s); HOperatorSet.ReadShapeModel(PathHelper.currentProductPath + @"\waiguan2.shm", out hv_ModelID); HOperatorSet.FindShapeModel(Image, hv_ModelID, -6.29, 6.29, 0, 1, 0.5, "least_squares", 0, 0.9, out hv_Row, out hv_Column, out hv_Angle, out hv_Score); if ((int)(new HTuple((new HTuple(hv_Score.TupleLength())).TupleEqual(1))) != 0) { HOperatorSet.VectorAngleToRigid(hv_Row, hv_Column, hv_Angle, DRow1s, DColumn1s, 0, out hv_HomMat2D); ho_ImageAffinTrans.Dispose(); HOperatorSet.AffineTransImage(Image, out ho_ImageAffinTrans, hv_HomMat2D, "constant", "false"); ho_ImageReduced.Dispose(); HOperatorSet.ReduceDomain(ho_ImageAffinTrans, ho_Rectanglem, out ho_ImageReduced ); ho_Region.Dispose(); HOperatorSet.Threshold(ho_ImageReduced, out ho_Region, thv, 255); // ho_RegionDilation1.Dispose(); HOperatorSet.DilationCircle(ho_Region, out ho_RegionDilation1, this.afs); ho_ConnectedRegions2.Dispose(); HOperatorSet.Connection(ho_RegionDilation1, out ho_ConnectedRegions2); ho_SelectedRegions2.Dispose(); HOperatorSet.SelectShapeStd(ho_ConnectedRegions2, out ho_SelectedRegions2, "max_area", 70); ho_RegionTrans2.Dispose(); HOperatorSet.ShapeTrans(ho_SelectedRegions2, out ho_RegionTrans2, "convex"); ho_RegionDifference2.Dispose(); HOperatorSet.Difference(ho_RegionTrans2, ho_SelectedRegions2, out ho_RegionDifference2 ); ho_RegionErosion1.Dispose(); HOperatorSet.ErosionCircle(ho_RegionDifference2, out ho_RegionErosion1, this.apz); ho_ConnectedRegions3.Dispose(); HOperatorSet.Connection(ho_RegionErosion1, out ho_ConnectedRegions3); ho_SelectedRegions3.Dispose(); HOperatorSet.SelectShapeStd(ho_ConnectedRegions3, out ho_SelectedRegions3, "max_area", 70); ho_RegionTrans3.Dispose(); HOperatorSet.ShapeTrans(ho_SelectedRegions3, out ho_RegionTrans3, "convex"); ho_ImageReduced3.Dispose(); HOperatorSet.ReduceDomain(ho_ImageReduced, ho_RegionTrans3, out ho_ImageReduced3 ); ho_Region3.Dispose(); HOperatorSet.Threshold(ho_ImageReduced3, out ho_Region3, thv, 255); ho_ConnectedRegions4.Dispose(); HOperatorSet.Connection(ho_Region3, out ho_ConnectedRegions4); ho_SelectedRegions4.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions4, out ho_SelectedRegions4, "area", "and", this.kdz, 9900999); HOperatorSet.AreaCenter(ho_SelectedRegions4, out hv_Area1, out hv_Row4, out hv_Column4); if ((int)(new HTuple((new HTuple(hv_Area1.TupleLength())).TupleGreater(0))) != 0) { hv_m1 = hv_Area1.TupleMax(); hv_n1 = hv_Area1.TupleSum(); { HObject ExpTmpOutVar_0; HOperatorSet.Union2(ho_Regionn, ho_SelectedRegions4, out ExpTmpOutVar_0); ho_Regionn.Dispose(); ho_Regionn = ExpTmpOutVar_0; } } else { hv_m1 = 0; hv_n1 = 0; } // ho_RegionErosion.Dispose(); HOperatorSet.ErosionRectangle1(ho_Region, out ho_RegionErosion, this.cd, this.pzz); ho_RegionDilation.Dispose(); HOperatorSet.DilationRectangle1(ho_RegionErosion, out ho_RegionDilation, this.cd, this.pzz); ho_RegionClosing.Dispose(); HOperatorSet.ClosingRectangle1(ho_RegionDilation, out ho_RegionClosing, this.yd, this.bjz); ho_ConnectedRegions.Dispose(); HOperatorSet.Connection(ho_RegionClosing, out ho_ConnectedRegions); ho_SelectedRegions.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, (new HTuple("height")).TupleConcat( "width"), "and", (new HTuple(this.yd)).TupleConcat(this.bjz), (new HTuple(9999)).TupleConcat( 5000)); HOperatorSet.CountObj(ho_SelectedRegions, out hv_Number); if ((int)(new HTuple(hv_Number.TupleEqual(2))) != 0) { ho_ObjectSelected.Dispose(); HOperatorSet.SelectObj(ho_SelectedRegions, out ho_ObjectSelected, 1); ho_RegionTrans.Dispose(); HOperatorSet.ShapeTrans(ho_ObjectSelected, out ho_RegionTrans, "convex"); HOperatorSet.SmallestRectangle1(ho_RegionTrans, out hv_Row1, out hv_Column1, out hv_Row2, out hv_Column2); hv_h1 = hv_Row2 - hv_Row1; hv_w1 = hv_Column2 - hv_Column1; ho_ImageReduced1.Dispose(); HOperatorSet.ReduceDomain(ho_ImageReduced, ho_RegionTrans, out ho_ImageReduced1 ); ho_Region1.Dispose(); HOperatorSet.Threshold(ho_ImageReduced1, out ho_Region1, thv, 255); ho_RegionDifference.Dispose(); HOperatorSet.Difference(ho_RegionTrans, ho_Region1, out ho_RegionDifference ); { HObject ExpTmpOutVar_0; HOperatorSet.Union2(ho_Regionm, ho_RegionDifference, out ExpTmpOutVar_0); ho_Regionm.Dispose(); ho_Regionm = ExpTmpOutVar_0; } ho_ObjectSelected1.Dispose(); HOperatorSet.SelectObj(ho_SelectedRegions, out ho_ObjectSelected1, 2); ho_RegionTrans1.Dispose(); HOperatorSet.ShapeTrans(ho_ObjectSelected1, out ho_RegionTrans1, "convex"); HOperatorSet.SmallestRectangle1(ho_RegionTrans1, out hv_Row11, out hv_Column11, out hv_Row21, out hv_Column21); hv_h2 = hv_Row21 - hv_Row11; hv_w2 = hv_Column21 - hv_Column11; ho_ImageReduced2.Dispose(); HOperatorSet.ReduceDomain(ho_ImageReduced, ho_RegionTrans1, out ho_ImageReduced2 ); ho_Region2.Dispose(); HOperatorSet.Threshold(ho_ImageReduced2, out ho_Region2, thv, 255); ho_RegionDifference1.Dispose(); HOperatorSet.Difference(ho_RegionTrans1, ho_Region2, out ho_RegionDifference1 ); { HObject ExpTmpOutVar_0; HOperatorSet.Union2(ho_Regionm, ho_RegionDifference1, out ExpTmpOutVar_0); ho_Regionm.Dispose(); ho_Regionm = ExpTmpOutVar_0; } ho_ConnectedRegions1.Dispose(); HOperatorSet.Connection(ho_Regionm, out ho_ConnectedRegions1); ho_SelectedRegions1.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions1, out ho_SelectedRegions1, "area", "and", this.mj, 99999); HOperatorSet.AreaCenter(ho_SelectedRegions1, out hv_Area, out hv_Row3, out hv_Column3); if ((int)(new HTuple((new HTuple(hv_Area.TupleLength())).TupleGreater(0))) != 0) { hv_m = hv_Area.TupleMax(); hv_n = hv_Area.TupleSum(); { HObject ExpTmpOutVar_0; HOperatorSet.Union2(ho_Regionn, ho_SelectedRegions1, out ExpTmpOutVar_0 ); ho_Regionn.Dispose(); ho_Regionn = ExpTmpOutVar_0; } } else { hv_m = 0; hv_n = 0; } } HOperatorSet.VectorAngleToRigid(DRow1s, DColumn1s, 0, hv_Row, hv_Column, hv_Angle, out hv_HomMat2D1); ho_RegionAffineTrans.Dispose(); HOperatorSet.AffineTransRegion(ho_Regionn, out ho_RegionAffineTrans, hv_HomMat2D1, "nearest_neighbor"); { HObject ExpTmpOutVar_0; HOperatorSet.Union2(ho_Regiont, ho_RegionAffineTrans, out ExpTmpOutVar_0); ho_Regiont.Dispose(); ho_Regiont = ExpTmpOutVar_0; } } else { hv_h1 = 0; hv_w1 = 0; hv_h2 = 0; hv_w2 = 0; hv_m = 99999; hv_n = 99999; hv_m1 = 99999; hv_n1 = 99999; } HOperatorSet.ClearShapeModel(hv_ModelID); HOperatorSet.Union1(ho_Regiont, out RegionToDisp); HTuple hv_result = GetHv_result(); hv_result = hv_result.TupleConcat("亮色区缺陷总面积"); hv_result = hv_result.TupleConcat(hv_n.D); hv_result = hv_result.TupleConcat("亮色区最大缺陷面积"); hv_result = hv_result.TupleConcat(hv_m.D); hv_result = hv_result.TupleConcat("暗色区缺陷总面积"); hv_result = hv_result.TupleConcat(hv_n1.D); hv_result = hv_result.TupleConcat("暗色区最大缺陷面积"); hv_result = hv_result.TupleConcat(hv_m1.D); hv_result = hv_result.TupleConcat("高1"); hv_result = hv_result.TupleConcat(hv_h1.D); hv_result = hv_result.TupleConcat("宽1"); hv_result = hv_result.TupleConcat(hv_w1.D); hv_result = hv_result.TupleConcat("高2"); hv_result = hv_result.TupleConcat(hv_h2.D); hv_result = hv_result.TupleConcat("宽2"); hv_result = hv_result.TupleConcat(hv_w2.D); result = hv_result.Clone(); ho_Rectanglem.Dispose(); ho_Regionm.Dispose(); ho_Regionn.Dispose(); ho_Regiont.Dispose(); ho_ImageAffinTrans.Dispose(); ho_ImageReduced.Dispose(); ho_Region.Dispose(); ho_RegionDilation1.Dispose(); ho_ConnectedRegions2.Dispose(); ho_SelectedRegions2.Dispose(); ho_RegionTrans2.Dispose(); ho_RegionDifference2.Dispose(); ho_RegionErosion1.Dispose(); ho_ConnectedRegions3.Dispose(); ho_SelectedRegions3.Dispose(); ho_RegionTrans3.Dispose(); ho_ImageReduced3.Dispose(); ho_Region3.Dispose(); ho_ConnectedRegions4.Dispose(); ho_SelectedRegions4.Dispose(); ho_RegionErosion.Dispose(); ho_RegionDilation.Dispose(); ho_RegionClosing.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions.Dispose(); ho_ObjectSelected.Dispose(); ho_RegionTrans.Dispose(); ho_ImageReduced1.Dispose(); ho_Region1.Dispose(); ho_RegionDifference.Dispose(); ho_ObjectSelected1.Dispose(); ho_RegionTrans1.Dispose(); ho_ImageReduced2.Dispose(); ho_Region2.Dispose(); ho_RegionDifference1.Dispose(); ho_ConnectedRegions1.Dispose(); ho_SelectedRegions1.Dispose(); ho_RegionAffineTrans.Dispose(); algorithm.Region.Dispose(); } catch { HTuple hv_result = GetHv_result(); hv_result = hv_result.TupleConcat("亮色区缺陷总面积"); hv_result = hv_result.TupleConcat(9999999); hv_result = hv_result.TupleConcat("亮色区最大缺陷面积"); hv_result = hv_result.TupleConcat(9999999); hv_result = hv_result.TupleConcat("暗色区缺陷总面积"); hv_result = hv_result.TupleConcat(9999999); hv_result = hv_result.TupleConcat("暗色区最大缺陷面积"); hv_result = hv_result.TupleConcat(9999999); hv_result = hv_result.TupleConcat("高1"); hv_result = hv_result.TupleConcat(0); hv_result = hv_result.TupleConcat("宽1"); hv_result = hv_result.TupleConcat(0); hv_result = hv_result.TupleConcat("高2"); hv_result = hv_result.TupleConcat(0); hv_result = hv_result.TupleConcat("宽2"); hv_result = hv_result.TupleConcat(0); result = hv_result.Clone(); ho_Rectanglem.Dispose(); ho_Regionm.Dispose(); ho_Regionn.Dispose(); ho_Regiont.Dispose(); ho_ImageAffinTrans.Dispose(); ho_ImageReduced.Dispose(); ho_Region.Dispose(); ho_RegionDilation1.Dispose(); ho_ConnectedRegions2.Dispose(); ho_SelectedRegions2.Dispose(); ho_RegionTrans2.Dispose(); ho_RegionDifference2.Dispose(); ho_RegionErosion1.Dispose(); ho_ConnectedRegions3.Dispose(); ho_SelectedRegions3.Dispose(); ho_RegionTrans3.Dispose(); ho_ImageReduced3.Dispose(); ho_Region3.Dispose(); ho_ConnectedRegions4.Dispose(); ho_SelectedRegions4.Dispose(); ho_RegionErosion.Dispose(); ho_RegionDilation.Dispose(); ho_RegionClosing.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions.Dispose(); ho_ObjectSelected.Dispose(); ho_RegionTrans.Dispose(); ho_ImageReduced1.Dispose(); ho_Region1.Dispose(); ho_RegionDifference.Dispose(); ho_ObjectSelected1.Dispose(); ho_RegionTrans1.Dispose(); ho_ImageReduced2.Dispose(); ho_Region2.Dispose(); ho_RegionDifference1.Dispose(); ho_ConnectedRegions1.Dispose(); ho_SelectedRegions1.Dispose(); ho_RegionAffineTrans.Dispose(); algorithm.Region.Dispose(); } finally { ho_Rectanglem.Dispose(); ho_Regionm.Dispose(); ho_Regionn.Dispose(); ho_Regiont.Dispose(); ho_ImageAffinTrans.Dispose(); ho_ImageReduced.Dispose(); ho_Region.Dispose(); ho_RegionDilation1.Dispose(); ho_ConnectedRegions2.Dispose(); ho_SelectedRegions2.Dispose(); ho_RegionTrans2.Dispose(); ho_RegionDifference2.Dispose(); ho_RegionErosion1.Dispose(); ho_ConnectedRegions3.Dispose(); ho_SelectedRegions3.Dispose(); ho_RegionTrans3.Dispose(); ho_ImageReduced3.Dispose(); ho_Region3.Dispose(); ho_ConnectedRegions4.Dispose(); ho_SelectedRegions4.Dispose(); ho_RegionErosion.Dispose(); ho_RegionDilation.Dispose(); ho_RegionClosing.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions.Dispose(); ho_ObjectSelected.Dispose(); ho_RegionTrans.Dispose(); ho_ImageReduced1.Dispose(); ho_Region1.Dispose(); ho_RegionDifference.Dispose(); ho_ObjectSelected1.Dispose(); ho_RegionTrans1.Dispose(); ho_ImageReduced2.Dispose(); ho_Region2.Dispose(); ho_RegionDifference1.Dispose(); ho_ConnectedRegions1.Dispose(); ho_SelectedRegions1.Dispose(); ho_RegionAffineTrans.Dispose(); algorithm.Region.Dispose(); } }
// Main procedure private void action() { // Local iconic variables HObject ho_Image, ho_ModelRegion, ho_TemplateImage; HObject ho_ModelContours, ho_RectifiedImage = null, ho_Regions = null; HObject ho_ConnectedRegions = null, ho_SelectedRegions = null; HObject ho_Contours = null, ho_Regions1 = null, ho_RegionLines = null; // Local control variables HTuple hv_ModelID = new HTuple(), hv_ModelRegionArea = new HTuple(); HTuple hv_RefRow = new HTuple(), hv_RefColumn = new HTuple(); HTuple hv_TestImages = new HTuple(), hv_T = new HTuple(); HTuple hv_Row = new HTuple(), hv_Column = new HTuple(); HTuple hv_Angle = new HTuple(), hv_Score = new HTuple(); HTuple hv_I = new HTuple(), hv_RectificationHomMat2D = new HTuple(); HTuple hv_Row1 = new HTuple(), hv_Column1 = new HTuple(); HTuple hv_Radius = new HTuple(), hv_MetrologyHandle = new HTuple(); HTuple hv_Width = new HTuple(), hv_Height = new HTuple(); HTuple hv_Index = new HTuple(), hv_Row3 = new HTuple(); HTuple hv_Column3 = new HTuple(), hv_Parameter = new HTuple(); HTuple hv_Row2 = new HTuple(), hv_Column2 = new HTuple(); HTuple hv_Radius1 = new HTuple(), hv_MetrologyHandle1 = new HTuple(); HTuple hv_Index1 = new HTuple(), hv_Parameter1 = new HTuple(); HTuple hv_SmlC = new HTuple(), hv_SR = new HTuple(), hv_SC = new HTuple(); HTuple hv_BR = new HTuple(), hv_BC = new HTuple(), hv_Distance = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Image); HOperatorSet.GenEmptyObj(out ho_ModelRegion); HOperatorSet.GenEmptyObj(out ho_TemplateImage); HOperatorSet.GenEmptyObj(out ho_ModelContours); HOperatorSet.GenEmptyObj(out ho_RectifiedImage); HOperatorSet.GenEmptyObj(out ho_Regions); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions); HOperatorSet.GenEmptyObj(out ho_SelectedRegions); HOperatorSet.GenEmptyObj(out ho_Contours); HOperatorSet.GenEmptyObj(out ho_Regions1); HOperatorSet.GenEmptyObj(out ho_RegionLines); // //Matching 01: ************************************************ //Matching 01: BEGIN of generated code for model initialization //Matching 01: ************************************************ HOperatorSet.SetSystem("border_shape_models", "false"); // //Matching 01: Obtain the model image ho_Image.Dispose(); HOperatorSet.ReadImage(out ho_Image, "C:/Users/Chanru/Desktop/Class/bd/bd1.png"); // //Matching 01: Build the ROI from basic regions ho_ModelRegion.Dispose(); HOperatorSet.GenRectangle1(out ho_ModelRegion, 445.809, 637.592, 801.311, 1070.62); // //Matching 01: Reduce the model template ho_TemplateImage.Dispose(); HOperatorSet.ReduceDomain(ho_Image, ho_ModelRegion, out ho_TemplateImage); // //Matching 01: Create the shape model hv_ModelID.Dispose(); HOperatorSet.CreateShapeModel(ho_TemplateImage, 6, (new HTuple(0)).TupleRad() , (new HTuple(360)).TupleRad(), (new HTuple(0.4233)).TupleRad(), (new HTuple("point_reduction_medium")).TupleConcat( "no_pregeneration"), "use_polarity", ((new HTuple(10)).TupleConcat(14)).TupleConcat( 35), 3, out hv_ModelID); // //Matching 01: Get the model contour for transforming it later into the image ho_ModelContours.Dispose(); HOperatorSet.GetShapeModelContours(out ho_ModelContours, hv_ModelID, 1); // //Matching 01: Get the reference position hv_ModelRegionArea.Dispose(); hv_RefRow.Dispose(); hv_RefColumn.Dispose(); HOperatorSet.AreaCenter(ho_ModelRegion, out hv_ModelRegionArea, out hv_RefRow, out hv_RefColumn); // //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 hv_TestImages.Dispose(); hv_TestImages = new HTuple(); hv_TestImages[0] = "C:/Users/Chanru/Desktop/Class/bd/bd1.png"; hv_TestImages[1] = "C:/Users/Chanru/Desktop/Class/bd/bd10.png"; hv_TestImages[2] = "C:/Users/Chanru/Desktop/Class/bd/bd2.png"; hv_TestImages[3] = "C:/Users/Chanru/Desktop/Class/bd/bd3.png"; hv_TestImages[4] = "C:/Users/Chanru/Desktop/Class/bd/bd4.png"; hv_TestImages[5] = "C:/Users/Chanru/Desktop/Class/bd/bd5.png"; hv_TestImages[6] = "C:/Users/Chanru/Desktop/Class/bd/bd6.png"; hv_TestImages[7] = "C:/Users/Chanru/Desktop/Class/bd/bd7.png"; hv_TestImages[8] = "C:/Users/Chanru/Desktop/Class/bd/bd8.png"; hv_TestImages[9] = "C:/Users/Chanru/Desktop/Class/bd/bd9.png"; for (hv_T = 0; (int)hv_T <= 9; hv_T = (int)hv_T + 1) { // //Matching 01: Obtain the test image ho_Image.Dispose(); HOperatorSet.ReadImage(out ho_Image, hv_TestImages.TupleSelect(hv_T)); // //Matching 01: Find the model hv_Row.Dispose(); hv_Column.Dispose(); hv_Angle.Dispose(); hv_Score.Dispose(); HOperatorSet.FindShapeModel(ho_Image, hv_ModelID, (new HTuple(0)).TupleRad() , (new HTuple(360)).TupleRad(), 0.5, 0, 0.5, "least_squares", (new HTuple(6)).TupleConcat( 1), 0.75, out hv_Row, out hv_Column, out hv_Angle, out hv_Score); // //Matching 01: Code for rectification of the image //Matching 01: Calculate an inverse hom_mat2d for each of the matching results for (hv_I = 0; (int)hv_I <= (int)((new HTuple(hv_Score.TupleLength())) - 1); hv_I = (int)hv_I + 1) { hv_RectificationHomMat2D.Dispose(); HOperatorSet.HomMat2dIdentity(out hv_RectificationHomMat2D); { HTuple ExpTmpOutVar_0; HOperatorSet.HomMat2dTranslate(hv_RectificationHomMat2D, hv_RefRow - (hv_Row.TupleSelect( hv_I)), hv_RefColumn - (hv_Column.TupleSelect(hv_I)), out ExpTmpOutVar_0); hv_RectificationHomMat2D.Dispose(); hv_RectificationHomMat2D = ExpTmpOutVar_0; } { HTuple ExpTmpOutVar_0; HOperatorSet.HomMat2dRotate(hv_RectificationHomMat2D, -(hv_Angle.TupleSelect( hv_I)), hv_RefRow, hv_RefColumn, out ExpTmpOutVar_0); hv_RectificationHomMat2D.Dispose(); hv_RectificationHomMat2D = ExpTmpOutVar_0; } ho_RectifiedImage.Dispose(); HOperatorSet.AffineTransImage(ho_Image, out ho_RectifiedImage, hv_RectificationHomMat2D, "constant", "false"); // //Matching 01: Insert your code using the rectified image here ho_Regions.Dispose(); HOperatorSet.Threshold(ho_Image, out ho_Regions, 99, 255); ho_ConnectedRegions.Dispose(); HOperatorSet.Connection(ho_Regions, out ho_ConnectedRegions); ho_SelectedRegions.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, "area", "and", 150, 800); hv_Row1.Dispose(); hv_Column1.Dispose(); hv_Radius.Dispose(); HOperatorSet.SmallestCircle(ho_SelectedRegions, out hv_Row1, out hv_Column1, out hv_Radius); hv_MetrologyHandle.Dispose(); HOperatorSet.CreateMetrologyModel(out hv_MetrologyHandle); hv_Width.Dispose(); hv_Height.Dispose(); HOperatorSet.GetImageSize(ho_RectifiedImage, out hv_Width, out hv_Height); HOperatorSet.SetMetrologyModelImageSize(hv_MetrologyHandle, hv_Width, hv_Height); hv_Index.Dispose(); HOperatorSet.AddMetrologyObjectCircleMeasure(hv_MetrologyHandle, hv_Row1, hv_Column1, hv_Radius, 20, 5, 1, 30, "num_measures", 30, out hv_Index); HOperatorSet.ApplyMetrologyModel(ho_RectifiedImage, hv_MetrologyHandle); ho_Contours.Dispose(); hv_Row3.Dispose(); hv_Column3.Dispose(); HOperatorSet.GetMetrologyObjectMeasures(out ho_Contours, hv_MetrologyHandle, "all", "all", out hv_Row3, out hv_Column3); hv_Parameter.Dispose(); HOperatorSet.GetMetrologyObjectResult(hv_MetrologyHandle, "all", "all", "result_type", "all_param", out hv_Parameter); //********* ho_Regions1.Dispose(); HOperatorSet.Threshold(ho_Image, out ho_Regions1, 22, 78); hv_Row2.Dispose(); hv_Column2.Dispose(); hv_Radius1.Dispose(); HOperatorSet.SmallestCircle(ho_Regions1, out hv_Row2, out hv_Column2, out hv_Radius1); hv_MetrologyHandle1.Dispose(); HOperatorSet.CreateMetrologyModel(out hv_MetrologyHandle1); HOperatorSet.SetMetrologyModelImageSize(hv_MetrologyHandle1, hv_Width, hv_Height); hv_Index1.Dispose(); HOperatorSet.AddMetrologyObjectCircleMeasure(hv_MetrologyHandle1, hv_Row2, hv_Column2, hv_Radius1, 20, 5, 1, 30, new HTuple(), new HTuple(), out hv_Index1); HOperatorSet.ApplyMetrologyModel(ho_RectifiedImage, hv_MetrologyHandle1); hv_Parameter1.Dispose(); HOperatorSet.GetMetrologyObjectResult(hv_MetrologyHandle1, "all", "all", "result_type", "all_param", out hv_Parameter1); //******* hv_SmlC.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_SmlC = HTuple.TupleGenSequence( 0, (new HTuple(hv_Parameter.TupleLength())) - 1, 3); } hv_SR.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_SR = hv_Parameter.TupleSelect( hv_SmlC); } hv_SC.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_SC = hv_Parameter.TupleSelect( hv_SmlC + 1); } hv_BR.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_BR = (hv_SR * 0) + (hv_Parameter1.TupleSelect( 0)); } hv_BC.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_BC = (hv_SC * 0) + (hv_Parameter1.TupleSelect( 1)); } hv_Distance.Dispose(); HOperatorSet.DistancePp(hv_SR, hv_SC, hv_BR, hv_BC, out hv_Distance); if (HDevWindowStack.IsOpen()) { HOperatorSet.DispObj(ho_RectifiedImage, HDevWindowStack.GetActive()); } ho_RegionLines.Dispose(); HOperatorSet.GenRegionLine(out ho_RegionLines, hv_SR, hv_SC, hv_BR, hv_BC); // stop(...); only in hdevelop } } // //Matching 01: ******************************************* //Matching 01: END of generated code for model application //Matching 01: ******************************************* // ho_Image.Dispose(); ho_ModelRegion.Dispose(); ho_TemplateImage.Dispose(); ho_ModelContours.Dispose(); ho_RectifiedImage.Dispose(); ho_Regions.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions.Dispose(); ho_Contours.Dispose(); ho_Regions1.Dispose(); ho_RegionLines.Dispose(); hv_ModelID.Dispose(); hv_ModelRegionArea.Dispose(); hv_RefRow.Dispose(); hv_RefColumn.Dispose(); hv_TestImages.Dispose(); hv_T.Dispose(); hv_Row.Dispose(); hv_Column.Dispose(); hv_Angle.Dispose(); hv_Score.Dispose(); hv_I.Dispose(); hv_RectificationHomMat2D.Dispose(); hv_Row1.Dispose(); hv_Column1.Dispose(); hv_Radius.Dispose(); hv_MetrologyHandle.Dispose(); hv_Width.Dispose(); hv_Height.Dispose(); hv_Index.Dispose(); hv_Row3.Dispose(); hv_Column3.Dispose(); hv_Parameter.Dispose(); hv_Row2.Dispose(); hv_Column2.Dispose(); hv_Radius1.Dispose(); hv_MetrologyHandle1.Dispose(); hv_Index1.Dispose(); hv_Parameter1.Dispose(); hv_SmlC.Dispose(); hv_SR.Dispose(); hv_SC.Dispose(); hv_BR.Dispose(); hv_BC.Dispose(); hv_Distance.Dispose(); }
private void action() { // Stack for temporary objects HObject[] OTemp = new HObject[20]; // Local iconic variables HObject ho_Circley, ho_Circley1; HObject ho_Rectanglem; HObject ho_Region3, ho_Region4, ho_Region5; HObject ho_ImageAffinTrans = null, ho_RegionDifference = null; HObject ho_RegionDifference1 = null, ho_ImageReduced2 = null; HObject ho_ImageMean1 = null, ho_RegionDynThresh = null, ho_RegionDynThresh1 = null; HObject ho_RegionErosion = null, ho_ImageReduced3 = null, ho_Region1 = null; HObject ho_Region2 = null, ho_ConnectedRegions = null, ho_SelectedRegions = null; HObject ho_RegionAffineTrans; // Local control variables HTuple hv_ModelID = null, hv_aa = null; HTuple hv_bb = null, hv_Row2 = null, hv_Column2 = null; HTuple hv_Angle = null, hv_Score = null, hv_HomMat2D = new HTuple(); HTuple hv_Area = new HTuple(), hv_Row3 = new HTuple(); HTuple hv_Column3 = new HTuple(), hv_HomMat2D1 = null; // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Circley); HOperatorSet.GenEmptyObj(out ho_Circley1); HOperatorSet.GenEmptyObj(out ho_Rectanglem); HOperatorSet.GenEmptyObj(out ho_Region3); HOperatorSet.GenEmptyObj(out ho_Region4); HOperatorSet.GenEmptyObj(out ho_Region5); HOperatorSet.GenEmptyObj(out ho_ImageAffinTrans); HOperatorSet.GenEmptyObj(out ho_RegionDifference); HOperatorSet.GenEmptyObj(out ho_RegionDifference1); HOperatorSet.GenEmptyObj(out ho_ImageReduced2); HOperatorSet.GenEmptyObj(out ho_ImageMean1); HOperatorSet.GenEmptyObj(out ho_RegionDynThresh); HOperatorSet.GenEmptyObj(out ho_RegionDynThresh1); HOperatorSet.GenEmptyObj(out ho_RegionErosion); HOperatorSet.GenEmptyObj(out ho_ImageReduced3); HOperatorSet.GenEmptyObj(out ho_Region1); HOperatorSet.GenEmptyObj(out ho_Region2); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions); HOperatorSet.GenEmptyObj(out ho_SelectedRegions); HOperatorSet.GenEmptyObj(out ho_RegionAffineTrans); HOperatorSet.Union1(algorithm.Region, out RegionToDisp); try { hv_aa = 0; hv_bb = 0; ho_Region3.Dispose(); HOperatorSet.GenRegionPoints(out ho_Region3, DRows, DColumns); ho_Region4.Dispose(); HOperatorSet.GenRegionPoints(out ho_Region4, DRows, DColumns); ho_Region5.Dispose(); HOperatorSet.GenRegionPoints(out ho_Region5, DRows, DColumns); ho_Circley.Dispose(); HOperatorSet.GenCircle(out ho_Circley, DRowy, DColumny, DPhiy); ho_Circley1.Dispose(); HOperatorSet.GenCircle(out ho_Circley1, DRowz, DColumnz, DPhiz); ho_Rectanglem.Dispose(); HOperatorSet.GenRectangle2(out ho_Rectanglem, DRows, DColumns, DPhis, DLength1s, DLength2s); HOperatorSet.ReadShapeModel(PathHelper.currentProductPath + @"\nbquekou.shm", out hv_ModelID); HOperatorSet.FindShapeModel(Image, hv_ModelID, 0, 3.15, 0.3, 1, 0.5, "least_squares", 0, 0.9, out hv_Row2, out hv_Column2, out hv_Angle, out hv_Score); if ((int)(new HTuple((new HTuple(hv_Score.TupleLength())).TupleEqual(1))) != 0) { HOperatorSet.VectorAngleToRigid(hv_Row2, hv_Column2, hv_Angle, DRow1s, DColumn1s, 0, out hv_HomMat2D); ho_ImageAffinTrans.Dispose(); HOperatorSet.AffineTransImage(Image, out ho_ImageAffinTrans, hv_HomMat2D, "constant", "false"); ho_RegionDifference.Dispose(); HOperatorSet.Difference(ho_Circley, ho_Circley1, out ho_RegionDifference); ho_RegionDifference1.Dispose(); HOperatorSet.Difference(ho_RegionDifference, ho_Rectanglem, out ho_RegionDifference1 ); ho_ImageReduced2.Dispose(); HOperatorSet.ReduceDomain(ho_ImageAffinTrans, ho_RegionDifference1, out ho_ImageReduced2 ); ho_ImageMean1.Dispose(); HOperatorSet.MeanImage(ho_ImageReduced2, out ho_ImageMean1, this.yd, this.yd); ho_RegionDynThresh.Dispose(); HOperatorSet.DynThreshold(ho_ImageReduced2, ho_ImageMean1, out ho_RegionDynThresh, this.bjz, "dark"); { HObject ExpTmpOutVar_0; HOperatorSet.Union2(ho_Region3, ho_RegionDynThresh, out ExpTmpOutVar_0); ho_Region3.Dispose(); ho_Region3 = ExpTmpOutVar_0; } ho_RegionDynThresh1.Dispose(); HOperatorSet.DynThreshold(ho_ImageReduced2, ho_ImageMean1, out ho_RegionDynThresh1, this.bjz, "light"); { HObject ExpTmpOutVar_0; HOperatorSet.Union2(ho_Region3, ho_RegionDynThresh1, out ExpTmpOutVar_0); ho_Region3.Dispose(); ho_Region3 = ExpTmpOutVar_0; } ho_RegionErosion.Dispose(); HOperatorSet.ErosionCircle(ho_RegionDifference1, out ho_RegionErosion, this.kdz); ho_ImageReduced3.Dispose(); HOperatorSet.ReduceDomain(ho_ImageAffinTrans, ho_RegionErosion, out ho_ImageReduced3 ); ho_Region1.Dispose(); HOperatorSet.Threshold(ho_ImageReduced3, out ho_Region1, 0, this.pzz); { HObject ExpTmpOutVar_0; HOperatorSet.Union2(ho_Region3, ho_Region1, out ExpTmpOutVar_0); ho_Region3.Dispose(); ho_Region3 = ExpTmpOutVar_0; } ho_Region2.Dispose(); HOperatorSet.Threshold(ho_ImageReduced3, out ho_Region2, this.cd, 255); { HObject ExpTmpOutVar_0; HOperatorSet.Union2(ho_Region3, ho_Region2, out ExpTmpOutVar_0); ho_Region3.Dispose(); ho_Region3 = ExpTmpOutVar_0; } ho_ConnectedRegions.Dispose(); HOperatorSet.Connection(ho_Region3, out ho_ConnectedRegions); ho_SelectedRegions.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, "area", "and", this.mj, 999990000); HOperatorSet.AreaCenter(ho_SelectedRegions, out hv_Area, out hv_Row3, out hv_Column3); if ((int)(new HTuple((new HTuple(hv_Area.TupleLength())).TupleGreater(0))) != 0) { { HObject ExpTmpOutVar_0; HOperatorSet.Union2(ho_Region4, ho_SelectedRegions, out ExpTmpOutVar_0); ho_Region4.Dispose(); ho_Region4 = ExpTmpOutVar_0; } hv_aa = hv_Area.TupleSum(); hv_bb = hv_Area.TupleMax(); } else { hv_aa = 0; hv_bb = 0; } } HOperatorSet.VectorAngleToRigid(DRow1s, DColumn1s, 0, hv_Row2, hv_Column2, hv_Angle, out hv_HomMat2D1); ho_RegionAffineTrans.Dispose(); HOperatorSet.AffineTransRegion(ho_Region4, out ho_RegionAffineTrans, hv_HomMat2D1, "nearest_neighbor"); { HObject ExpTmpOutVar_0; HOperatorSet.Union2(ho_Region5, ho_RegionAffineTrans, out ExpTmpOutVar_0); ho_Region5.Dispose(); ho_Region5 = ExpTmpOutVar_0; } HOperatorSet.ClearShapeModel(hv_ModelID); HOperatorSet.Union1(ho_Region5, out RegionToDisp); HTuple hv_result = GetHv_result(); hv_result = hv_result.TupleConcat("缺陷总面积"); hv_result = hv_result.TupleConcat(hv_aa.D); hv_result = hv_result.TupleConcat("最大面积"); hv_result = hv_result.TupleConcat(hv_bb.D); result = hv_result.Clone(); ho_Circley.Dispose(); ho_Circley1.Dispose(); ho_Rectanglem.Dispose(); ho_Region3.Dispose(); ho_Region4.Dispose(); ho_Region5.Dispose(); ho_ImageAffinTrans.Dispose(); ho_RegionDifference.Dispose(); ho_RegionDifference1.Dispose(); ho_ImageReduced2.Dispose(); ho_ImageMean1.Dispose(); ho_RegionDynThresh.Dispose(); ho_RegionDynThresh1.Dispose(); ho_RegionErosion.Dispose(); ho_ImageReduced3.Dispose(); ho_Region1.Dispose(); ho_Region2.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions.Dispose(); ho_RegionAffineTrans.Dispose(); algorithm.Region.Dispose(); } catch { HTuple hv_result = GetHv_result(); 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_Circley.Dispose(); ho_Circley1.Dispose(); ho_Rectanglem.Dispose(); ho_Region3.Dispose(); ho_Region4.Dispose(); ho_Region5.Dispose(); ho_ImageAffinTrans.Dispose(); ho_RegionDifference.Dispose(); ho_RegionDifference1.Dispose(); ho_ImageReduced2.Dispose(); ho_ImageMean1.Dispose(); ho_RegionDynThresh.Dispose(); ho_RegionDynThresh1.Dispose(); ho_RegionErosion.Dispose(); ho_ImageReduced3.Dispose(); ho_Region1.Dispose(); ho_Region2.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions.Dispose(); ho_RegionAffineTrans.Dispose(); algorithm.Region.Dispose(); } finally { ho_Circley.Dispose(); ho_Circley1.Dispose(); ho_Rectanglem.Dispose(); ho_Region3.Dispose(); ho_Region4.Dispose(); ho_Region5.Dispose(); ho_ImageAffinTrans.Dispose(); ho_RegionDifference.Dispose(); ho_RegionDifference1.Dispose(); ho_ImageReduced2.Dispose(); ho_ImageMean1.Dispose(); ho_RegionDynThresh.Dispose(); ho_RegionDynThresh1.Dispose(); ho_RegionErosion.Dispose(); ho_ImageReduced3.Dispose(); ho_Region1.Dispose(); ho_Region2.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions.Dispose(); ho_RegionAffineTrans.Dispose(); algorithm.Region.Dispose(); } }
// 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; }
// Main procedure private HTuple action() { // Local iconic variables HObject ho_Image, ho_ImageRotate, ho_GrayImage; HObject ho_ImageMedian, ho_Region, ho_ConnectedRegions; HObject ho_SelectedRegions, ho_SelectedRegions2, ho_SelectedRegions1; HObject ho_SelectedRegions3, ho_SortedRegions, ho_RegionUnion; HObject ho_Rectangle, ho_ImageReduced, ho_GrayImageA, ho_GragImageA; HObject ho_RegionsA_temp, ho_ConnectedRegionsA_temp, ho_SelectedRegionsA_temp; HObject ho_ImageAffineTrans, ho_RegionsA, ho_RegionDilationA; HObject ho_ConnectedRegionsA, ho_SelectedRegionsA, ho_RegionsA1; HObject ho_RegionOpeningA, ho_SelectedRegionsA1, ho_RegionUnionA; HObject ho_SelectedRegionsA2, ho_RegionsB, ho_ConnectedRegionsB; HObject ho_SelectedRegionsB, ho_RectangleB1, ho_RectangleB2; HObject ho_RegionDifferenceB, ho_ImageReducedB1, ho_RegionB1; HObject ho_ConnectedRegionsB2, ho_SelectedRegionsB2, ho_outContours; HObject ho_SelectedContours, ho_SortedContours, ho_Region1; HObject ho_ConnectedRegions1, ho_SelectedRegions4, ho_SelectedRegions5; HObject ho_SelectedRegions6, ho_Contours, ho_SortedContours3; HObject ho_obj = null, ho_objj = null, ho_ContoursSplit = null; HObject ho_SelectedXLD = null, ho_SortedContours1 = null, ho_M = null; HObject ho_Contour = null, ho_SelectedXLD1 = null, ho_SortedContours2 = null; HObject ho_ObjectSelectedB = null; // Local control variables HTuple hv_NumberB = null, hv_Row1 = null, hv_Column1 = null; HTuple hv_Phi = null, hv_Length1 = null, hv_Length2 = null; HTuple hv_Phi_temp = null, hv_Area_temp = null, hv_Row_temp = null; HTuple hv_Column_temp = null, hv_HomMat2D = null, hv_RowA1 = null; HTuple hv_ColumnA1 = null, hv_RowA2 = null, hv_ColumnA2 = null; HTuple hv_RowA3 = null, hv_ColumnA3 = null, hv_RowA4 = null; HTuple hv_ColumnA4 = null, hv_RowB16 = null, hv_ColumnB16 = null; HTuple hv_PhiB3 = null, hv_LengthB1 = null, hv_LengthB2 = null; HTuple hv_AreaB = null, hv_RowB2 = null, hv_ColumnB2 = null; HTuple hv_Number = null, hv_Number3 = null, hv_A1 = null; HTuple hv_A2 = null, hv_B1 = null, hv_B2 = null, hv_C1 = null; HTuple hv_C2 = null, hv_C3 = null, hv_C4 = null, hv_i = null; HTuple hv_Ro1 = new HTuple(), hv_Co1 = new HTuple(), hv_MinBR = new HTuple(); HTuple hv_MaxBR = new HTuple(), hv_MinBC = new HTuple(); HTuple hv_MaxBC = new HTuple(), hv_BR = new HTuple(), hv_BC = new HTuple(); HTuple hv_j = new HTuple(), hv_Number1 = new HTuple(); HTuple hv_a = new HTuple(), hv_Ro2 = new HTuple(), hv_Co2 = new HTuple(); HTuple hv_LUC = new HTuple(), hv_RUC = new HTuple(), hv_Ro3 = new HTuple(); HTuple hv_Co3 = new HTuple(), hv_LDC = new HTuple(), hv_RDC = 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_Rowc = new HTuple(), hv_Colc = new HTuple(); HTuple hv_MeanR = new HTuple(), hv_H1 = new HTuple(), hv_H3 = new HTuple(); HTuple hv_Number2 = new HTuple(), hv_b = new HTuple(); HTuple hv_Ro4 = new HTuple(), hv_Co4 = new HTuple(), hv_LUR = new HTuple(); HTuple hv_LDR = new HTuple(), hv_Ro5 = new HTuple(), hv_Co5 = new HTuple(); HTuple hv_RUR = new HTuple(), hv_RDR = new HTuple(), hv_MeanC = new HTuple(); HTuple hv_H4 = new HTuple(), hv_H2 = new HTuple(), hv_Distance1 = new HTuple(); HTuple hv_Distance2 = new HTuple(), hv_AreaA = null, hv_RowA = null; HTuple hv_ColumnA = null, hv_phi = null, hv_paozhengwei = null; HTuple hv_k = null, hv_Indices = null, hv_liebo = null; HTuple hv_NumB = null, hv_count = null, hv_I = new HTuple(); HTuple hv_AreaB1 = new HTuple(), hv_RowB3 = new HTuple(); HTuple hv_ColumnB3 = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Image); HOperatorSet.GenEmptyObj(out ho_ImageRotate); HOperatorSet.GenEmptyObj(out ho_GrayImage); HOperatorSet.GenEmptyObj(out ho_ImageMedian); HOperatorSet.GenEmptyObj(out ho_Region); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions); HOperatorSet.GenEmptyObj(out ho_SelectedRegions); HOperatorSet.GenEmptyObj(out ho_SelectedRegions2); HOperatorSet.GenEmptyObj(out ho_SelectedRegions1); HOperatorSet.GenEmptyObj(out ho_SelectedRegions3); HOperatorSet.GenEmptyObj(out ho_SortedRegions); HOperatorSet.GenEmptyObj(out ho_RegionUnion); HOperatorSet.GenEmptyObj(out ho_Rectangle); HOperatorSet.GenEmptyObj(out ho_ImageReduced); HOperatorSet.GenEmptyObj(out ho_GrayImageA); HOperatorSet.GenEmptyObj(out ho_GragImageA); HOperatorSet.GenEmptyObj(out ho_RegionsA_temp); HOperatorSet.GenEmptyObj(out ho_ConnectedRegionsA_temp); HOperatorSet.GenEmptyObj(out ho_SelectedRegionsA_temp); HOperatorSet.GenEmptyObj(out ho_ImageAffineTrans); HOperatorSet.GenEmptyObj(out ho_RegionsA); HOperatorSet.GenEmptyObj(out ho_RegionDilationA); HOperatorSet.GenEmptyObj(out ho_ConnectedRegionsA); HOperatorSet.GenEmptyObj(out ho_SelectedRegionsA); HOperatorSet.GenEmptyObj(out ho_RegionsA1); HOperatorSet.GenEmptyObj(out ho_RegionOpeningA); HOperatorSet.GenEmptyObj(out ho_SelectedRegionsA1); HOperatorSet.GenEmptyObj(out ho_RegionUnionA); HOperatorSet.GenEmptyObj(out ho_SelectedRegionsA2); HOperatorSet.GenEmptyObj(out ho_RegionsB); HOperatorSet.GenEmptyObj(out ho_ConnectedRegionsB); HOperatorSet.GenEmptyObj(out ho_SelectedRegionsB); HOperatorSet.GenEmptyObj(out ho_RectangleB1); HOperatorSet.GenEmptyObj(out ho_RectangleB2); HOperatorSet.GenEmptyObj(out ho_RegionDifferenceB); HOperatorSet.GenEmptyObj(out ho_ImageReducedB1); HOperatorSet.GenEmptyObj(out ho_RegionB1); HOperatorSet.GenEmptyObj(out ho_ConnectedRegionsB2); HOperatorSet.GenEmptyObj(out ho_SelectedRegionsB2); HOperatorSet.GenEmptyObj(out ho_outContours); HOperatorSet.GenEmptyObj(out ho_SelectedContours); HOperatorSet.GenEmptyObj(out ho_SortedContours); HOperatorSet.GenEmptyObj(out ho_Region1); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions1); HOperatorSet.GenEmptyObj(out ho_SelectedRegions4); HOperatorSet.GenEmptyObj(out ho_SelectedRegions5); HOperatorSet.GenEmptyObj(out ho_SelectedRegions6); HOperatorSet.GenEmptyObj(out ho_Contours); HOperatorSet.GenEmptyObj(out ho_SortedContours3); HOperatorSet.GenEmptyObj(out ho_obj); HOperatorSet.GenEmptyObj(out ho_objj); HOperatorSet.GenEmptyObj(out ho_ContoursSplit); HOperatorSet.GenEmptyObj(out ho_SelectedXLD); HOperatorSet.GenEmptyObj(out ho_SortedContours1); HOperatorSet.GenEmptyObj(out ho_M); HOperatorSet.GenEmptyObj(out ho_Contour); HOperatorSet.GenEmptyObj(out ho_SelectedXLD1); HOperatorSet.GenEmptyObj(out ho_SortedContours2); HOperatorSet.GenEmptyObj(out ho_ObjectSelectedB); ho_Image.Dispose(); if (!this.index) { HOperatorSet.ReadImage(out ho_Image, "test.bmp"); } else { HOperatorSet.ReadImage(out ho_Image, "PersonImg\\xiaosy.png"); } //*******************************************第一组预处理*********************************************** ho_ImageRotate.Dispose(); HOperatorSet.RotateImage(ho_Image, out ho_ImageRotate, 45, "constant"); ho_GrayImage.Dispose(); HOperatorSet.Rgb1ToGray(ho_ImageRotate, out ho_GrayImage); ho_ImageMedian.Dispose(); HOperatorSet.MedianImage(ho_GrayImage, out ho_ImageMedian, "circle", 3, "mirrored"); ho_Region.Dispose(); HOperatorSet.Threshold(ho_GrayImage, out ho_Region, 200, 255); ho_ConnectedRegions.Dispose(); HOperatorSet.Connection(ho_Region, out ho_ConnectedRegions); ho_SelectedRegions.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, "area", "and", 150, 99999); ho_SelectedRegions2.Dispose(); HOperatorSet.SelectShape(ho_SelectedRegions, out ho_SelectedRegions2, "circularity", "and", 0.37, 0.7); ho_SelectedRegions1.Dispose(); HOperatorSet.ClosingRectangle1(ho_SelectedRegions2, out ho_SelectedRegions1, 5, 5); ho_SelectedRegions3.Dispose(); HOperatorSet.SelectShape(ho_SelectedRegions1, out ho_SelectedRegions3, "holes_num", "and", 1, 99); ho_SortedRegions.Dispose(); HOperatorSet.SortRegion(ho_SelectedRegions3, out ho_SortedRegions, "first_point", "true", "column"); HOperatorSet.CountObj(ho_SelectedRegions3, out hv_NumberB); ho_RegionUnion.Dispose(); HOperatorSet.Union1(ho_SelectedRegions3, out ho_RegionUnion); HOperatorSet.SmallestRectangle2(ho_RegionUnion, out hv_Row1, out hv_Column1, out hv_Phi, out hv_Length1, out hv_Length2); ho_Rectangle.Dispose(); HOperatorSet.GenRectangle2(out ho_Rectangle, hv_Row1, hv_Column1, hv_Phi, hv_Length1, hv_Length2); ho_ImageReduced.Dispose(); HOperatorSet.ReduceDomain(ho_GrayImage, ho_Rectangle, out ho_ImageReduced); //*******************************************第二组预处理*********************************************** ho_GrayImageA.Dispose(); HOperatorSet.Rgb1ToGray(ho_Image, out ho_GrayImageA); ho_GragImageA.Dispose(); HOperatorSet.GrayDilationRect(ho_GrayImageA, out ho_GragImageA, 4, 4); ho_RegionsA_temp.Dispose(); HOperatorSet.Threshold(ho_GrayImageA, out ho_RegionsA_temp, 116, 218); ho_ConnectedRegionsA_temp.Dispose(); HOperatorSet.Connection(ho_RegionsA_temp, out ho_ConnectedRegionsA_temp); ho_SelectedRegionsA_temp.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegionsA_temp, out ho_SelectedRegionsA_temp, "area", "and", 108357, 495042); HOperatorSet.OrientationRegion(ho_SelectedRegionsA_temp, out hv_Phi_temp); HOperatorSet.AreaCenter(ho_SelectedRegionsA_temp, out hv_Area_temp, out hv_Row_temp, out hv_Column_temp); HOperatorSet.VectorAngleToRigid(hv_Row_temp, hv_Column_temp, hv_Phi_temp, hv_Row_temp, hv_Column_temp, (new HTuple(0)).TupleRad(), out hv_HomMat2D); ho_ImageAffineTrans.Dispose(); HOperatorSet.AffineTransImage(ho_GrayImageA, out ho_ImageAffineTrans, hv_HomMat2D, "constant", "false"); ho_RegionsA.Dispose(); HOperatorSet.Threshold(ho_ImageAffineTrans, out ho_RegionsA, 116, 218); ho_RegionDilationA.Dispose(); HOperatorSet.DilationRectangle1(ho_RegionsA, out ho_RegionDilationA, 2, 2); ho_ConnectedRegionsA.Dispose(); HOperatorSet.Connection(ho_RegionDilationA, out ho_ConnectedRegionsA); ho_SelectedRegionsA.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegionsA, out ho_SelectedRegionsA, "circularity", "and", 0.001, 0.03); ho_RegionsA1.Dispose(); HOperatorSet.Threshold(ho_GrayImageA, out ho_RegionsA1, 227, 255); ho_RegionOpeningA.Dispose(); HOperatorSet.OpeningCircle(ho_RegionsA1, out ho_RegionOpeningA, 5.5); ho_ConnectedRegionsA.Dispose(); HOperatorSet.Connection(ho_RegionOpeningA, out ho_ConnectedRegionsA); ho_SelectedRegionsA1.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegionsA, out ho_SelectedRegionsA1, "row", "and", 513.2, 601.23); ho_RegionUnionA.Dispose(); HOperatorSet.Union1(ho_SelectedRegionsA1, out ho_RegionUnionA); HOperatorSet.SmallestRectangle1(ho_RegionUnionA, out hv_RowA1, out hv_ColumnA1, out hv_RowA2, out hv_ColumnA2); ho_SelectedRegionsA2.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegionsA, out ho_SelectedRegionsA2, "width", "and", 92.694, 100); HOperatorSet.InnerRectangle1(ho_SelectedRegionsA2, out hv_RowA3, out hv_ColumnA3, out hv_RowA4, out hv_ColumnA4); ho_ConnectedRegionsA.Dispose(); HOperatorSet.Connection(ho_RegionsA1, out ho_ConnectedRegionsA); //*******************************************第三组预处理********************************************* ho_RegionsB.Dispose(); HOperatorSet.Threshold(ho_Image, out ho_RegionsB, 131, 153); ho_ConnectedRegionsB.Dispose(); HOperatorSet.Connection(ho_RegionsB, out ho_ConnectedRegionsB); ho_SelectedRegionsB.Dispose(); HOperatorSet.SelectShapeStd(ho_ConnectedRegionsB, out ho_SelectedRegionsB, "max_area", 70); HOperatorSet.SmallestRectangle2(ho_SelectedRegionsB, out hv_RowB16, out hv_ColumnB16, out hv_PhiB3, out hv_LengthB1, out hv_LengthB2); ho_RectangleB1.Dispose(); HOperatorSet.GenRectangle2(out ho_RectangleB1, hv_RowB16 - 5, hv_ColumnB16, hv_PhiB3, hv_LengthB1 - 5, hv_LengthB2 - 5); ho_RectangleB2.Dispose(); HOperatorSet.GenRectangle2(out ho_RectangleB2, hv_RowB16 - 3, hv_ColumnB16, hv_PhiB3, hv_LengthB1 - 5, hv_LengthB2 - 18); ho_RegionDifferenceB.Dispose(); HOperatorSet.Difference(ho_RectangleB1, ho_RectangleB2, out ho_RegionDifferenceB ); ho_ImageReducedB1.Dispose(); HOperatorSet.ReduceDomain(ho_Image, ho_RegionDifferenceB, out ho_ImageReducedB1 ); ho_RegionB1.Dispose(); HOperatorSet.Threshold(ho_ImageReducedB1, out ho_RegionB1, 200, 255); ho_ConnectedRegionsB2.Dispose(); HOperatorSet.Connection(ho_RegionB1, out ho_ConnectedRegionsB2); ho_SelectedRegionsB2.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegionsB2, out ho_SelectedRegionsB2, "area", "and", 26.01, 200); HOperatorSet.AreaCenter(ho_SelectedRegionsB2, out hv_AreaB, out hv_RowB2, out hv_ColumnB2); //*****************************************花瓣ABC************************************************** //边缘轮廓检测 ho_outContours.Dispose(); HOperatorSet.GenContourRegionXld(ho_SelectedRegions3, out ho_outContours, "border"); ho_SelectedContours.Dispose(); HOperatorSet.SelectContoursXld(ho_outContours, out ho_SelectedContours, "contour_length", 60, 600, -0.5, 0.5); ho_SortedContours.Dispose(); HOperatorSet.SortContoursXld(ho_SelectedContours, out ho_SortedContours, "upper_left", "true", "column"); HOperatorSet.CountObj(ho_SortedContours, out hv_Number); //中心轮廓检测 ho_Region1.Dispose(); HOperatorSet.Threshold(ho_ImageReduced, out ho_Region1, 0, 135); ho_ConnectedRegions1.Dispose(); HOperatorSet.Connection(ho_Region1, out ho_ConnectedRegions1); ho_SelectedRegions4.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions1, out ho_SelectedRegions4, "area", "and", 230, 600); ho_SelectedRegions5.Dispose(); HOperatorSet.SelectShape(ho_SelectedRegions4, out ho_SelectedRegions5, "ratio", "and", 0.7, 1.352); ho_SelectedRegions6.Dispose(); HOperatorSet.SelectShape(ho_SelectedRegions5, out ho_SelectedRegions6, "circularity", "and", 0.2, 1); ho_Contours.Dispose(); HOperatorSet.GenContourRegionXld(ho_SelectedRegions6, out ho_Contours, "border"); ho_SortedContours3.Dispose(); HOperatorSet.SortContoursXld(ho_Contours, out ho_SortedContours3, "upper_left", "true", "row"); HOperatorSet.CountObj(ho_SortedContours3, out hv_Number3); if ((int)(new HTuple((((hv_Number + hv_Number3) % 2)).TupleEqual(1))) != 0) { //这里需要在C#输出无法检测的信息 HDevelopStop(); } //里面的轮廓 A1左上到右下 A2左下到右上 hv_A1 = new HTuple(); hv_A2 = new HTuple(); //外面的轮廓 B1垂直方向 B2水平方向 hv_B1 = new HTuple(); hv_B2 = new HTuple(); //c1到c4顺时针顺序的四个花瓣长度 hv_C1 = new HTuple(); hv_C2 = new HTuple(); hv_C3 = new HTuple(); hv_C4 = new HTuple(); //B的检测 HTuple end_val103 = hv_Number; HTuple step_val103 = 1; for (hv_i = 1; hv_i.Continue(end_val103, step_val103); hv_i = hv_i.TupleAdd(step_val103)) { ho_obj.Dispose(); HOperatorSet.SelectObj(ho_SortedContours, out ho_obj, hv_i); HOperatorSet.GetContourXld(ho_obj, out hv_Ro1, out hv_Co1); HOperatorSet.TupleMin(hv_Ro1, out hv_MinBR); HOperatorSet.TupleMax(hv_Ro1, out hv_MaxBR); HOperatorSet.TupleMin(hv_Co1, out hv_MinBC); HOperatorSet.TupleMax(hv_Co1, out hv_MaxBC); hv_BR = hv_MaxBR - hv_MinBR; hv_BC = hv_MaxBC - hv_MinBC; hv_B1 = hv_B1.TupleConcat(hv_BR); hv_B2 = hv_B2.TupleConcat(hv_BC); //A的检测 HTuple end_val118 = hv_Number3; HTuple step_val118 = 1; for (hv_j = 1; hv_j.Continue(end_val118, step_val118); hv_j = hv_j.TupleAdd(step_val118)) { if ((int)(new HTuple(hv_i.TupleEqual(hv_j))) != 0) { ho_objj.Dispose(); HOperatorSet.SelectObj(ho_SortedContours3, out ho_objj, hv_j); //C的检测 ho_ContoursSplit.Dispose(); HOperatorSet.SegmentContoursXld(ho_objj, out ho_ContoursSplit, "lines", 5, 4, 2); ho_SelectedXLD.Dispose(); HOperatorSet.SelectShapeXld(ho_ContoursSplit, out ho_SelectedXLD, "width", "and", 13, 99); ho_SortedContours1.Dispose(); HOperatorSet.SortContoursXld(ho_SelectedXLD, out ho_SortedContours1, "upper_left", "true", "row"); HOperatorSet.CountObj(ho_SortedContours1, out hv_Number1); HTuple end_val130 = hv_Number1; HTuple step_val130 = 1; for (hv_a = 1; hv_a.Continue(end_val130, step_val130); hv_a = hv_a.TupleAdd(step_val130)) { ho_M.Dispose(); HOperatorSet.SelectObj(ho_SortedContours1, out ho_M, hv_a); if ((int)(new HTuple(hv_a.TupleEqual(1))) != 0) { HOperatorSet.GetContourXld(ho_M, out hv_Ro2, out hv_Co2); HOperatorSet.TupleMin(hv_Co2, out hv_LUC); HOperatorSet.TupleMax(hv_Co2, out hv_RUC); } else { HOperatorSet.GetContourXld(ho_M, out hv_Ro3, out hv_Co3); HOperatorSet.TupleMin(hv_Co3, out hv_LDC); HOperatorSet.TupleMax(hv_Co3, out hv_RDC); } HOperatorSet.FitLineContourXld(ho_M, "huber", -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); ho_Contour.Dispose(); HOperatorSet.GenContourPolygonXld(out ho_Contour, hv_RowBegin.TupleConcat( hv_RowEnd), hv_ColBegin.TupleConcat(hv_ColEnd)); HOperatorSet.GetContourXld(ho_Contour, out hv_Rowc, out hv_Colc); HOperatorSet.TupleMean(hv_Rowc, out hv_MeanR); if ((int)(new HTuple(hv_a.TupleEqual(1))) != 0) { hv_H1 = hv_MeanR - hv_MinBR; hv_C1 = hv_C1.TupleConcat(hv_H1); } else { hv_H3 = hv_MaxBR - hv_MeanR; hv_C3 = hv_C3.TupleConcat(hv_H3); } } ho_SelectedXLD1.Dispose(); HOperatorSet.SelectShapeXld(ho_ContoursSplit, out ho_SelectedXLD1, "height", "and", 13, 99); ho_SortedContours2.Dispose(); HOperatorSet.SortContoursXld(ho_SelectedXLD1, out ho_SortedContours2, "upper_left", "true", "column"); HOperatorSet.CountObj(ho_SortedContours2, out hv_Number2); HTuple end_val157 = hv_Number2; HTuple step_val157 = 1; for (hv_b = 1; hv_b.Continue(end_val157, step_val157); hv_b = hv_b.TupleAdd(step_val157)) { ho_M.Dispose(); HOperatorSet.SelectObj(ho_SortedContours2, out ho_M, hv_b); if ((int)(new HTuple(hv_b.TupleEqual(1))) != 0) { HOperatorSet.GetContourXld(ho_M, out hv_Ro4, out hv_Co4); HOperatorSet.TupleMin(hv_Ro4, out hv_LUR); HOperatorSet.TupleMax(hv_Ro4, out hv_LDR); } else { HOperatorSet.GetContourXld(ho_M, out hv_Ro5, out hv_Co5); HOperatorSet.TupleMin(hv_Ro5, out hv_RUR); HOperatorSet.TupleMax(hv_Ro5, out hv_RDR); } HOperatorSet.FitLineContourXld(ho_M, "huber", -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); ho_Contour.Dispose(); HOperatorSet.GenContourPolygonXld(out ho_Contour, hv_RowBegin.TupleConcat( hv_RowEnd), hv_ColBegin.TupleConcat(hv_ColEnd)); HOperatorSet.GetContourXld(ho_Contour, out hv_Rowc, out hv_Colc); HOperatorSet.TupleMean(hv_Colc, out hv_MeanC); if ((int)(new HTuple(hv_b.TupleEqual(1))) != 0) { hv_H4 = hv_MeanC - hv_MinBC; hv_C4 = hv_C4.TupleConcat(hv_H4); } else { hv_H2 = hv_MaxBC - hv_MeanC; hv_C2 = hv_C2.TupleConcat(hv_H2); } } HOperatorSet.DistancePp(hv_LUC, hv_LUR, hv_RDC, hv_RDR, out hv_Distance1); HOperatorSet.DistancePp(hv_RUC, hv_RUR, hv_LDC, hv_LDR, out hv_Distance2); hv_A1 = hv_A1.TupleConcat(hv_Distance1); hv_A2 = hv_A2.TupleConcat(hv_Distance2); } } } //*********************************倾斜角度 跑针位 k******************************************* HOperatorSet.AreaCenter(ho_SelectedRegionsA, out hv_AreaA, out hv_RowA, out hv_ColumnA); HOperatorSet.OrientationRegion(ho_SelectedRegionsA, out hv_Phi); hv_Phi = hv_Phi.TupleDeg(); hv_phi = ((90 - (hv_Phi.TupleAbs()))).TupleAbs(); hv_paozhengwei = (hv_RowA3 - ((hv_RowA2 / 2) + (hv_RowA1 / 2))) - 4; hv_k = (hv_RowA2 - hv_RowA1) + 4; //***************************************裂箔**************************************************** HOperatorSet.TupleSortIndex(hv_AreaB, out hv_Indices); hv_liebo = new HTuple(); hv_NumB = new HTuple(hv_Indices.TupleLength()); hv_count = 0; if ((int)(new HTuple(hv_NumB.TupleGreater(0))) != 0) { HTuple end_val208 = hv_NumB; HTuple step_val208 = 1; for (hv_I = 1; hv_I.Continue(end_val208, step_val208); hv_I = hv_I.TupleAdd(step_val208)) { ho_ObjectSelectedB.Dispose(); HOperatorSet.SelectObj(ho_SelectedRegionsB2, out ho_ObjectSelectedB, hv_I); HOperatorSet.AreaCenter(ho_ObjectSelectedB, out hv_AreaB1, out hv_RowB3, out hv_ColumnB3); if ((int)(new HTuple(hv_AreaB1.TupleGreater(30))) != 0) { hv_count = hv_count + 1; } else { } } } else { } if (hv_liebo == null) { hv_liebo = new HTuple(); } hv_liebo[0] = hv_count; HTuple result = new HTuple(); result.Append(hv_A1[0]); result.Append(hv_A2[0]); result.Append(hv_B1[0]); result.Append(hv_B2[0]); result.Append(hv_C1[0]); result.Append(hv_C2[0]); result.Append(hv_C3[0]); result.Append(hv_C4[0]); result.Append(hv_phi[0]); result.Append(hv_paozhengwei[0]); result.Append(hv_liebo[0]); //************************************************************************************************** ho_Image.Dispose(); ho_ImageRotate.Dispose(); ho_GrayImage.Dispose(); ho_ImageMedian.Dispose(); ho_Region.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions.Dispose(); ho_SelectedRegions2.Dispose(); ho_SelectedRegions1.Dispose(); ho_SelectedRegions3.Dispose(); ho_SortedRegions.Dispose(); ho_RegionUnion.Dispose(); ho_Rectangle.Dispose(); ho_ImageReduced.Dispose(); ho_GrayImageA.Dispose(); ho_GragImageA.Dispose(); ho_RegionsA_temp.Dispose(); ho_ConnectedRegionsA_temp.Dispose(); ho_SelectedRegionsA_temp.Dispose(); ho_ImageAffineTrans.Dispose(); ho_RegionsA.Dispose(); ho_RegionDilationA.Dispose(); ho_ConnectedRegionsA.Dispose(); ho_SelectedRegionsA.Dispose(); ho_RegionsA1.Dispose(); ho_RegionOpeningA.Dispose(); ho_SelectedRegionsA1.Dispose(); ho_RegionUnionA.Dispose(); ho_SelectedRegionsA2.Dispose(); ho_RegionsB.Dispose(); ho_ConnectedRegionsB.Dispose(); ho_SelectedRegionsB.Dispose(); ho_RectangleB1.Dispose(); ho_RectangleB2.Dispose(); ho_RegionDifferenceB.Dispose(); ho_ImageReducedB1.Dispose(); ho_RegionB1.Dispose(); ho_ConnectedRegionsB2.Dispose(); ho_SelectedRegionsB2.Dispose(); ho_outContours.Dispose(); ho_SelectedContours.Dispose(); ho_SortedContours.Dispose(); ho_Region1.Dispose(); ho_ConnectedRegions1.Dispose(); ho_SelectedRegions4.Dispose(); ho_SelectedRegions5.Dispose(); ho_SelectedRegions6.Dispose(); ho_Contours.Dispose(); ho_SortedContours3.Dispose(); ho_obj.Dispose(); ho_objj.Dispose(); ho_ContoursSplit.Dispose(); ho_SelectedXLD.Dispose(); ho_SortedContours1.Dispose(); ho_M.Dispose(); ho_Contour.Dispose(); ho_SelectedXLD1.Dispose(); ho_SortedContours2.Dispose(); ho_ObjectSelectedB.Dispose(); return(result); }
private void action() { // Stack for temporary objects HObject[] OTemp = new HObject[20]; // Local iconic variables HObject ho_Circley1, ho_Rectanglet; HObject ho_Region1, ho_Region2, ho_RegionDifference, ho_ImageReduced; HObject ho_Region, ho_ConnectedRegions, ho_SelectedRegions; HObject ho_RegionDilation, ho_RegionUnion, ho_RegionErosion; HObject ho_Skeleton, ho_RegionAffineTrans = null, ho_RegionDifference1 = null; HObject ho_RegionDilation1 = null, ho_ConnectedRegions1 = null; HObject ho_ImageAffinTrans = null, ho_ImageReduced1 = null; HObject ho_ImageMean = null, ho_RegionDynThresh = null, ho_ConnectedRegions2 = null; HObject ho_SelectedRegions1 = null, ho_RegionDilation2 = null; HObject ho_RegionUnion1 = null, ho_Circle = null, ho_RegionDifference2 = null; HObject ho_RegionTrans = null, ho_Circle1 = null, ho_RegionDilation3 = null; HObject ho_Region3 = null, ho_RegionDifference3 = null, ho_RegionDifference4 = null; HObject ho_RegionErosion1 = null, ho_ConnectedRegions3 = null; HObject ho_SelectedRegions2 = null; // Local control variables HTuple hv_m = null, hv_n = null, hv_Phi = null, hv_Row = null; HTuple hv_Column = null, hv_Angle = null, hv_Score = null; HTuple hv_HomMat2D = new HTuple(), hv_Number = new HTuple(); HTuple hv_HomMat2D1 = new HTuple(), hv_Row1 = new HTuple(); HTuple hv_Column1 = new HTuple(), hv_Radius = new HTuple(); HTuple hv_Row2 = new HTuple(), hv_Column2 = new HTuple(); HTuple hv_Radius1 = new HTuple(), hv_Area = new HTuple(); HTuple hv_Row3 = new HTuple(), hv_Column3 = new HTuple(); HTuple hv_HomMat2D2 = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Circley1); HOperatorSet.GenEmptyObj(out ho_Rectanglet); HOperatorSet.GenEmptyObj(out ho_Region1); HOperatorSet.GenEmptyObj(out ho_Region2); HOperatorSet.GenEmptyObj(out ho_RegionDifference); HOperatorSet.GenEmptyObj(out ho_ImageReduced); HOperatorSet.GenEmptyObj(out ho_Region); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions); HOperatorSet.GenEmptyObj(out ho_SelectedRegions); HOperatorSet.GenEmptyObj(out ho_RegionDilation); HOperatorSet.GenEmptyObj(out ho_RegionUnion); HOperatorSet.GenEmptyObj(out ho_RegionErosion); HOperatorSet.GenEmptyObj(out ho_Skeleton); HOperatorSet.GenEmptyObj(out ho_RegionAffineTrans); HOperatorSet.GenEmptyObj(out ho_RegionDifference1); HOperatorSet.GenEmptyObj(out ho_RegionDilation1); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions1); HOperatorSet.GenEmptyObj(out ho_ImageAffinTrans); HOperatorSet.GenEmptyObj(out ho_ImageReduced1); HOperatorSet.GenEmptyObj(out ho_ImageMean); HOperatorSet.GenEmptyObj(out ho_RegionDynThresh); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions2); HOperatorSet.GenEmptyObj(out ho_SelectedRegions1); HOperatorSet.GenEmptyObj(out ho_RegionDilation2); HOperatorSet.GenEmptyObj(out ho_RegionUnion1); HOperatorSet.GenEmptyObj(out ho_Circle); HOperatorSet.GenEmptyObj(out ho_RegionDifference2); HOperatorSet.GenEmptyObj(out ho_RegionTrans); HOperatorSet.GenEmptyObj(out ho_Circle1); HOperatorSet.GenEmptyObj(out ho_RegionDilation3); HOperatorSet.GenEmptyObj(out ho_Region3); HOperatorSet.GenEmptyObj(out ho_RegionDifference3); HOperatorSet.GenEmptyObj(out ho_RegionDifference4); HOperatorSet.GenEmptyObj(out ho_RegionErosion1); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions3); HOperatorSet.GenEmptyObj(out ho_SelectedRegions2); HOperatorSet.Union1(algorithm.Region, out RegionToDisp); try { hv_m = 0; hv_n = 0; ho_Region1.Dispose(); HOperatorSet.GenRegionPoints(out ho_Region1, DRowy, DColumny); ho_Region2.Dispose(); HOperatorSet.GenRegionPoints(out ho_Region2, DRowy, DColumny); ho_Circley1.Dispose(); HOperatorSet.GenCircle(out ho_Circley1, DRowy, DColumny, DPhiy); ho_Rectanglet.Dispose(); HOperatorSet.GenRectangle2(out ho_Rectanglet, DRows, DColumns, DPhis, DLength1s, DLength2s); HOperatorSet.ReadShapeModel(PathHelper.currentProductPath + @"\nbquekoudj1.shm", out hv_ModelID); ho_RegionDifference.Dispose(); HOperatorSet.Difference(ho_Circley1, ho_Rectanglet, out ho_RegionDifference); ho_ImageReduced.Dispose(); HOperatorSet.ReduceDomain(Image, ho_Circley1, out ho_ImageReduced); ho_Region.Dispose(); HOperatorSet.Threshold(ho_ImageReduced, out ho_Region, thv, 255); ho_ConnectedRegions.Dispose(); HOperatorSet.Connection(ho_Region, out ho_ConnectedRegions); ho_SelectedRegions.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, ((new HTuple("width")).TupleConcat( "height")).TupleConcat("area"), "and", (((new HTuple(this.kdz).TupleConcat(this.kdz))).TupleConcat( 100)), ((new HTuple(this.DPhiy * 2 - 10)).TupleConcat(this.DPhiy * 2 - 10)).TupleConcat(mjsx)); ho_RegionDilation.Dispose(); HOperatorSet.DilationCircle(ho_SelectedRegions, out ho_RegionDilation, 5.5); ho_RegionUnion.Dispose(); HOperatorSet.Union2(ho_RegionDilation, ho_RegionDilation, out ho_RegionUnion); ho_RegionErosion.Dispose(); HOperatorSet.ErosionCircle(ho_RegionUnion, out ho_RegionErosion, 3.5); ho_Skeleton.Dispose(); HOperatorSet.Skeleton(ho_RegionErosion, out ho_Skeleton); HOperatorSet.OrientationRegion(ho_Skeleton, out hv_Phi); HOperatorSet.FindShapeModel(Image, hv_ModelID, -3.14, 3.15, 0.3, 1, 0.5, "least_squares", 0, 0.9, out hv_Row, out hv_Column, out hv_Angle, out hv_Score); if ((int)(new HTuple((new HTuple(hv_Score.TupleLength())).TupleEqual(1))) != 0) { HOperatorSet.VectorAngleToRigid(hv_Row, hv_Column, hv_Phi - DPhi1m, DRow1s, DColumn1s, 0, out hv_HomMat2D); ho_RegionAffineTrans.Dispose(); HOperatorSet.AffineTransRegion(ho_Skeleton, out ho_RegionAffineTrans, hv_HomMat2D, "nearest_neighbor"); ho_RegionDifference1.Dispose(); HOperatorSet.Difference(ho_RegionAffineTrans, ho_Rectanglet, out ho_RegionDifference1 ); ho_RegionDilation1.Dispose(); HOperatorSet.DilationCircle(ho_RegionDifference1, out ho_RegionDilation1, 3.5); ho_ConnectedRegions1.Dispose(); HOperatorSet.Connection(ho_RegionDilation1, out ho_ConnectedRegions1); HOperatorSet.CountObj(ho_ConnectedRegions1, out hv_Number); if ((int)(new HTuple(hv_Number.TupleEqual(1))) != 0) { ho_ImageAffinTrans.Dispose(); HOperatorSet.AffineTransImage(Image, out ho_ImageAffinTrans, hv_HomMat2D, "constant", "false"); } else if ((int)(new HTuple(hv_Number.TupleEqual(2))) != 0) { HOperatorSet.VectorAngleToRigid(hv_Row, hv_Column, (hv_Phi - DPhi1m) + 3.14, DRow1s, DColumn1s, 0, out hv_HomMat2D1); ho_ImageAffinTrans.Dispose(); HOperatorSet.AffineTransImage(Image, out ho_ImageAffinTrans, hv_HomMat2D1, "constant", "false"); } ho_ImageReduced1.Dispose(); HOperatorSet.ReduceDomain(ho_ImageAffinTrans, ho_RegionDifference, out ho_ImageReduced1 ); ho_ImageMean.Dispose(); HOperatorSet.MeanImage(ho_ImageReduced1, out ho_ImageMean, this.yd, this.yd); ho_RegionDynThresh.Dispose(); HOperatorSet.DynThreshold(ho_ImageReduced1, ho_ImageMean, out ho_RegionDynThresh, this.bjz, "dark"); ho_ConnectedRegions2.Dispose(); HOperatorSet.Connection(ho_RegionDynThresh, out ho_ConnectedRegions2); ho_SelectedRegions1.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions2, out ho_SelectedRegions1, (new HTuple("width")).TupleConcat( "height"), "and", new HTuple(this.kdz).TupleConcat(new HTuple(this.kdz)), (new HTuple(999999999)).TupleConcat( 9999999)); ho_RegionDilation2.Dispose(); HOperatorSet.DilationCircle(ho_SelectedRegions1, out ho_RegionDilation2, 1.5); ho_RegionUnion1.Dispose(); HOperatorSet.Union1(ho_RegionDilation2, out ho_RegionUnion1); HOperatorSet.SmallestCircle(ho_RegionUnion1, out hv_Row1, out hv_Column1, out hv_Radius); ho_Circle.Dispose(); HOperatorSet.GenCircle(out ho_Circle, hv_Row1, hv_Column1, hv_Radius); ho_RegionDifference2.Dispose(); HOperatorSet.Difference(ho_Circle, ho_RegionUnion1, out ho_RegionDifference2 ); ho_RegionTrans.Dispose(); HOperatorSet.ShapeTrans(ho_RegionDifference2, out ho_RegionTrans, "inner_circle"); HOperatorSet.SmallestCircle(ho_RegionTrans, out hv_Row2, out hv_Column2, out hv_Radius1); ho_Circle1.Dispose(); HOperatorSet.GenCircle(out ho_Circle1, hv_Row2, hv_Column2, hv_Radius1); { HObject ExpTmpOutVar_0; HOperatorSet.Union2(ho_Region2, ho_Circle1, out ExpTmpOutVar_0); ho_Region2.Dispose(); ho_Region2 = ExpTmpOutVar_0; } ho_RegionDilation3.Dispose(); HOperatorSet.DilationCircle(ho_RegionTrans, out ho_RegionDilation3, 10.5); ho_Region3.Dispose(); HOperatorSet.Threshold(ho_ImageReduced1, out ho_Region3, 0, this.cd); ho_RegionDifference3.Dispose(); HOperatorSet.Difference(ho_Region3, ho_RegionDilation3, out ho_RegionDifference3 ); ho_RegionDifference4.Dispose(); HOperatorSet.Difference(ho_RegionDifference3, ho_RegionDilation2, out ho_RegionDifference4 ); ho_RegionErosion1.Dispose(); HOperatorSet.ErosionCircle(ho_RegionDifference4, out ho_RegionErosion1, this.pzz); ho_ConnectedRegions3.Dispose(); HOperatorSet.Connection(ho_RegionErosion1, out ho_ConnectedRegions3); ho_SelectedRegions2.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions3, out ho_SelectedRegions2, "area", "and", this.mj, 99999999); HOperatorSet.AreaCenter(ho_SelectedRegions2, out hv_Area, out hv_Row3, out hv_Column3); if ((int)(new HTuple((new HTuple(hv_Area.TupleLength())).TupleGreater(0))) != 0) { { HObject ExpTmpOutVar_0; HOperatorSet.Union2(ho_Region2, ho_SelectedRegions2, out ExpTmpOutVar_0); ho_Region2.Dispose(); ho_Region2 = ExpTmpOutVar_0; } hv_m = hv_Area.TupleSum(); hv_n = hv_Area.TupleMax(); } else { hv_m = 0; hv_n = 0; } if ((int)(new HTuple(hv_Number.TupleEqual(1))) != 0) { HOperatorSet.VectorAngleToRigid(DRow1s, DColumn1s, 0, hv_Row, hv_Column, hv_Phi - DPhi1m, out hv_HomMat2D2); } else if ((int)(new HTuple(hv_Number.TupleEqual(2))) != 0) { HOperatorSet.VectorAngleToRigid(DRow1s, DColumn1s, 0, hv_Row, hv_Column, (hv_Phi - DPhi1m) + 3.14, out hv_HomMat2D2); } ho_RegionAffineTrans.Dispose(); HOperatorSet.AffineTransRegion(ho_Region2, out ho_RegionAffineTrans, hv_HomMat2D2, "nearest_neighbor"); { HObject ExpTmpOutVar_0; HOperatorSet.Union2(ho_Region1, ho_RegionAffineTrans, out ExpTmpOutVar_0); ho_Region1.Dispose(); ho_Region1 = ExpTmpOutVar_0; } } HOperatorSet.ClearShapeModel(hv_ModelID); HOperatorSet.Union1(ho_Region1, out RegionToDisp); HTuple hv_result = GetHv_result(); hv_result = hv_result.TupleConcat("缺陷总面积"); hv_result = hv_result.TupleConcat(hv_m.D); hv_result = hv_result.TupleConcat("最大面积"); hv_result = hv_result.TupleConcat(hv_n.D); hv_result = hv_result.TupleConcat("内径"); hv_result = hv_result.TupleConcat(hv_Radius1.D * 2 * pixeldist); result = hv_result.Clone(); ho_Circley1.Dispose(); ho_Rectanglet.Dispose(); ho_Region1.Dispose(); ho_Region2.Dispose(); ho_RegionDifference.Dispose(); ho_ImageReduced.Dispose(); ho_Region.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions.Dispose(); ho_RegionDilation.Dispose(); ho_RegionUnion.Dispose(); ho_RegionErosion.Dispose(); ho_Skeleton.Dispose(); ho_RegionAffineTrans.Dispose(); ho_RegionDifference1.Dispose(); ho_RegionDilation1.Dispose(); ho_ConnectedRegions1.Dispose(); ho_ImageAffinTrans.Dispose(); ho_ImageReduced1.Dispose(); ho_ImageMean.Dispose(); ho_RegionDynThresh.Dispose(); ho_ConnectedRegions2.Dispose(); ho_SelectedRegions1.Dispose(); ho_RegionDilation2.Dispose(); ho_RegionUnion1.Dispose(); ho_Circle.Dispose(); ho_RegionDifference2.Dispose(); ho_RegionTrans.Dispose(); ho_Circle1.Dispose(); ho_RegionDilation3.Dispose(); ho_Region3.Dispose(); ho_RegionDifference3.Dispose(); ho_RegionDifference4.Dispose(); ho_RegionErosion1.Dispose(); ho_ConnectedRegions3.Dispose(); ho_SelectedRegions2.Dispose(); algorithm.Region.Dispose(); } catch { HTuple hv_result = GetHv_result(); 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(0); result = hv_result.Clone(); ho_Circley1.Dispose(); ho_Rectanglet.Dispose(); ho_Region1.Dispose(); ho_Region2.Dispose(); ho_RegionDifference.Dispose(); ho_ImageReduced.Dispose(); ho_Region.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions.Dispose(); ho_RegionDilation.Dispose(); ho_RegionUnion.Dispose(); ho_RegionErosion.Dispose(); ho_Skeleton.Dispose(); ho_RegionAffineTrans.Dispose(); ho_RegionDifference1.Dispose(); ho_RegionDilation1.Dispose(); ho_ConnectedRegions1.Dispose(); ho_ImageAffinTrans.Dispose(); ho_ImageReduced1.Dispose(); ho_ImageMean.Dispose(); ho_RegionDynThresh.Dispose(); ho_ConnectedRegions2.Dispose(); ho_SelectedRegions1.Dispose(); ho_RegionDilation2.Dispose(); ho_RegionUnion1.Dispose(); ho_Circle.Dispose(); ho_RegionDifference2.Dispose(); ho_RegionTrans.Dispose(); ho_Circle1.Dispose(); ho_RegionDilation3.Dispose(); ho_Region3.Dispose(); ho_RegionDifference3.Dispose(); ho_RegionDifference4.Dispose(); ho_RegionErosion1.Dispose(); ho_ConnectedRegions3.Dispose(); ho_SelectedRegions2.Dispose(); algorithm.Region.Dispose(); } finally { ho_Circley1.Dispose(); ho_Rectanglet.Dispose(); ho_Region1.Dispose(); ho_Region2.Dispose(); ho_RegionDifference.Dispose(); ho_ImageReduced.Dispose(); ho_Region.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions.Dispose(); ho_RegionDilation.Dispose(); ho_RegionUnion.Dispose(); ho_RegionErosion.Dispose(); ho_Skeleton.Dispose(); ho_RegionAffineTrans.Dispose(); ho_RegionDifference1.Dispose(); ho_RegionDilation1.Dispose(); ho_ConnectedRegions1.Dispose(); ho_ImageAffinTrans.Dispose(); ho_ImageReduced1.Dispose(); ho_ImageMean.Dispose(); ho_RegionDynThresh.Dispose(); ho_ConnectedRegions2.Dispose(); ho_SelectedRegions1.Dispose(); ho_RegionDilation2.Dispose(); ho_RegionUnion1.Dispose(); ho_Circle.Dispose(); ho_RegionDifference2.Dispose(); ho_RegionTrans.Dispose(); ho_Circle1.Dispose(); ho_RegionDilation3.Dispose(); ho_Region3.Dispose(); ho_RegionDifference3.Dispose(); ho_RegionDifference4.Dispose(); ho_RegionErosion1.Dispose(); ho_ConnectedRegions3.Dispose(); ho_SelectedRegions2.Dispose(); algorithm.Region.Dispose(); } }
private void FindLineBtn_Click(object sender, EventArgs e) { txtFindTime.Clear(); Stopwatch sw = new Stopwatch(); sw.Start(); if (GrabedImg == null) { Logger.PopError("请先采集图片!", true); return; } //1.0模板匹配 St_TemplateParam TemplateParam = VisionPara0.localPara.Template; RectangleF roi = new RectangleF(); LocalSettingPara Setting = VisionPara0.localPara.localSetting; roi.X = Setting.SearchAreaX; roi.Y = Setting.SearchAreaY; roi.Width = Setting.SearchWidth; roi.Height = Setting.SearchHeight; MatchingResult result; TemplateParam.FindSharpTemplate(GrabedImg, roi, TemplateParam, out result); //2.0调整图像位置 St_VectorAngle VectorAngle0 = new St_VectorAngle(VisionPara0.localPara.Template.CenterY, VisionPara0.localPara.Template.CenterX, VisionPara0.localPara.Template.TemplateAngle); St_VectorAngle TempFindVectorAngle = new St_VectorAngle(result.mRow, result.mCol, result.mAngle);//找到的模板坐标 HTuple HomMat = new HTuple(); HOperatorSet.VectorAngleToRigid(result.mRow, result.mCol, result.mAngle, VisionPara0.localPara.Template.CenterY, VisionPara0.localPara.Template.CenterX, VisionPara0.localPara.Template.TemplateAngle, out HomMat); HObject AffineImg = new HObject(); HOperatorSet.AffineTransImage(GrabedImg, out AffineImg, HomMat, "constant", "false"); HOperatorSet.ClearWindow(ShowWindow); MyVisionBase.hDispObj(ShowWindow, GrabedImg); //3.0找出Pin针坐标 HObject RoiContour = new HObject(); MyVisionBase.hDispObj(ShowWindow, AffineImg); HTuple PinRows = new HTuple(), PinCols = new HTuple(); PinInsepct.FindPinPos(TeachInspectPinParam, AffineImg, out PinRows, out PinCols); HObject ShowContour = new HObject(); HOperatorSet.GenCrossContourXld(out ShowContour, PinRows, PinCols, 50, 0); MyVisionBase.hSetColor(ShowWindow, "red"); MyVisionBase.hDispObj(ShowWindow, ShowContour); //4.0 计算出Pin针偏移量 HTuple OffSetRows = new HTuple(), OffSetCols = new HTuple(), OffSetDists = new HTuple();; PinInsepct.CalculatePinOffset(TeachInspectPinParam, PinRows, PinCols, out OffSetRows, out OffSetCols, out OffSetDists); HTuple Max = OffSetDists.TupleMax(); HTuple MaxIndex = OffSetDists.TupleFind(Max); HOperatorSet.GenCircleContourXld(out ShowContour, PinRows[MaxIndex[0].I], PinCols[MaxIndex[0].I], 50, 0, Math.PI * 2, "positive", 1.0); MyVisionBase.hSetColor(ShowWindow, "red"); MyVisionBase.hDispObj(ShowWindow, ShowContour); txtFindTime.Text = sw.ElapsedMilliseconds.ToString(); }
private void action(HTuple HDWindow_, string imgPath) { HDevWindowStack.Push(HDWindow_); // Local iconic variables HObject ho_Image, ho_DotImage, ho_Region, ho_RegionDilation; HObject ho_RegionClosing, ho_ConnectedRegions, ho_SelectedRegions; HObject ho_RegionUnion, ho_RegionClosing2, ho_ConnectedRegions2; HObject ho_SelectedRegions5, ho_RegionIntersection, ho_RegionAffineTrans1; HObject ho_rotateImage, ho_RegionDilation1, ho_RegionClosing1; HObject ho_RegionOpening, ho_ConnectedRegions1, ho_SelectedRegions1; HObject ho_RegionTrans, ho_Partitioned, ho_SelectedRegions2; HObject ho_RegionIntersection1, ho_SortedRegions1, ho_SelectedRegions3; HObject ho_RegionTrans1, ho_Partitioned1, ho_SelectedRegions4; HObject ho_RegionIntersection2, ho_SortedRegions2; // Local control variables HTuple hv_Row, hv_Column, hv_Phi, hv_Length1; HTuple hv_Length2, hv_HomMat2DIdentity, hv_HomMat2DRotate; HTuple hv_Area, hv_Row1, hv_Column1, hv_Area11, hv_Row11; HTuple hv_Column11, hv_Number1, hv_OCRHandle, hv_Chars1; HTuple hv_Confidence1, hv_Area12, hv_Row12, hv_Column12; HTuple hv_Number2, hv_Chars2, hv_Confidence2; // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Image); HOperatorSet.GenEmptyObj(out ho_DotImage); HOperatorSet.GenEmptyObj(out ho_Region); HOperatorSet.GenEmptyObj(out ho_RegionDilation); HOperatorSet.GenEmptyObj(out ho_RegionClosing); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions); HOperatorSet.GenEmptyObj(out ho_SelectedRegions); HOperatorSet.GenEmptyObj(out ho_RegionUnion); HOperatorSet.GenEmptyObj(out ho_RegionClosing2); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions2); HOperatorSet.GenEmptyObj(out ho_SelectedRegions5); HOperatorSet.GenEmptyObj(out ho_RegionIntersection); HOperatorSet.GenEmptyObj(out ho_RegionAffineTrans1); HOperatorSet.GenEmptyObj(out ho_rotateImage); HOperatorSet.GenEmptyObj(out ho_RegionDilation1); HOperatorSet.GenEmptyObj(out ho_RegionClosing1); HOperatorSet.GenEmptyObj(out ho_RegionOpening); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions1); HOperatorSet.GenEmptyObj(out ho_SelectedRegions1); HOperatorSet.GenEmptyObj(out ho_RegionTrans); HOperatorSet.GenEmptyObj(out ho_Partitioned); HOperatorSet.GenEmptyObj(out ho_SelectedRegions2); HOperatorSet.GenEmptyObj(out ho_RegionIntersection1); HOperatorSet.GenEmptyObj(out ho_SortedRegions1); HOperatorSet.GenEmptyObj(out ho_SelectedRegions3); HOperatorSet.GenEmptyObj(out ho_RegionTrans1); HOperatorSet.GenEmptyObj(out ho_Partitioned1); HOperatorSet.GenEmptyObj(out ho_SelectedRegions4); HOperatorSet.GenEmptyObj(out ho_RegionIntersection2); HOperatorSet.GenEmptyObj(out ho_SortedRegions2); ho_Image.Dispose(); HOperatorSet.ReadImage(out ho_Image, imgPath); ho_DotImage.Dispose(); HOperatorSet.DotsImage(ho_Image, out ho_DotImage, 5, "dark", 2); ho_Region.Dispose(); HOperatorSet.Threshold(ho_DotImage, out ho_Region, 110, 255); ho_RegionDilation.Dispose(); HOperatorSet.DilationCircle(ho_Region, out ho_RegionDilation, 2.5); ho_RegionClosing.Dispose(); HOperatorSet.ClosingRectangle1(ho_RegionDilation, out ho_RegionClosing, 3, 3); ho_ConnectedRegions.Dispose(); HOperatorSet.Connection(ho_RegionClosing, out ho_ConnectedRegions); ho_SelectedRegions.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, (new HTuple("width")).TupleConcat( "height"), "and", (new HTuple(15)).TupleConcat(15), (new HTuple(80)).TupleConcat( 80)); ho_RegionUnion.Dispose(); HOperatorSet.Union1(ho_SelectedRegions, out ho_RegionUnion); ho_RegionClosing2.Dispose(); HOperatorSet.ClosingRectangle1(ho_RegionUnion, out ho_RegionClosing2, 30, 20); ho_ConnectedRegions2.Dispose(); HOperatorSet.Connection(ho_RegionClosing2, out ho_ConnectedRegions2); ho_SelectedRegions5.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions2, out ho_SelectedRegions5, "area", "and", 10000, 20000); ho_RegionIntersection.Dispose(); HOperatorSet.Intersection(ho_Region, ho_SelectedRegions5, out ho_RegionIntersection ); HOperatorSet.SmallestRectangle2(ho_RegionIntersection, out hv_Row, out hv_Column, out hv_Phi, out hv_Length1, out hv_Length2); HOperatorSet.HomMat2dIdentity(out hv_HomMat2DIdentity); HOperatorSet.HomMat2dRotate(hv_HomMat2DIdentity, -hv_Phi, hv_Column, hv_Row, out hv_HomMat2DRotate); ho_RegionAffineTrans1.Dispose(); HOperatorSet.AffineTransRegion(ho_RegionIntersection, out ho_RegionAffineTrans1, hv_HomMat2DRotate, "true"); ho_rotateImage.Dispose(); HOperatorSet.AffineTransImage(ho_Image, out ho_rotateImage, hv_HomMat2DRotate, "bilinear", "false"); ho_RegionDilation1.Dispose(); HOperatorSet.DilationCircle(ho_RegionAffineTrans1, out ho_RegionDilation1, 2.5); ho_RegionClosing1.Dispose(); HOperatorSet.ClosingRectangle1(ho_RegionDilation1, out ho_RegionClosing1, 3, 3); ho_RegionOpening.Dispose(); HOperatorSet.OpeningCircle(ho_RegionClosing1, out ho_RegionOpening, 2.5); ho_ConnectedRegions1.Dispose(); HOperatorSet.Connection(ho_RegionOpening, out ho_ConnectedRegions1); HOperatorSet.AreaCenter(ho_RegionAffineTrans1, out hv_Area, out hv_Row1, out hv_Column1); ho_SelectedRegions1.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions1, out ho_SelectedRegions1, "row", "and", hv_Row1 - 30, hv_Row1); ho_RegionTrans.Dispose(); HOperatorSet.ShapeTrans(ho_SelectedRegions1, out ho_RegionTrans, "rectangle1"); ho_Partitioned.Dispose(); HOperatorSet.PartitionDynamic(ho_RegionTrans, out ho_Partitioned, 20, 20); ho_SelectedRegions2.Dispose(); HOperatorSet.SelectShape(ho_Partitioned, out ho_SelectedRegions2, "height", "and", 25, 48); ho_RegionIntersection1.Dispose(); HOperatorSet.Intersection(ho_SelectedRegions2, ho_RegionAffineTrans1, out ho_RegionIntersection1 ); ho_SortedRegions1.Dispose(); HOperatorSet.SortRegion(ho_RegionIntersection1, out ho_SortedRegions1, "first_point", "true", "column"); HOperatorSet.AreaCenter(ho_SortedRegions1, out hv_Area11, out hv_Row11, out hv_Column11); HOperatorSet.CountObj(ho_SortedRegions1, out hv_Number1); //FontFile := 'D:/github/CodeRecognition/tzb1112.omc' HOperatorSet.ReadOcrClassMlp("C:/Program Files/MVTec/HALCON-10.0/ocr/DotPrint_0-9A-Z.omc", out hv_OCRHandle); HOperatorSet.DoOcrMultiClassMlp(ho_SortedRegions1, ho_rotateImage, hv_OCRHandle, out hv_Chars1, out hv_Confidence1); ho_SelectedRegions3.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions1, out ho_SelectedRegions3, "row", "and", hv_Row1, hv_Row1 + 40); ho_RegionTrans1.Dispose(); HOperatorSet.ShapeTrans(ho_SelectedRegions3, out ho_RegionTrans1, "rectangle1"); ho_Partitioned1.Dispose(); HOperatorSet.PartitionDynamic(ho_RegionTrans1, out ho_Partitioned1, 20, 1); ho_SelectedRegions4.Dispose(); HOperatorSet.SelectShape(ho_Partitioned1, out ho_SelectedRegions4, "height", "and", 25, 48); ho_RegionIntersection2.Dispose(); HOperatorSet.Intersection(ho_SelectedRegions4, ho_RegionAffineTrans1, out ho_RegionIntersection2 ); ho_SortedRegions2.Dispose(); HOperatorSet.SortRegion(ho_RegionIntersection2, out ho_SortedRegions2, "first_point", "true", "column"); HOperatorSet.AreaCenter(ho_SortedRegions2, out hv_Area12, out hv_Row12, out hv_Column12); HOperatorSet.CountObj(ho_SortedRegions2, out hv_Number2); HOperatorSet.DoOcrMultiClassMlp(ho_SortedRegions2, ho_rotateImage, hv_OCRHandle, out hv_Chars2, out hv_Confidence2); //word := ['d'] //TrainFile := 'D:/github/CodeRecognition/tzb1112.trf' //dev_set_check ('~give_error') //delete_file (TrainFile) //dev_set_check ('~give_error') //for i := 7 to Number2 by 1 //select_obj (SortedRegions2, SingleWord, i) //append_ocr_trainf (SingleWord, rotateImage, word, TrainFile) //endfor //read_ocr_trainf_names (TrainFile, CharacterNames, CharacterCount) //trainf_ocr_class_mlp (OCRHandle, TrainFile, 200, 1, 0.01, Error, ErrorLog) //write_ocr_class_mlp (OCRHandle, FontFile) //120, 68, 147, 183, 188, 0, 0, 107, 162, 197, 138, 0, 123 //120, 68, 147, 183, 146, 202, 0, 107, 162, 197, 138, 169, 123 if (HDevWindowStack.IsOpen()) { HOperatorSet.ClearWindow(HDevWindowStack.GetActive()); } if (HDevWindowStack.IsOpen()) { HOperatorSet.DispObj(ho_Image, HDevWindowStack.GetActive()); } if (HDevWindowStack.IsOpen()) { HOperatorSet.SetColor(HDevWindowStack.GetActive(), "blue"); } if (HDevWindowStack.IsOpen()) { HOperatorSet.DispObj(ho_SortedRegions1, HDevWindowStack.GetActive()); } if (HDevWindowStack.IsOpen()) { HOperatorSet.DispObj(ho_SortedRegions2, HDevWindowStack.GetActive()); } ho_Image.Dispose(); ho_DotImage.Dispose(); ho_Region.Dispose(); ho_RegionDilation.Dispose(); ho_RegionClosing.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions.Dispose(); ho_RegionUnion.Dispose(); ho_RegionClosing2.Dispose(); ho_ConnectedRegions2.Dispose(); ho_SelectedRegions5.Dispose(); ho_RegionIntersection.Dispose(); ho_RegionAffineTrans1.Dispose(); ho_rotateImage.Dispose(); ho_RegionDilation1.Dispose(); ho_RegionClosing1.Dispose(); ho_RegionOpening.Dispose(); ho_ConnectedRegions1.Dispose(); ho_SelectedRegions1.Dispose(); ho_RegionTrans.Dispose(); ho_Partitioned.Dispose(); ho_SelectedRegions2.Dispose(); ho_RegionIntersection1.Dispose(); ho_SortedRegions1.Dispose(); ho_SelectedRegions3.Dispose(); ho_RegionTrans1.Dispose(); ho_Partitioned1.Dispose(); ho_SelectedRegions4.Dispose(); ho_RegionIntersection2.Dispose(); ho_SortedRegions2.Dispose(); //errorCounts = hv_errorCounts; RecognitionStr1 = hv_Chars1; RecognitionStr2 = hv_Chars2; }
// Main procedure private void action() { // Local iconic variables HObject ho_Image = null, ho_ImageAffinTrans = null; // Local control variables HTuple hv_WindowHandle = new HTuple(), hv_DeviceIdentifier = null; HTuple hv_Index = null, hv_DeviceName = new HTuple(), hv_DeviceVendor = new HTuple(); HTuple hv_Message = new HTuple(), hv_DeviceIndex = null; HTuple hv_DeviceHandle = new HTuple(), hv_HomMat2DIdentity = new HTuple(); HTuple hv_HomMat2DScale = new HTuple(), hv_HomMat2D = new HTuple(); HTuple hv_Loops = new HTuple(), hv_Before = new HTuple(); HTuple hv_After = new HTuple(), hv_TimeGPU = new HTuple(); HTuple hv_Grayval = new HTuple(), hv_Pointer = new HTuple(); HTuple hv_Type = new HTuple(), hv_Width = new HTuple(); HTuple hv_Height = new HTuple(), hv_TimeGPUinclTransfer = new HTuple(); HTuple hv_TimeCPU = new HTuple(), hv_SpeedUp = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Image); HOperatorSet.GenEmptyObj(out ho_ImageAffinTrans); try { //This example shows how to use compute devices with HALCON. // dev_update_off(); //dev_close_window(...); dev_open_window_fit_size(0, 0, 640, 480, -1, -1, out hv_WindowHandle); set_display_font(hv_ExpDefaultWinHandle, 16, "mono", "true", "false"); // //Get list of all available compute devices. HOperatorSet.QueryAvailableComputeDevices(out hv_DeviceIdentifier); // //End example if no device could be found. if ((int)(new HTuple((new HTuple(hv_DeviceIdentifier.TupleLength())).TupleEqual( 0))) != 0) { ho_Image.Dispose(); ho_ImageAffinTrans.Dispose(); return; } // //Display basic information on detected devices. disp_message(hv_ExpDefaultWinHandle, new HTuple(new HTuple("Found ") + (new HTuple(hv_DeviceIdentifier.TupleLength() ))) + " Compute Device(s):", "window", 12, 12, "black", "true"); for (hv_Index = 0; (int)hv_Index <= (int)((new HTuple(hv_DeviceIdentifier.TupleLength() )) - 1); hv_Index = (int)hv_Index + 1) { HOperatorSet.GetComputeDeviceInfo(hv_DeviceIdentifier.TupleSelect(hv_Index), "name", out hv_DeviceName); HOperatorSet.GetComputeDeviceInfo(hv_DeviceIdentifier.TupleSelect(hv_Index), "vendor", out hv_DeviceVendor); if (hv_Message == null) { hv_Message = new HTuple(); } hv_Message[hv_Index] = (((("Device #" + hv_Index) + ": ") + hv_DeviceVendor) + " ") + hv_DeviceName; } disp_message(hv_ExpDefaultWinHandle, hv_Message, "window", 42, 12, "white", "false"); disp_continue_message(hv_ExpDefaultWinHandle, "black", "true"); HDevelopStop(); // //Perform a small benchmark for all devices. for (hv_DeviceIndex = 0; (int)hv_DeviceIndex <= (int)((new HTuple(hv_DeviceIdentifier.TupleLength() )) - 1); hv_DeviceIndex = (int)hv_DeviceIndex + 1) { HOperatorSet.ClearWindow(hv_ExpDefaultWinHandle); disp_message(hv_ExpDefaultWinHandle, ("Activating Device #" + hv_DeviceIndex) + " and performing benchmark...", "window", 12, 12, "black", "true"); //Open device. HOperatorSet.OpenComputeDevice(hv_DeviceIdentifier.TupleSelect(hv_DeviceIndex), out hv_DeviceHandle); //Deactivate asynchronous execution to obtain reliable benchmarks. HOperatorSet.SetComputeDeviceParam(hv_DeviceHandle, "asynchronous_execution", "false"); //Call affine_trans_image on this device and measure the obtained speed-up. //Activate the compute device and perform the initialization of affine_trans_image. //If this is omitted, the initialization is performed with the first //call of affine_trans_image. HOperatorSet.InitComputeDevice(hv_DeviceHandle, "affine_trans_image"); HOperatorSet.ActivateComputeDevice(hv_DeviceHandle); //create benchmark input data ho_Image.Dispose(); HOperatorSet.ReadImage(out ho_Image, "rings_and_nuts"); HOperatorSet.HomMat2dIdentity(out hv_HomMat2DIdentity); HOperatorSet.HomMat2dScale(hv_HomMat2DIdentity, 0.9, 0.9, 320, 240, out hv_HomMat2DScale); HOperatorSet.HomMat2dRotate(hv_HomMat2DScale, 0.78, 320, 240, out hv_HomMat2D); //Set number of benchmark loops. hv_Loops = 200; //One call to fill caches. ho_ImageAffinTrans.Dispose(); HOperatorSet.AffineTransImage(ho_Image, out ho_ImageAffinTrans, hv_HomMat2D, "constant", "false"); HOperatorSet.CountSeconds(out hv_Before); HTuple end_val50 = hv_Loops; HTuple step_val50 = 1; for (hv_Index = 1; hv_Index.Continue(end_val50, step_val50); hv_Index = hv_Index.TupleAdd(step_val50)) { ho_ImageAffinTrans.Dispose(); HOperatorSet.AffineTransImage(ho_Image, out ho_ImageAffinTrans, hv_HomMat2D, "constant", "false"); } HOperatorSet.CountSeconds(out hv_After); hv_TimeGPU = ((hv_After - hv_Before) * 1000.0) / hv_Loops; // //Perform a slightly modified version of this benchmark to include //host->device and device->host transfer. HOperatorSet.GetGrayval(ho_Image, 0, 0, out hv_Grayval); ho_ImageAffinTrans.Dispose(); HOperatorSet.AffineTransImage(ho_Image, out ho_ImageAffinTrans, hv_HomMat2D, "constant", "false"); HOperatorSet.CountSeconds(out hv_Before); HTuple end_val61 = hv_Loops; HTuple step_val61 = 1; for (hv_Index = 1; hv_Index.Continue(end_val61, step_val61); hv_Index = hv_Index.TupleAdd(step_val61)) { //set_grayval ensures that Image must be transferred to the device again. HOperatorSet.SetGrayval(ho_Image, 0, 0, hv_Grayval); ho_ImageAffinTrans.Dispose(); HOperatorSet.AffineTransImage(ho_Image, out ho_ImageAffinTrans, hv_HomMat2D, "constant", "false"); //get_image_pointer1 ensures that ImageAffinTrans is transferred back to host. HOperatorSet.GetImagePointer1(ho_ImageAffinTrans, out hv_Pointer, out hv_Type, out hv_Width, out hv_Height); } HOperatorSet.CountSeconds(out hv_After); hv_TimeGPUinclTransfer = ((hv_After - hv_Before) * 1000.0) / hv_Loops; // //Deactivate the device and perform the same benchmark on the CPU. HOperatorSet.DeactivateComputeDevice(hv_DeviceHandle); ho_ImageAffinTrans.Dispose(); HOperatorSet.AffineTransImage(ho_Image, out ho_ImageAffinTrans, hv_HomMat2D, "constant", "false"); HOperatorSet.CountSeconds(out hv_Before); HTuple end_val75 = hv_Loops; HTuple step_val75 = 1; for (hv_Index = 1; hv_Index.Continue(end_val75, step_val75); hv_Index = hv_Index.TupleAdd(step_val75)) { ho_ImageAffinTrans.Dispose(); HOperatorSet.AffineTransImage(ho_Image, out ho_ImageAffinTrans, hv_HomMat2D, "constant", "false"); } HOperatorSet.CountSeconds(out hv_After); hv_TimeCPU = ((hv_After - hv_Before) * 1000.0) / hv_Loops; hv_SpeedUp = hv_TimeCPU / hv_TimeGPU; hv_Message = "affine_trans_image runtimes:"; if (hv_Message == null) { hv_Message = new HTuple(); } hv_Message[1] = ((("Compute Device #" + hv_DeviceIndex) + " (excl. transfer): ") + (hv_TimeGPU.TupleString( ".2f"))) + " ms"; if (hv_Message == null) { hv_Message = new HTuple(); } hv_Message[2] = ((("Compute Device #" + hv_DeviceIndex) + " (incl. transfer): ") + (hv_TimeGPUinclTransfer.TupleString( ".2f"))) + " ms"; if (hv_Message == null) { hv_Message = new HTuple(); } hv_Message[3] = ("CPU: " + (hv_TimeCPU.TupleString( ".2f"))) + " ms"; if (hv_Message == null) { hv_Message = new HTuple(); } hv_Message[4] = " "; if (hv_Message == null) { hv_Message = new HTuple(); } hv_Message[5] = "Potential speedup: " + (hv_SpeedUp.TupleString(".1f")); disp_message(hv_ExpDefaultWinHandle, hv_Message, "window", 42, 12, "white", "false"); if ((int)(new HTuple(hv_DeviceIndex.TupleLess((new HTuple(hv_DeviceIdentifier.TupleLength() )) - 1))) != 0) { disp_continue_message(hv_ExpDefaultWinHandle, "black", "true"); HDevelopStop(); } } } catch (HalconException HDevExpDefaultException) { ho_Image.Dispose(); ho_ImageAffinTrans.Dispose(); throw HDevExpDefaultException; } ho_Image.Dispose(); ho_ImageAffinTrans.Dispose(); }
public void region_ocr_num_svm(HObject ho_Image, HObject ho_ROI_OCR_01_0, HTuple hv_TextModel, HTuple hv_OcrHandle, out HTuple hv_SymbolNames_OCR_01_0, out HTuple hv_Ocr_Split) { // Local iconic variables HObject ho_TmpObj_Mono, ho_TmpObj_MonoReduced_OCR_01_0; HObject ho_TmpObj_Domain, ho_TmpObj_DomainExpanded, ho_TmpObj_DomainTransformedRaw; HObject ho_TmpObj_DomainTransformed, ho_TmpObj_ImageTransformed; HObject ho_TmpObj_ImageTransformedExpanded, ho_TmpObj_ImageTransformedReduced; HObject ho_Symbols_OCR_01_0; // Local control variables HTuple hv_TmpCtrl_MatrixIdentity = new HTuple(); HTuple hv_TmpCtrl_ClipRegion = new HTuple(), hv_TmpCtrl_Row1 = new HTuple(); HTuple hv_TmpCtrl_Col1 = new HTuple(), hv_TmpCtrl_Row2 = new HTuple(); HTuple hv_TmpCtrl_Col2 = new HTuple(), hv_TmpCtrl_MatrixTranslation = new HTuple(); HTuple hv_TmpCtrl_MatrixComposite = new HTuple(), hv_TmpCtrl_ResultHandle_OCR_01_0 = new HTuple(); HTuple hv_OcrHandle_COPY_INP_TMP = new HTuple(hv_OcrHandle); HTuple hv_TextModel_COPY_INP_TMP = new HTuple(hv_TextModel); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_TmpObj_Mono); HOperatorSet.GenEmptyObj(out ho_TmpObj_MonoReduced_OCR_01_0); HOperatorSet.GenEmptyObj(out ho_TmpObj_Domain); HOperatorSet.GenEmptyObj(out ho_TmpObj_DomainExpanded); HOperatorSet.GenEmptyObj(out ho_TmpObj_DomainTransformedRaw); HOperatorSet.GenEmptyObj(out ho_TmpObj_DomainTransformed); HOperatorSet.GenEmptyObj(out ho_TmpObj_ImageTransformed); HOperatorSet.GenEmptyObj(out ho_TmpObj_ImageTransformedExpanded); HOperatorSet.GenEmptyObj(out ho_TmpObj_ImageTransformedReduced); HOperatorSet.GenEmptyObj(out ho_Symbols_OCR_01_0); hv_SymbolNames_OCR_01_0 = new HTuple(); hv_Ocr_Split = new HTuple(); //OCR 01: Code generated by OCR 01 //OCR 01: //OCR 01: Prepare text model //OCR 01: if ((int)(new HTuple(hv_TextModel_COPY_INP_TMP.TupleEqual(new HTuple()))) != 0) { hv_TextModel_COPY_INP_TMP.Dispose(); HOperatorSet.CreateTextModelReader("manual", new HTuple(), out hv_TextModel_COPY_INP_TMP); HOperatorSet.SetTextModelParam(hv_TextModel_COPY_INP_TMP, "manual_stroke_width", 5); HOperatorSet.SetTextModelParam(hv_TextModel_COPY_INP_TMP, "manual_fragment_size_min", 5); HOperatorSet.SetTextModelParam(hv_TextModel_COPY_INP_TMP, "manual_eliminate_border_blobs", "true"); HOperatorSet.SetTextModelParam(hv_TextModel_COPY_INP_TMP, "manual_base_line_tolerance", 0.2); HOperatorSet.SetTextModelParam(hv_TextModel_COPY_INP_TMP, "manual_max_line_num", 2); } //OCR 01: //OCR 01: Load classifier //OCR 01: if ((int)(new HTuple(hv_OcrHandle_COPY_INP_TMP.TupleEqual(new HTuple()))) != 0) { hv_OcrHandle_COPY_INP_TMP.Dispose(); HOperatorSet.ReadOcrClassSvm("C:/Users/iwake/OneDrive - wake/Desktop/OCR/NumOcrTrainBlck.osc", out hv_OcrHandle_COPY_INP_TMP); } //OCR 01: //OCR 01: Extract symbol regions (segmentation step) //OCR 01: Only consider first channel for color images ho_TmpObj_Mono.Dispose(); HOperatorSet.AccessChannel(ho_Image, out ho_TmpObj_Mono, 1); ho_TmpObj_MonoReduced_OCR_01_0.Dispose(); HOperatorSet.ReduceDomain(ho_TmpObj_Mono, ho_ROI_OCR_01_0, out ho_TmpObj_MonoReduced_OCR_01_0 ); //OCR 01: //OCR 01: Orientation Correction (for consistent border and domain //OCR 01: handling, this is always applied, even with no rotation) //OCR 01: hv_TmpCtrl_MatrixIdentity.Dispose(); HOperatorSet.HomMat2dIdentity(out hv_TmpCtrl_MatrixIdentity); //OCR 01: Apply transformation to image and domain ho_TmpObj_Domain.Dispose(); HOperatorSet.GetDomain(ho_TmpObj_MonoReduced_OCR_01_0, out ho_TmpObj_Domain); hv_TmpCtrl_ClipRegion.Dispose(); HOperatorSet.GetSystem("clip_region", out hv_TmpCtrl_ClipRegion); HOperatorSet.SetSystem("clip_region", "false"); ho_TmpObj_DomainExpanded.Dispose(); HOperatorSet.DilationCircle(ho_TmpObj_Domain, out ho_TmpObj_DomainExpanded, 25); ho_TmpObj_DomainTransformedRaw.Dispose(); HOperatorSet.AffineTransRegion(ho_TmpObj_DomainExpanded, out ho_TmpObj_DomainTransformedRaw, hv_TmpCtrl_MatrixIdentity, "true"); hv_TmpCtrl_Row1.Dispose(); hv_TmpCtrl_Col1.Dispose(); hv_TmpCtrl_Row2.Dispose(); hv_TmpCtrl_Col2.Dispose(); HOperatorSet.SmallestRectangle1(ho_TmpObj_DomainTransformedRaw, out hv_TmpCtrl_Row1, out hv_TmpCtrl_Col1, out hv_TmpCtrl_Row2, out hv_TmpCtrl_Col2); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_TmpCtrl_MatrixTranslation.Dispose(); HOperatorSet.HomMat2dTranslate(hv_TmpCtrl_MatrixIdentity, -hv_TmpCtrl_Row1, -hv_TmpCtrl_Col1, out hv_TmpCtrl_MatrixTranslation); } hv_TmpCtrl_MatrixComposite.Dispose(); HOperatorSet.HomMat2dCompose(hv_TmpCtrl_MatrixTranslation, hv_TmpCtrl_MatrixIdentity, out hv_TmpCtrl_MatrixComposite); ho_TmpObj_DomainTransformed.Dispose(); HOperatorSet.AffineTransRegion(ho_TmpObj_Domain, out ho_TmpObj_DomainTransformed, hv_TmpCtrl_MatrixComposite, "true"); ho_TmpObj_ImageTransformed.Dispose(); HOperatorSet.AffineTransImage(ho_TmpObj_MonoReduced_OCR_01_0, out ho_TmpObj_ImageTransformed, hv_TmpCtrl_MatrixComposite, "constant", "true"); ho_TmpObj_DomainExpanded.Dispose(); HOperatorSet.DilationCircle(ho_TmpObj_Domain, out ho_TmpObj_DomainExpanded, 25); ho_TmpObj_ImageTransformedExpanded.Dispose(); HOperatorSet.ExpandDomainGray(ho_TmpObj_ImageTransformed, out ho_TmpObj_ImageTransformedExpanded, 25); ho_TmpObj_ImageTransformedReduced.Dispose(); HOperatorSet.ReduceDomain(ho_TmpObj_ImageTransformed, ho_TmpObj_DomainTransformed, out ho_TmpObj_ImageTransformedReduced); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { ho_TmpObj_MonoReduced_OCR_01_0.Dispose(); HOperatorSet.CropPart(ho_TmpObj_ImageTransformedReduced, out ho_TmpObj_MonoReduced_OCR_01_0, 0, 0, (hv_TmpCtrl_Col2 - hv_TmpCtrl_Col1) + 1, (hv_TmpCtrl_Row2 - hv_TmpCtrl_Row1) + 1); } HOperatorSet.SetSystem("clip_region", hv_TmpCtrl_ClipRegion); hv_TmpCtrl_ResultHandle_OCR_01_0.Dispose(); HOperatorSet.FindText(ho_TmpObj_MonoReduced_OCR_01_0, hv_TextModel_COPY_INP_TMP, out hv_TmpCtrl_ResultHandle_OCR_01_0); //OCR 01: //OCR 01: Read text (classification step) ho_Symbols_OCR_01_0.Dispose(); HOperatorSet.GetTextObject(out ho_Symbols_OCR_01_0, hv_TmpCtrl_ResultHandle_OCR_01_0, "manual_all_lines"); //dev_display (TmpObj_MonoReduced_OCR_01_0) //dev_set_draw ('fill') //dev_set_colored (3) //dev_display (Symbols_OCR_01_0) hv_SymbolNames_OCR_01_0.Dispose(); HOperatorSet.DoOcrMultiClassSvm(ho_Symbols_OCR_01_0, ho_TmpObj_MonoReduced_OCR_01_0, hv_OcrHandle_COPY_INP_TMP, out hv_SymbolNames_OCR_01_0); hv_Ocr_Split.Dispose(); ocr_split(hv_SymbolNames_OCR_01_0, out hv_Ocr_Split); ho_TmpObj_Mono.Dispose(); ho_TmpObj_MonoReduced_OCR_01_0.Dispose(); ho_TmpObj_Domain.Dispose(); ho_TmpObj_DomainExpanded.Dispose(); ho_TmpObj_DomainTransformedRaw.Dispose(); ho_TmpObj_DomainTransformed.Dispose(); ho_TmpObj_ImageTransformed.Dispose(); ho_TmpObj_ImageTransformedExpanded.Dispose(); ho_TmpObj_ImageTransformedReduced.Dispose(); ho_Symbols_OCR_01_0.Dispose(); hv_OcrHandle_COPY_INP_TMP.Dispose(); hv_TextModel_COPY_INP_TMP.Dispose(); hv_TmpCtrl_MatrixIdentity.Dispose(); hv_TmpCtrl_ClipRegion.Dispose(); hv_TmpCtrl_Row1.Dispose(); hv_TmpCtrl_Col1.Dispose(); hv_TmpCtrl_Row2.Dispose(); hv_TmpCtrl_Col2.Dispose(); hv_TmpCtrl_MatrixTranslation.Dispose(); hv_TmpCtrl_MatrixComposite.Dispose(); hv_TmpCtrl_ResultHandle_OCR_01_0.Dispose(); return; }