public bool Grab_Intervene_Act(HImage image, List <HHomMat2D> Mat2Ds) { try { if (!bIsInitial) { Initial_Grab_Intervene(); } if (Grab_Intervene_Region == null || !Grab_Intervene_Region.IsInitialized()) { return(false); } if (Mat2Ds == null || Mat2Ds.Count() < 1) { return(false); } if (ResultRegion == null) { ResultRegion = new HRegion(); } if (ResultRegion != null && ResultRegion.IsInitialized()) { ResultRegion.Dispose(); } ResultRegion.GenEmptyObj(); grabInterveneOkNg = new HTuple(); if (Grab_Intervene_Region_Affines == null) { Grab_Intervene_Region_Affines = new HRegion(); } if (Grab_Intervene_Region_Affines != null && Grab_Intervene_Region_Affines.IsInitialized()) { Grab_Intervene_Region_Affines.Dispose(); } Grab_Intervene_Region_Affines.GenEmptyObj(); for (int i = 0; i < Mat2Ds.Count(); i++) { if (Grab_Intervene_Region_Affine == null) { Grab_Intervene_Region_Affine = new HRegion(); } if (Grab_Intervene_Region_Affine != null && Grab_Intervene_Region_Affine.IsInitialized()) { Grab_Intervene_Region_Affine.Dispose(); } Grab_Intervene_Region_Affine.GenEmptyObj(); Grab_Intervene_Region_Affine = Mat2Ds[i].AffineTransRegion(Grab_Intervene_Region, "nearest_neighbor"); Grab_Intervene_Region_Affines = Grab_Intervene_Region_Affines.ConcatObj(Grab_Intervene_Region_Affine); Act_Engine(image); } } catch { return(false); } return(true); }
/// <summary> /// Creates a measure object based on the model data /// defined by the ROI instance and the parameters /// describing the measure context. /// </summary> protected void UpdateMeasure() { double extent, sPhi, radius; if (mHandle != null) { mHandle.Dispose(); } mMeasAssist.exceptionText = ""; try { switch (mROIType) { case ROI.ROI_TYPE_CIRCLEARC: radius = mROICoord[2].D; sPhi = mROICoord[3].D; extent = mROICoord[4].D; mMeasROI = GenSurCircle(mROICoord, mMeasAssist.mRoiWidth); mHandle = new HMeasure(mROICoord[0].D, mROICoord[1].D, radius, sPhi, extent, mMeasAssist.mRoiWidth, mMeasAssist.mWidth, mMeasAssist.mHeight, mMeasAssist.mInterpolation); break; case ROI.ROI_TYPE_CIRCLE: //記錄 ROI 範圍 mMeasROI = GenSurCircle2(mROICoord, mMeasAssist.mRoiWidth); break; case ROI.ROI_TYPE_LINE: case ROI.ROI_TYPE_POINT: mMeasROI = GenSurRect2(mROICoord, mROICoord[4]); mHandle = new HMeasure(mMeasROI[0].D, mMeasROI[1].D, mMeasROI[2].D, mMeasROI[3].D, mMeasROI[4].D, mMeasAssist.mWidth, mMeasAssist.mHeight, mMeasAssist.mInterpolation); break; } } catch (HOperatorException e) { mEdgeXLD.Dispose(); mMeasureRegion.Dispose(); mMeasAssist.exceptionText = e.Message; ClearResultData(); return; } UpdateResults(); UpdateMeasureRegion(); }
public void Close() { if (hShapeModel != null && hShapeModel.IsInitialized()) { hShapeModel.Dispose(); } hShapeModel = null; if (modelRegion != null && modelRegion.IsInitialized()) { modelRegion.Dispose(); } modelRegion = null; if (modelXLDCont != null && modelXLDCont.IsInitialized()) { modelXLDCont.Dispose(); } modelXLDCont = null; if (modelXLDContAffine != null && modelXLDContAffine.IsInitialized()) { modelXLDContAffine.Dispose(); } modelXLDContAffine = null; shapeModelROIList = null; }
public void SetModelImage() { if (ModelImg != null) { ModelImg.Dispose(); } ModelImg = new HImage(InputImg); if (SearchRegion != null) { SearchRegion.Dispose(); SearchRegion = null; } if (ModelRegion != null) { ModelRegion.Dispose(); ModelRegion = null; } if (nCCModel != null) { nCCModel.Dispose(); nCCModel = null; } }
public void GenDetectionRegionResult(HRegion modelRegion) { if (resultRegion == null) { resultRegion = new HRegion(); } if (resultRegion != null && resultRegion.IsInitialized()) { resultRegion.Dispose(); } resultRegion.GenEmptyObj(); HRegion temp = new HRegion(); for (int i = 0; i < row.Length; i++) { HHomMat2D mat1 = new HHomMat2D(); mat1.VectorAngleToRigid( createShapeModel.refCoordinates[0].D, createShapeModel.refCoordinates[1].D, createShapeModel.refCoordinates[2].D, row[i].D, column[i].D, angle[i].D); mat1 = mat1.HomMat2dScale(scale[i].D, scale[i].D, row[i].D, column[i].D); //图像偏移 temp = mat1.AffineTransRegion(modelRegion, "nearest_neighbor"); //获取模板集合 resultRegion = resultRegion.ConcatObj(temp); temp.Dispose(); } }
/// <summary> /// Test the neighborhood. /// </summary> private void NeighborhoodTest() { HImage image = new HImage("byte", 512, 512); HRegion regionLine = new HRegion(); HRegion regionComplement = new HRegion(); HRegion regionConnected = new HRegion(); HTuple hv_DefWindow = new HTuple(); HWindow HalconWindow1 = HalconWindowControl1.HalconWindow; HWindow HalconWindow2 = HalconWindowControl2.HalconWindow; try { HalconWindow1.SetColored(6); HalconWindow2.SetColored(6); int numObjects; image.GenImageGrayRamp(0, 0, 128, 256, 256, 512, 512); // Display code image.DispImage(HalconWindow1); image.DispImage(HalconWindow2); regionLine.GenRegionLine(100, -1, 150, 512); regionComplement = regionLine.Complement(); HOperatorSet.SetSystem("neighborhood", 4); regionConnected = regionComplement.Connection(); image.DispImage(HalconWindow1); regionConnected.DispRegion(HalconWindow1); numObjects = regionConnected.CountObj(); label1.Text = "Number of objects 4-connected:" + numObjects.ToString(); regionConnected.Dispose(); HOperatorSet.SetSystem("neighborhood", 8); regionConnected = regionComplement.Connection(); image.DispImage(HalconWindow2); regionConnected.DispRegion(HalconWindow2); numObjects = regionConnected.CountObj(); label2.Text = "Number of objects 8-connected:" + numObjects.ToString(); HOperatorSet.CloseWindow(HDevWindowStack.Pop()); } catch (Exception) { throw; } finally { image.Dispose(); regionLine.Dispose(); regionConnected.Dispose(); regionComplement.Dispose(); } }
public void AddHRegion(HRegion region) { if (MaskRegion != null) { HRegion buff = MaskRegion.Union2(region); MaskRegion.Dispose(); MaskRegion = buff; } else { MaskRegion = region.Clone(); } }
private void Act_Engine(HImage R, HImage B) { LanQuan_ProcedureCall.SetInputIconicParamObject("R", R); LanQuan_ProcedureCall.SetInputIconicParamObject("B", B); LanQuan_ProcedureCall.SetInputIconicParamObject("ROI_LanQuan_T", LanQuan_Region_Affine); LanQuan_ProcedureCall.SetInputCtrlParamTuple("minThreshold", new HTuple(minThreshold)); LanQuan_ProcedureCall.SetInputCtrlParamTuple("filterRadiu", new HTuple(filterRadiu)); LanQuan_ProcedureCall.SetInputCtrlParamTuple("minArea", new HTuple(minArea)); LanQuan_ProcedureCall.Execute(); if (LanQuan_OkNg.Length == 0) { LanQuan_OkNg = (LanQuan_ProcedureCall.GetOutputCtrlParamTuple("lanQuan_OKNG")); Area = LanQuan_ProcedureCall.GetOutputCtrlParamTuple("Area"); } else { LanQuan_OkNg = LanQuan_OkNg.TupleConcat(LanQuan_ProcedureCall.GetOutputCtrlParamTuple("lanQuan_OKNG")); Area = Area.TupleConcat(LanQuan_ProcedureCall.GetOutputCtrlParamTuple("Area")); } HRegion temp = new HRegion(); temp = LanQuan_ProcedureCall.GetOutputIconicParamRegion("Result_Region"); if (temp != null && temp.IsInitialized()) { ResultRegion = ResultRegion.ConcatObj(temp); temp.Dispose(); } }
/// <summary> /// 在图像中绘制圆形区域 /// </summary> /// <param name="row"></param> /// <param name="column"></param> /// <param name="radius"></param> public void DrawCircle(string color, out double row, out double column, out double radius) { try { Double _row, _column, _radius; ShieldMouseEvent(); hWindowControl1.Focus(); hWindowControl1.HalconWindow.SetColor(color); hWindowControl1.HalconWindow.DrawCircle(out _row, out _column, out _radius); HRegion circle = new HRegion(); circle.GenCircle(_row, _column, _radius); circle.GenContourRegionXld("border").DispObj(hWindowControl1.HalconWindow); // circle.DispObj(hWindowControl1.HalconWindow); circle.Dispose(); ReloadMouseEvent(); row = _row; column = _column; radius = _radius; } catch (Exception ex) { row = 0.0; column = 0.0; radius = 0.0; status_message.Text = ex.Message; } }
/// <summary> /// 在图像中绘制矩形区域 /// </summary> /// <param name="row"></param> /// <param name="column"></param> /// <param name="phi"></param> /// <param name="length1"></param> /// <param name="length2"></param> public void DrawRectangle2(string color, out double row, out double column, out double phi, out double length1, out double length2) { try { Double _row, _column, _phi, _length1, _length2; ShieldMouseEvent(); hWindowControl1.Focus(); hWindowControl1.HalconWindow.SetColor(color); hWindowControl1.HalconWindow.DrawRectangle2(out _row, out _column, out _phi, out _length1, out _length2); HRegion rectangle = new HRegion(); rectangle.GenRectangle2(_row, _column, _phi, _length1, _length2); rectangle.GenContourRegionXld("border").DispObj(hWindowControl1.HalconWindow); // rectangle.DispObj(hWindowControl1.HalconWindow); rectangle.Dispose(); ReloadMouseEvent(); row = _row; column = _column; phi = _phi; length1 = _length1; length2 = _length2; } catch (System.Exception ex) { row = 0.0; column = 0.0; phi = 0.0; length1 = 0.0; length2 = 0.0; status_message.Text = ex.Message; } }
private void Act_Engine(HImage image) { Grab_Intervene_ProcedureCall.SetInputIconicParamObject("G", image); Grab_Intervene_ProcedureCall.SetInputIconicParamObject("ROI_Grab_T", Grab_Intervene_Region_Affine); Grab_Intervene_ProcedureCall.SetInputCtrlParamTuple("minThreshold", new HTuple(minThreshold)); Grab_Intervene_ProcedureCall.SetInputCtrlParamTuple("filterRadiu", new HTuple(filterRadiu)); Grab_Intervene_ProcedureCall.SetInputCtrlParamTuple("minAreaThread", new HTuple(minAreaThread)); Grab_Intervene_ProcedureCall.Execute(); if (grabInterveneOkNg.Length == 0) { grabInterveneOkNg = (Grab_Intervene_ProcedureCall.GetOutputCtrlParamTuple("grabInterveneOkNg")); } else { grabInterveneOkNg = grabInterveneOkNg.TupleConcat(Grab_Intervene_ProcedureCall.GetOutputCtrlParamTuple("grabInterveneOkNg")); } HRegion temp = new HRegion(); temp = Grab_Intervene_ProcedureCall.GetOutputIconicParamRegion("ResultRegion"); if (temp != null && temp.IsInitialized()) { ResultRegion = ResultRegion.ConcatObj(temp); temp.Dispose(); } }
/// <summary> /// Compute the model image and the model contour for the applied ROI. /// </summary> public void setModelROI(HRegion roi) { if (mTrainingImage == null) { return; } if (mROIModel != null) { mROIModel.Dispose(); } mROIModel = roi; PyramidROIs = null; createNewModelID = true; if (mROIModel == null) { mReducedImage = null; return; } if (mReducedImage != null) { mReducedImage.Dispose(); } mReducedImage = mTrainingImage.ReduceDomain(mROIModel); determineStepRanges(); if (parameterSet.isOnAuto()) { determineShapeParameter(); } inspectShapeModel(); }
private bool StartupLicenseTest() { bool status = false; HImage testImage = new HImage(); HRegion testRegion = new HRegion(); try { // This will fail if we don't have a proper license testImage = new HImage("byte", 16, 16); testRegion = testImage.Threshold(0.0, 255.0); HSystem.SetSystem("temporary_mem_cache", "false"); // This saves RAM significantly! HSystem.SetSystem("global_mem_cache", "idle"); // Likewise status = true; } catch (Exception ex) { MessageBox.Show(ex.Message + " " + DateTime.Now); // Display errors if any in a listbox } finally { testImage.Dispose(); testRegion.Dispose(); } return(status); }
private async void 交叉点ToolStripMenuItem_Click(object sender, EventArgs e) { HImage ho_ImageReduced; HRegion ho_Circle; HTuple hv_Row, hv_Column, hv_CoRR, hv_CoRC, hv_CoCC, hv_RowArea, hv_ColumnArea, hv_CoRRArea, hv_CoRCArea, hv_CoCCArea; double row, column, radius; this.processing = true; this.HwControl.Focus(); this.HwControl.HalconWindow.DrawCircle(out row, out column, out radius); ho_Circle = new HRegion(row, column, radius); ho_ImageReduced = this.ho_Image.ReduceDomain(ho_Circle); //ho_ImageReduced.PointsHarris(0.7, 5.0, 0.08, 1000.0, out hv_Row, out hv_Column); ho_ImageReduced.PointsFoerstner(1.0, 3.0, 5.0, 200, 0.3, "gauss", "true", out hv_Row, out hv_Column, out hv_CoRR, out hv_CoRC, out hv_CoCC, out hv_RowArea, out hv_ColumnArea, out hv_CoRRArea, out hv_CoRCArea, out hv_CoCCArea); if (hv_Row.Length == 1) { this.CalData.Rows.Add(this.count++, hv_Row.D, hv_Column.D, 0, 0, 0); } await Task.Delay(1000); this.processing = false; ho_ImageReduced.Dispose(); ho_Circle.Dispose(); }
private void Act_Engine(HImage image) { FangDai_ProcedureCall.SetInputIconicParamObject("G", image); FangDai_ProcedureCall.SetInputIconicParamObject("RegionFD_T", FangDai_Region_Affine); FangDai_ProcedureCall.SetInputCtrlParamTuple("minThreshold", new HTuple(minThreshold)); FangDai_ProcedureCall.SetInputCtrlParamTuple("minArea", new HTuple(minArea)); FangDai_ProcedureCall.SetInputCtrlParamTuple("maxArea", new HTuple(maxArea)); FangDai_ProcedureCall.Execute(); if (FangDai_OkNg.Length == 0) { FangDai_OkNg = (FangDai_ProcedureCall.GetOutputCtrlParamTuple("fD_OkNg")); Area = FangDai_ProcedureCall.GetOutputCtrlParamTuple("Area"); } else { FangDai_OkNg = FangDai_OkNg.TupleConcat(FangDai_ProcedureCall.GetOutputCtrlParamTuple("fD_OkNg")); Area = Area.TupleConcat(FangDai_ProcedureCall.GetOutputCtrlParamTuple("Area")); } HRegion temp = new HRegion(); temp = FangDai_ProcedureCall.GetOutputIconicParamRegion("ResultRegion"); if (temp != null && temp.IsInitialized()) { ResultRegion = ResultRegion.ConcatObj(temp); temp.Dispose(); } }
public HImage Process(HImage image) { // image.WriteImage("tiff", 0, @"B:\Test_Ori"); var preprocessImage = PreprocessFilter.Process(image); // preprocessImage.WriteImage("tiff", 0, @"B:\Test_preprocessImage"); var thresholdImage = ThresholdImageFilter.Process(preprocessImage); // thresholdImage.WriteImage("tiff", 0, @"B:\Test_thresholdImage"); HRegion region = preprocessImage.DynThreshold( thresholdImage, Offset, LightDark.ToHalconString()); var complement = region.Complement(); thresholdImage.OverpaintRegion(region, (double)ForegroundGray, "fill"); thresholdImage.OverpaintRegion(complement, (double)BackgroundGray, "fill"); // thresholdImage.WriteImage("tiff", 0, @"B:\Test_OverpaintRegion"); region.Dispose(); complement.Dispose(); preprocessImage.Dispose(); return(thresholdImage); }
/// <summary> /// 从DataTable数据获取最终区域 /// </summary> /// <param name="data">DataTable</param> /// <returns>最终区域</returns> public HRegion GenCompRegion(DataTable data) { var hRegion = new HRegion(); hRegion.GenEmptyRegion(); foreach (DataRow dr in data.Rows) { HRegion hr, htemp; hr = GetRegion(dr); if ((bool)dr["ToAdd"]) { htemp = hRegion | hr; } else { htemp = hRegion / hr; } hr.Dispose(); hRegion.Dispose(); hRegion = htemp.CopyObj(1, -1); htemp.Dispose(); } return(hRegion); }
private void Act_Engine(HImage image) { LM_DP_ProcedureCall.SetInputIconicParamObject("R", image); LM_DP_ProcedureCall.SetInputIconicParamObject("ROI_LuoMuDiePian_T", LM_DP_Region_Affine); LM_DP_ProcedureCall.SetInputCtrlParamTuple("minThreshold", new HTuple(minThreshold)); LM_DP_ProcedureCall.SetInputCtrlParamTuple("filterRadiu", new HTuple(filterRadiu)); LM_DP_ProcedureCall.SetInputCtrlParamTuple("minAreaThreshold", new HTuple(minAreaThread)); LM_DP_ProcedureCall.SetInputCtrlParamTuple("luoMuMaxArea", new HTuple(luoMuMaxArea)); LM_DP_ProcedureCall.SetInputCtrlParamTuple("luoMuWidth", new HTuple(luoMuWidth)); LM_DP_ProcedureCall.Execute(); if (lM_DP_OkNg.Length == 0) { lM_DP_OkNg = (LM_DP_ProcedureCall.GetOutputCtrlParamTuple("luoMuDiePian_OKNG")); lM_DP_Num = (LM_DP_ProcedureCall.GetOutputCtrlParamTuple("lM_DP_Num")); lM_DP_Area = (LM_DP_ProcedureCall.GetOutputCtrlParamTuple("lM_DP_Area")); } else { lM_DP_OkNg = lM_DP_OkNg.TupleConcat(LM_DP_ProcedureCall.GetOutputCtrlParamTuple("luoMuDiePian_OKNG")); lM_DP_Num = lM_DP_Num.TupleConcat(LM_DP_ProcedureCall.GetOutputCtrlParamTuple("lM_DP_Num")); lM_DP_Area = lM_DP_Area.TupleConcat(LM_DP_ProcedureCall.GetOutputCtrlParamTuple("lM_DP_Area")); } HRegion temp = new HRegion(); temp = LM_DP_ProcedureCall.GetOutputIconicParamRegion("Result_Region"); if (temp != null && temp.IsInitialized()) { ResultRegion = ResultRegion.ConcatObj(temp); temp.Dispose(); } }
public HRegion Extract(HImage image) { var domain = image.GetDomain(); var offsetRow1 = domain.GetRow1(); var offsetColumn1 = domain.GetColumn1(); var croppedImage = image.CropDomain(); var swThresholdImageFilter = new NotifyStopwatch("DynThresholdCroppedRegionExtractor.ThresholdImageFilter"); HImage thresholdImage = ThresholdImageFilter.Process(croppedImage); swThresholdImageFilter.Dispose(); var swDynThreshold = new NotifyStopwatch("DynThresholdCroppedRegionExtractor.DynThreshold"); HRegion region = croppedImage.DynThreshold( thresholdImage, Offset, LightDark.ToHalconString()); swDynThreshold.Dispose(); var movedRegion = region.MoveRegion(offsetRow1, offsetColumn1); croppedImage.Dispose(); thresholdImage.Dispose(); region.Dispose(); return(movedRegion); }
private void HWindowControl1_HMouseDown(object sender, HMouseEventArgs e) { if (drawFrame == DrawFrame.Brush) { HRegion region = new HRegion(e.Y, e.X, (int)brushSize); if (e.Button == MouseButtons.Left) { ChangeMaskHRegion(region); } DisplayMaskRegion(); hWindowControl1.HalconWindow.SetColor("blue"); hWindowControl1.HalconWindow.DispObj(region); region.Dispose(); } if (ctrller.ActiveROIIndex < 0 && rOI == null && drawFrame != DrawFrame.Brush) { if (e.Button == MouseButtons.Left) { hWndCtrller.SetViewMode(HWndCtrller.MODE_VIEW_MOVE); } } rOI = null; }
public void Close() { if (resultXLDCont != null && resultXLDCont.IsInitialized()) { resultXLDCont.Dispose(); } resultXLDCont = null; refImage = null; createShapeModel = null; if (SearchRegion != null && SearchRegion.IsInitialized()) { SearchRegion.Dispose(); } SearchRegion = null; }
/// <summary> /// Action for this instance. /// </summary> private void Action() { // Local iconic variables HObject ho_ImageGrayRamp, ho_RegionLines, ho_RegionComplement; HObject ho_ConnectedRegions; // Local control variables HTuple hv_Number = null; // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_ImageGrayRamp); HOperatorSet.GenEmptyObj(out ho_RegionLines); HOperatorSet.GenEmptyObj(out ho_RegionComplement); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions); ho_ImageGrayRamp.Dispose(); HOperatorSet.GenImageGrayRamp(out ho_ImageGrayRamp, 0, 0, 128, 256, 256, 512, 512); HImage ImageGrayRamp = new HImage(ho_ImageGrayRamp); // Cast using as operator // Traditional cast ho_RegionLines.Dispose(); HOperatorSet.GenRegionLine(out ho_RegionLines, 100, -1, 150, 512); HRegion RegionLines = new HRegion(ho_RegionLines); ho_RegionComplement.Dispose(); HOperatorSet.Complement(ho_RegionLines, out ho_RegionComplement); HRegion RegionComplement = new HRegion(ho_RegionComplement); HOperatorSet.SetSystem("neighborhood", 4); ho_ConnectedRegions.Dispose(); HOperatorSet.Connection(ho_RegionComplement, out ho_ConnectedRegions); HRegion ConnectedRegions = new HRegion(ho_ConnectedRegions); ImageGrayRamp.DispImage(HalconWindow1); ConnectedRegions.DispRegion(HalconWindow1); RegionLines.DispRegion(HalconWindow1); // Should be two objects HOperatorSet.CountObj(ho_ConnectedRegions, out hv_Number); label1.Text = "Number of objects 4-connected:" + hv_Number.ToString(); HOperatorSet.SetSystem("neighborhood", 8); ConnectedRegions.Dispose(); ConnectedRegions = RegionComplement.Connection(); ImageGrayRamp.DispImage(HalconWindow2); ConnectedRegions.DispRegion(HalconWindow2); RegionLines.DispRegion(HalconWindow2); // Should be a single object hv_Number = ConnectedRegions.CountObj(); label2.Text = "Number of objects 8-connected:" + hv_Number.ToString(); ho_ImageGrayRamp.Dispose(); ho_RegionLines.Dispose(); ho_RegionComplement.Dispose(); ho_ConnectedRegions.Dispose(); }
public bool PZT_Detection_Act(HImage image, List <HHomMat2D> Mat2Ds, HTuple Angle) { try { if (!bIsInitial) { Initial_PZT_Detection(); } if (Pzt_Region == null || !Pzt_Region.IsInitialized()) { return(false); } if (Mat2Ds == null || Mat2Ds.Count() < 1) { return(false); } if (Arrow == null) { Arrow = new HXLD(); } if (Arrow != null && Arrow.IsInitialized()) { Arrow.Dispose(); } Arrow.GenEmptyObj(); dist_PZT = new HTuple(); pZTOkNg = new HTuple(); for (int i = 0; i < Mat2Ds.Count(); i++) { if (Pzt_Region_Affine != null && Pzt_Region_Affine.IsInitialized()) { Pzt_Region_Affine.Dispose(); } Pzt_Region_Affine = Mat2Ds[i].AffineTransRegion(Pzt_Region, "nearest_neighbor"); Act_Engine(image, Angle, i); //Act_Source(image, Angle, i); } } catch { return(false); } return(true); }
public void CreateNccModel(string partName, System.Drawing.Bitmap srcImage, System.Drawing.Rectangle roi) { try { int partIndex = 0; NccModelName newModel = new NccModelName(); if (m_hTemplate != null) { m_hTemplate.Dispose(); } if (m_hoRectangle != null) { m_hoRectangle.Dispose(); } m_hoRectangle.GenRectangle1(1.0 * roi.Top, roi.Left, roi.Bottom, roi.Right); m_hoRectangle.AreaCenter(out m_roiRow, out m_roiColumn); if (srcImage != null) { HImage hImage = new HImage();//VisionProcess.Bitmap2HImage_8(srcImage); HImage hImageReduced; hImageReduced = hImage.ReduceDomain(m_hoRectangle); if (CheckPartModelIdIsExist(partName, ref partIndex)) { newModel.PartName = partName; newModel.ModelID = hImageReduced.CreateNccModel(m_iNumLevels, 0, 0, "auto", "use_polarity"); m_listPartModelID.RemoveAt(partIndex); } else { newModel.ModelID = hImageReduced.CreateNccModel("auto", 0, 0, "auto", "use_polarity"); newModel.PartName = partName; } m_listPartModelID.Add(newModel); } } catch { //LogFile.AppendText("CreateNccModel函数Exception:" + ex.Message.ToString()); //System.Windows.MessageBox.Show(ex.Message.ToString()); } }
public override void ClearTuYa() { if (reduceRegion != null && reduceRegion.IsInitialized()) { reduceRegion.Dispose(); } reduceRegion = new HRegion(); reduceRegion.GenEmptyRegion(); }
public void SetModelOrigin() { if (ModelRegion != null) { HRegion region = ModelRegion.ShapeTrans("convex"); SetModelOrigin(region.Row, region.Column); region.Dispose(); } }
public override void FindModel() { HImage img = InputImg; if (SearchRegion == null || !SearchRegion.IsInitialized()) { SearchRegion = img.GetDomain(); } if (createNewModelID) { if (!CreateNccModel()) { return; } } if (!nCCModel.IsInitialized()) { throw new Exception("无创建的模板"); } HRegion domain = img.GetDomain(); HRegion differentdomain = domain.Difference(SearchRegion); HImage searchImg = img.PaintRegion(differentdomain, 0.0, "fill"); HImage cropImg = searchImg.ReduceDomain(SearchRegion); domain.Dispose(); differentdomain.Dispose(); OutputResult.Reset(); try { double t1, t2; t1 = HSystem.CountSeconds(); HOperatorSet.FindNccModel(cropImg, nCCModel, nCCParam.mStartingAngle, nCCParam.mAngleExtent, nCCParam.MinScore, nCCParam.NumMatches, nCCParam.mMaxOverlap, nCCParam.SubPixel, 0, out OutputResult.Row, out OutputResult.Col, out OutputResult.Angle, out OutputResult.Score); OutputResult.TemplateHand = nCCModel; t2 = HSystem.CountSeconds(); OutputResult.Time = 1000.0 * (t2 - t1); OutputResult.Count = OutputResult.Row.Length; } catch (HOperatorException ex) { if (ex.GetErrorCode() != 9400) { throw ex; } } searchImg.Dispose(); cropImg.Dispose(); }
public void Reset() { Grab_Intervene_ROIList = new List <ROI>(); if (Grab_Intervene_Region != null && !Grab_Intervene_Region.IsInitialized()) { Grab_Intervene_Region.Dispose(); } Grab_Intervene_Region = null; }
public void Reset() { LanQuan_ROIList = new List <ROI>(); if (LanQuan_Region != null && !LanQuan_Region.IsInitialized()) { LanQuan_Region.Dispose(); } LanQuan_Region = null; }
public void Reset() { FangDai_ROIList = new List <ROI>(); if (FangDai_Region != null && !FangDai_Region.IsInitialized()) { FangDai_Region.Dispose(); } FangDai_Region = null; }