/// <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>Gets the HALCON region described by the ROI</summary> public override HRegion getRegion() { HRegion region = new HRegion(); region.GenCircle(midR, midC, radius); return(region); }
public HRegion Extract(HImage image) { var rect = new HRegion(); rect.GenCircle(Y, X, Radius); return(rect); }
public static HRegion GenCircleRegion(double row, double col, double radius) { HRegion circleRegion = new HRegion(); circleRegion.GenEmptyRegion(); circleRegion.GenCircle(row, col, radius); return(circleRegion); }
public void updateTuYaRegion(double row, double col) { if (reduceRegion == null) { reduceRegion = new HRegion(); reduceRegion.GenEmptyRegion(); } HRegion temp = new HRegion(); temp.GenEmptyRegion(); if (row < 1 && col < 1) { return; } temp.GenCircle(row, col, radius); reduceRegion = reduceRegion.Union2(temp); }
public static HImage ReduceDomainForRing(this HImage hImage, double centerX, double centerY, double innerRadius, double outerRadius) { var innerCircle = new HRegion(); innerCircle.GenCircle(centerY, centerX, innerRadius); var outerCircle = new HRegion(); outerCircle.GenCircle(centerY, centerX, outerRadius); var ring = outerCircle.Difference(innerCircle); var reducedImage = hImage.ChangeDomain(ring); innerCircle.Dispose(); outerCircle.Dispose(); ring.Dispose(); // reducedImage.CropDomain() // .ToBitmapSource() // .SaveToJpeg("_EnhanceEdgeArea_Domain.jpg"); return(reducedImage); }
/// <summary> /// 更新量測結果. /// 量測演算法放這裡 /// </summary> public override void UpdateResults() { if (mMeasAssist.mImage == null) { return; } #region 初始化數值 if (!String.IsNullOrEmpty(mMeasAssist.FitCircleAlgo)) { _Algorithm = new HTuple(mMeasAssist.FitCircleAlgo); } //init result mResult = new CircleResult(); // Local iconic variables HObject ho_MeasureROI, ho_ImageReduced; HObject ho_Border, tmp_Border; // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_MeasureROI); HOperatorSet.GenEmptyObj(out ho_ImageReduced); HOperatorSet.GenEmptyObj(out ho_Border); HOperatorSet.GenEmptyObj(out tmp_Border); #endregion try { //******* Create ROI ******** ho_MeasureROI.Dispose(); HOperatorSet.GenCircle(out ho_MeasureROI, mROICoord[0], mROICoord[1], mROICoord[2]); HRegion region = new HRegion(); region.GenCircle(mROICoord[0].D, mROICoord[1].D, mROICoord[2].D); //****** Area Center, 取得目標區域的 pixels 數 *********** HTuple area, areaRow, areaColumn; double areaPixels = 0.0; HOperatorSet.AreaCenter(region, out area, out areaRow, out areaColumn); areaPixels = area.D; //****** 取得影像 ****** var himage = mMeasAssist.getImage(); //******* Extract ROI Image ***** ho_ImageReduced.Dispose(); HOperatorSet.ReduceDomain(himage, ho_MeasureROI, out ho_ImageReduced); //******* Filter **************** var subpixThreadhold = mMeasAssist.SubpixThreadhold; HOperatorSet.GenEmptyObj(out ho_Border); HOperatorSet.ThresholdSubPix(ho_ImageReduced, out ho_Border, subpixThreadhold); if (mMeasAssist.ApplyCalibration && mMeasAssist.IsCalibrationValid) { if (_cameraOut.TupleLength() == 0) { _cameraOut = HMisc.ChangeRadialDistortionCamPar("adaptive", mMeasAssist.CameraIn, 0.0); } //var rectifyImage = himage.ChangeRadialDistortionImage(region, mMeasAssist.CameraIn, cameraOut); HObject calibrationBorder; HOperatorSet.GenEmptyObj(out calibrationBorder); HOperatorSet.ChangeRadialDistortionContoursXld(ho_Border, out calibrationBorder, mMeasAssist.CameraIn, _cameraOut); mResult = fitCircle(calibrationBorder, areaPixels); } else { mResult = fitCircle(ho_Border, areaPixels); } } catch (HOperatorException ex) { Hanbo.Log.LogManager.Error(ex); mResultWorld = new CircleResult(); mResult = new CircleResult(); } finally { ho_MeasureROI.Dispose(); ho_ImageReduced.Dispose(); ho_Border.Dispose(); } UpdateXLD(); }
/// <summary>Gets the HALCON region described by the ROI</summary> public override HRegion getRegion() { HRegion region = new HRegion(); region.GenCircle(midR, midC, radius); return region; }
/// <summary> /// 更新量測結果. /// 量測演算法放這裡 /// </summary> public override void UpdateResults() { if (mMeasAssist.mImage == null) return; #region 初始化數值 if (!String.IsNullOrEmpty(mMeasAssist.FitCircleAlgo)) _Algorithm = new HTuple(mMeasAssist.FitCircleAlgo); //init result mResult = new CircleResult(); // Local iconic variables HObject ho_MeasureROI, ho_ImageReduced; HObject ho_Border, tmp_Border; // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_MeasureROI); HOperatorSet.GenEmptyObj(out ho_ImageReduced); HOperatorSet.GenEmptyObj(out ho_Border); HOperatorSet.GenEmptyObj(out tmp_Border); #endregion try { //******* Create ROI ******** ho_MeasureROI.Dispose(); HOperatorSet.GenCircle(out ho_MeasureROI, mROICoord[0], mROICoord[1], mROICoord[2]); HRegion region = new HRegion(); region.GenCircle(mROICoord[0].D, mROICoord[1].D, mROICoord[2].D); //****** Area Center, 取得目標區域的 pixels 數 *********** HTuple area, areaRow, areaColumn; double areaPixels = 0.0; HOperatorSet.AreaCenter(region, out area, out areaRow, out areaColumn); areaPixels = area.D; //****** 取得影像 ****** var himage = mMeasAssist.getImage(); //******* Extract ROI Image ***** ho_ImageReduced.Dispose(); HOperatorSet.ReduceDomain(himage, ho_MeasureROI, out ho_ImageReduced); //******* Filter **************** var subpixThreadhold = mMeasAssist.SubpixThreadhold; HOperatorSet.GenEmptyObj(out ho_Border); HOperatorSet.ThresholdSubPix(ho_ImageReduced, out ho_Border, subpixThreadhold); if (mMeasAssist.ApplyCalibration && mMeasAssist.IsCalibrationValid) { if (_cameraOut.TupleLength() == 0) { _cameraOut = HMisc.ChangeRadialDistortionCamPar("adaptive", mMeasAssist.CameraIn, 0.0); } //var rectifyImage = himage.ChangeRadialDistortionImage(region, mMeasAssist.CameraIn, cameraOut); HObject calibrationBorder; HOperatorSet.GenEmptyObj(out calibrationBorder); HOperatorSet.ChangeRadialDistortionContoursXld(ho_Border, out calibrationBorder, mMeasAssist.CameraIn, _cameraOut); mResult = fitCircle(calibrationBorder, areaPixels); } else { mResult = fitCircle(ho_Border, areaPixels); } } catch (HOperatorException ex) { Hanbo.Log.LogManager.Error(ex); mResultWorld = new CircleResult(); mResult = new CircleResult(); } finally { ho_MeasureROI.Dispose(); ho_ImageReduced.Dispose(); ho_Border.Dispose(); } UpdateXLD(); }