/// <summary> /// 顯示 Measure 的幾何元素外觀 /// </summary> public override void UpdateXLD() { //clear mEdgeXLD.Dispose(); mEdgeXLD.GenEmptyObj(); var size = 15; var angle = 0.735398; if (_Result == null) { return; } if (_Result.Row1 == null) { return; } if (_Result.Row1.Length > 0) { for (int i = 0; i < _Result.Row1.Length; i++) { var pointXLD = new HXLDCont(); pointXLD.GenCrossContourXld(_Result.Row1[i].D, _Result.Col1[i].D, size, angle); //output mEdgeXLD = mEdgeXLD.ConcatObj(pointXLD); } } }
/// <summary> /// Project the edges of a 3D shape model into image coordinates. /// Instance represents: Handle of the 3D shape model. /// </summary> /// <param name="camParam">Internal camera parameters.</param> /// <param name="pose">3D pose of the 3D shape model in the world coordinate system.</param> /// <param name="hiddenSurfaceRemoval">Remove hidden surfaces? Default: "true"</param> /// <param name="minFaceAngle">Smallest face angle for which the edge is displayed Default: 0.523599</param> /// <returns>Contour representation of the model view.</returns> public HXLDCont ProjectShapeModel3d( HCamPar camParam, HPose pose, string hiddenSurfaceRemoval, double minFaceAngle) { IntPtr proc = HalconAPI.PreCall(1055); this.Store(proc, 0); HalconAPI.Store(proc, 1, (HData)camParam); HalconAPI.Store(proc, 2, (HData)pose); HalconAPI.StoreS(proc, 3, hiddenSurfaceRemoval); HalconAPI.StoreD(proc, 4, minFaceAngle); HalconAPI.InitOCT(proc, 1); int err = HalconAPI.CallProcedure(proc); HalconAPI.UnpinTuple((HTuple)((HData)camParam)); HalconAPI.UnpinTuple((HTuple)((HData)pose)); HXLDCont hxldCont; int procResult = HXLDCont.LoadNew(proc, 1, err, out hxldCont); HalconAPI.PostCall(proc, procResult); GC.KeepAlive((object)this); return(hxldCont); }
private double row2, col2; // second end point of line #endregion Fields #region Constructors public ROILine() { NumHandles = 3; // two end points of line activeHandleIdx = 2; arrowHandleXLD = new HXLDCont(); arrowHandleXLD.GenEmptyObj(); }
/// <summary> /// Detect and read 2D data code symbols in an image or train the 2D data code model. /// Instance represents: Handle of the 2D data code model. /// </summary> /// <param name="image">Input image. If the image has a reduced domain, the data code search is reduced to that domain. This usually reduces the runtime of the operator. However, if the datacode is not fully inside the domain, the datacode might not be found correctly. In rare cases, data codes may be found outside the domain. If these results are undesirable, they have to be subsequently eliminated. </param> /// <param name="genParamName">Names of (optional) parameters for controlling the behavior of the operator. Default: []</param> /// <param name="genParamValue">Values of the optional generic parameters. Default: []</param> /// <param name="resultHandles">Handles of all successfully decoded 2D data code symbols.</param> /// <param name="decodedDataStrings">Decoded data strings of all detected 2D data code symbols in the image.</param> /// <returns>XLD contours that surround the successfully decoded data code symbols. The order of the contour points reflects the orientation of the detected symbols. The contours begin in the top left corner (see 'orientation' at get_data_code_2d_results) and continue clockwise. Alignment{left} Figure[1][1][60]{get_data_code_2d_results-xld_qrcode} Order of points of SymbolXLDs Figure Alignment @f$ </returns> public HXLDCont FindDataCode2d( HImage image, string genParamName, int genParamValue, out int resultHandles, out string decodedDataStrings) { IntPtr proc = HalconAPI.PreCall(1768); this.Store(proc, 0); HalconAPI.Store(proc, 1, (HObjectBase)image); HalconAPI.StoreS(proc, 1, genParamName); HalconAPI.StoreI(proc, 2, genParamValue); HalconAPI.InitOCT(proc, 1); HalconAPI.InitOCT(proc, 0); HalconAPI.InitOCT(proc, 1); int err1 = HalconAPI.CallProcedure(proc); HXLDCont hxldCont; int err2 = HXLDCont.LoadNew(proc, 1, err1, out hxldCont); int err3 = HalconAPI.LoadI(proc, 0, err2, out resultHandles); int procResult = HalconAPI.LoadS(proc, 1, err3, out decodedDataStrings); HalconAPI.PostCall(proc, procResult); GC.KeepAlive((object)this); GC.KeepAlive((object)image); return(hxldCont); }
public ROILine() { NumHandles = 3; // two end points of line activeHandleIdx = 2; arrowHandleXLD = new HXLDCont(); arrowHandleXLD.GenEmptyObj(); }
/// <summary> /// 線段的顯示 viewModel /// </summary> /// <returns></returns> public override ResultDisplayViewModel CreateDisplayViewModel() { HXLDCont edge = new HXLDCont(); HTuple rows, cols; double centerRow = 0.0, centerCol = 0.0; double f_ArrowX = 0.0, f_ArrowY = 0.0, s_ArrowX = 0.0, s_ArrowY = 0.0; if (Row1.TupleLength() > 0 && Row2.TupleLength() > 0) { rows = new HTuple(new double[] { Row1, Row2 }); cols = new HTuple(new double[] { Col1, Col2 }); centerRow = (Row1.D + Row2.D) / 2.0; centerCol = (Col1.D + Col2.D) / 2.0; f_ArrowX = Col1; f_ArrowY = Row1; s_ArrowX = Col2; s_ArrowY = Row2; edge.GenContourPolygonXld(rows, cols); } return(new ResultDisplayViewModel() { PositionX = centerCol, PositionY = centerRow, ImageXLD = edge, FirstArrowX = f_ArrowX, FirstArrowY = f_ArrowY, SecArrowX = s_ArrowX, SecArrowY = s_ArrowY, }); }
/// <summary> /// Creates and initializes a measure object based on information the ROI object /// about the ROI. /// </summary> /// <param name="roi">ROI instance</param> /// <param name="mAssist">Reference to controller class</param> public Measurement(ROI roi, MeasureAssistant mAssist) { mMeasAssist = mAssist; mEdgeXLD = new HXLDCont(); mMeasureRegion = new HRegion(); initROI(roi); }
public override HMessage ActorTask(HMessage imsg) { HTuple row, column, angle, score; HImage img = new HImage(imsg.GetMessageObj("image")); if (sbm == null) { return(GenFinishMessage()); } HMessage msg = new HMessage(); msg.SetMessageObj(img, "image"); Monitor.Enter(lockobj); try { sbm.FindShapeModel(img, -Math.PI, 2 * Math.PI, 0.5, 1, 0.5, "least_squares", 0, 0.9, out row, out column, out angle, out score); if (row.Length > 0) { HXLDCont contours = sbm.GetShapeModelContours(1); HHomMat2D homMat2D = new HHomMat2D(); homMat2D.VectorAngleToRigid(0.0, 0.0, 0.0, row.D, column.D, angle.D); HXLDCont projcont = homMat2D.AffineTransContourXld(contours); msg.SetMessageObj(projcont, "contour"); } } finally { Monitor.Exit(lockobj); } imsg.Dispose(); return(msg); }
public void ShowResult(HWndCtrl viewCtrl) { //搜索范围 viewCtrl.ChangeGraphicSettings(Mode.DRAWMODE, "margin"); if (SearchRegion != null && SearchRegion.IsInitialized()) { viewCtrl.ChangeGraphicSettings(Mode.COLOR, "blue"); viewCtrl.ChangeGraphicSettings(Mode.LINEWIDTH, 2); viewCtrl.AddIconicVar(SearchRegion); } //确保已有模板 if (createShapeModel.hShapeModel == null || !createShapeModel.hShapeModel.IsInitialized() || createShapeModel.createNewModelID) { if (!createShapeModel.CreateShapeModelAct(refImage)) { return; } } //获取仿射变换后的轮廓 HXLDCont modelXldCont = createShapeModel.ModelXLDCont; if (row.Length < 1) { return; } GenDetectionXLDResults(modelXldCont); if (resultXLDCont != null && resultXLDCont.IsInitialized()) { viewCtrl.ChangeGraphicSettings(Mode.COLOR, "blue"); viewCtrl.ChangeGraphicSettings(Mode.LINEWIDTH, 2); viewCtrl.AddIconicVar(resultXLDCont); } }
public bool setTarget(List <HHomMat2D> mat2DsList) { if (mat2DsList == null || mat2DsList.Count < 1) { return(false); } if (GrabXld != null && GrabXld.IsInitialized()) { GrabXld.Dispose(); } else { GrabXld = new HXLDCont(); GrabXld.GenEmptyObj(); } GrabRowTarget = new HTuple(); GrabColTarget = new HTuple(); HTuple rowTemp, colTemp; for (int i = 0; i < mat2DsList.Count; i++) { HOperatorSet.AffineTransPixel(mat2DsList[i], new HTuple(GrabRowOrg), new HTuple(GrabColOrg), out rowTemp, out colTemp); GrabRowTarget = GrabRowTarget.TupleConcat(rowTemp); GrabColTarget = GrabColTarget.TupleConcat(colTemp); } return(true); }
/// <summary> /// 線段的顯示 viewModel /// </summary> /// <returns></returns> public override ResultDisplayViewModel CreateDisplayViewModel() { HXLDCont edge = new HXLDCont(); HTuple rows, cols; double centerRow = 0.0, centerCol = 0.0; double f_ArrowX = 0.0, f_ArrowY = 0.0, s_ArrowX = 0.0, s_ArrowY = 0.0; if (Row1.TupleLength() > 0 && Row2.TupleLength() > 0) { rows = new HTuple(new double[] { Row1, Row2 }); cols = new HTuple(new double[] { Col1, Col2 }); centerRow = (Row1.D + Row2.D) / 2.0; centerCol = (Col1.D + Col2.D) / 2.0; f_ArrowX = Col1; f_ArrowY = Row1; s_ArrowX = Col2; s_ArrowY = Row2; edge.GenContourPolygonXld(rows, cols); } return new ResultDisplayViewModel() { PositionX = centerCol, PositionY = centerRow, ImageXLD = edge, FirstArrowX = f_ArrowX, FirstArrowY = f_ArrowY, SecArrowX = s_ArrowX, SecArrowY = s_ArrowY, }; }
/// <summary> /// 图像处理 /// </summary> /// <returns>返回8个点位数组</returns> public double[] Process() { double[] coorderate = new double[8]; double hv_RowBegin1; double hv_ColBegin1; double hv_RowEnd1; double hv_ColEnd1; double hv_Nr1; double hv_Nc1; double hv_Dist1; double hv_RowBegin2; double hv_ColBegin2; double hv_RowEnd2; double hv_ColEnd2; double hv_Nr2; double hv_Nc2; double hv_Dist2; //图像阈值化,获得region HRegion hRegion = Ho_image.Threshold((double)LowThreshold, (double)HighThreshold); //region转化为himage HImage hImage = hRegion.RegionToBin(255, 0, 512, 512); //减去ROI以外多余部分 HImage image1 = hImage.ReduceDomain(Region1); HImage image2 = hImage.ReduceDomain(Region2); //生成边缘轮廓 HXLDCont edges1 = image1.EdgesSubPix("canny", 1, 5, 5); HXLDCont edges2 = image2.EdgesSubPix("canny", 1, 5, 5); //分割轮廓 HXLDCont xldContsplit1 = edges1.SegmentContoursXld("lines_circles", 5, 4, 2); HXLDCont xldContsplit2 = edges2.SegmentContoursXld("lines_circles", 5, 4, 2); //根据特征筛选轮廓 HXLDCont xldCont1 = xldContsplit1.SelectContoursXld("contour_length", 100, 99999999, -0.5, 0.5); HXLDCont xldCont2 = xldContsplit2.SelectContoursXld("contour_length", 100, 99999999, -0.5, 0.5); //拟合直线 xldCont1.FitLineContourXld("tukey", -1, 0, 5, 2, out hv_RowBegin1, out hv_ColBegin1, out hv_RowEnd1, out hv_ColEnd1, out hv_Nr1, out hv_Nc1, out hv_Dist1); xldCont2.FitLineContourXld("tukey", -1, 0, 5, 2, out hv_RowBegin2, out hv_ColBegin2, out hv_RowEnd2, out hv_ColEnd2, out hv_Nr2, out hv_Nc2, out hv_Dist2); coorderate[0] = hv_RowBegin1; coorderate[1] = hv_ColBegin1; coorderate[2] = hv_RowEnd1; coorderate[3] = hv_ColEnd1; coorderate[4] = hv_RowBegin2; coorderate[5] = hv_ColBegin2; coorderate[6] = hv_RowEnd2; coorderate[7] = hv_ColEnd2; return(coorderate); }
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 static HXLDCont DetermineCrossPoint(double row, double col, double size, double phi) { var crossPoint = new HXLDCont(); crossPoint.GenCrossContourXld(row, col, size, phi); return(crossPoint); }
//仿射变换后的全部轮廓 public void GenDetectionXLDResults(HXLDCont modelXldCont) { if (resultXLDCont == null) { resultXLDCont = new HXLDCont(); } if (resultXLDCont != null && resultXLDCont.IsInitialized()) { resultXLDCont.Dispose(); } resultXLDCont.GenEmptyObj(); HXLDCont rContours; for (int i = 0; i < row.Length; i++) { HHomMat2D mat1 = new HHomMat2D(); mat1.VectorAngleToRigid(0, 0, 0, row[i].D, column[i].D, angle[i].D); mat1 = mat1.HomMat2dScale(scale[i].D, scale[i].D, row[i].D, column[i].D); //图像偏移 rContours = mat1.AffineTransContourXld(modelXldCont); //获取模板集合 resultXLDCont = resultXLDCont.ConcatObj(rContours); rContours.Dispose(); rContours.GenCrossContourXld(row[i].D, column[i].D, 10, angle[i].D); resultXLDCont = resultXLDCont.ConcatObj(rContours); rContours.Dispose(); } }
private void AffineTransModelContour(HShapeModel model, HRegion modelRegion) { if (model != null && modelRegion != null) { try { //获取金字塔第一层轮廓 HXLDCont modelContour = model.GetShapeModelContours(1); double num3, num4; modelRegion.AreaCenter(out num3, out num4); HHomMat2D matd = new HHomMat2D(); matd.VectorAngleToRigid(0.0, 0.0, 0.0, num3, num4, 0.0); HXLD affterAffineModelXLD = matd.AffineTransContourXld(modelContour); if (info.IsShowModelXLD) { Window.SetColor("green"); affterAffineModelXLD.DispXld(Window.Window); } } catch (Exception e) { WriteErrorLog("VisionTool", e.ToString()); } } }
public void SerializeCheck() { if (modelXLDCont != null && modelXLDCont.IsInitialized()) { modelXLDCont.Dispose(); } if (modelXLDContAffine != null && modelXLDContAffine.IsInitialized()) { modelXLDContAffine.Dispose(); } modelXLDCont = null; modelXLDContAffine = null; if (hShapeModel != null && !hShapeModel.IsInitialized()) { hShapeModel = null; } if (modelRegion != null && !modelRegion.IsInitialized()) { modelRegion = null; } using (Stream objectStream = new MemoryStream()) { System.Runtime.Serialization.IFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); formatter.Serialize(objectStream, this); } }
public ROICircularArc(double RowIn, double ColIn, double RadiusIn, double StartPhi, double EndPhi) { NumHandles = 4; // midpoint handle + three handles on the arc activeHandleIdx = 0; contour = new HXLDCont(); circDir = ""; TwoPI = 2 * Math.PI; PI = Math.PI; midR = RowIn; midC = ColIn; radius = RadiusIn; sizeR = midR; sizeC = midC - radius; startPhi = StartPhi; extentPhi = EndPhi; circDir = "positive"; arrowHandleXLD = new HXLDCont(); arrowHandleXLD.GenEmptyObj(); determineArcHandles(); updateArrowHandle(); }
/// <summary> /// 顯示 Measure 的幾何元素外觀 /// </summary> public override void UpdateXLD() { //clear mEdgeXLD.Dispose(); mEdgeXLD.GenEmptyObj(); if (mResult.Row == null) { return; } try { if (mResult.Row.Length > 0) { for (int i = 0; i < mResult.Row.Length; i++) { var circleXLD = new HXLDCont(); var radius = mResult.Radius[i].D; //var radius = diameter / 2.0; // circleXLD.GenCircleContourXld(mResult.Row[i].D, mResult.Col[i].D, radius, 0.0, 6.28318, "positive", 1.0); //output mEdgeXLD = mEdgeXLD.ConcatObj(circleXLD); } } } catch (Exception ex) { Hanbo.Log.LogManager.Error(ex); } }
/// <summary> /// Asynchronous grab of images and preprocessed image data from the specified image acquisition device. /// Instance represents: Handle of the acquisition device to be used. /// </summary> /// <param name="region">Pre-processed image regions.</param> /// <param name="contours">Pre-processed XLD contours.</param> /// <param name="maxDelay">Maximum tolerated delay between the start of the asynchronous grab and the delivery of the image [ms]. Default: -1.0</param> /// <param name="data">Pre-processed control data.</param> /// <returns>Grabbed image data.</returns> public HImage GrabDataAsync( out HRegion region, out HXLDCont contours, double maxDelay, out string data) { IntPtr proc = HalconAPI.PreCall(2029); this.Store(proc, 0); HalconAPI.StoreD(proc, 1, maxDelay); HalconAPI.InitOCT(proc, 1); HalconAPI.InitOCT(proc, 2); HalconAPI.InitOCT(proc, 3); HalconAPI.InitOCT(proc, 0); int err1 = HalconAPI.CallProcedure(proc); HImage himage; int err2 = HImage.LoadNew(proc, 1, err1, out himage); int err3 = HRegion.LoadNew(proc, 2, err2, out region); int err4 = HXLDCont.LoadNew(proc, 3, err3, out contours); int procResult = HalconAPI.LoadS(proc, 0, err4, out data); HalconAPI.PostCall(proc, procResult); GC.KeepAlive((object)this); return(himage); }
public override void construct() { NumHandles = 3; // two end points of line activeHandleIdx = 2; arrowHandleXLD = new HXLDCont(); arrowHandleXLD.GenEmptyObj(); }
/// <summary> /// A helper method to ensure that a HALCON XLD Contour is correctly disposed when assigned a /// new value. /// </summary> /// <param name="from">The source HXLDCont.</param> /// <param name="to">The destination HXLDCont.</param> /// <exception cref="ArgumentNullException">from must not be null.</exception> /// <exception cref="System.ArgumentNullException">from must not be null.</exception> public static void HCopy(this HXLDCont from, ref HXLDCont to) { try { if (@from == null) { throw new ArgumentNullException(nameof(from)); } if (to == null) { to = new HXLDCont(); } to.Dispose(); to = @from.CopyObj(1, -1); } finally { if (@from != null) { @from.Dispose(); } } }
/// <summary> /// 顯示 Measure 的幾何元素外觀 /// </summary> public override void UpdateXLD() { //clear mEdgeXLD.Dispose(); mEdgeXLD.GenEmptyObj(); if (_Result == null) { return; } if (_Result.Row1 == null) { return; } if (_Result.Row1.Length > 0) { var rows = new double[] { _Result.Row1, _Result.Row2 }; var cols = new double[] { _Result.Col1, _Result.Col2 }; var pointXLD = new HXLDCont(); pointXLD.GenContourPolygonXld(rows, cols); //output mEdgeXLD = mEdgeXLD.ConcatObj(pointXLD); } }
public void Close() { if (GrabXld != null && GrabXld.IsInitialized()) { GrabXld.Dispose(); } GrabXld = null; }
public ROILine() { RoiType = GetType().ToString(); NumHandles = 3; // two end points of line activeHandleIdx = 2; arrowHandleXLD = new HXLDCont(); arrowHandleXLD.GenEmptyObj(); }
public ROILine(bool isSearch) { NumHandles = 3; // two end points of line activeHandleIdx = 2; arrowHandleXLD = new HXLDCont(); arrowHandleXLD.GenEmptyObj(); isSearchRegion = isSearch; regionColor = isSearchRegion ? "blue" : "green"; }
public bool CreateShapeModelAct(HImage modelImage) { if (modelImage == null || !modelImage.IsInitialized()) { return(false); } this.modelImage = modelImage; if (modelRegion == null || !modelRegion.IsInitialized()) { return(false); } try { HImage ROIImage = new HImage(); ROIImage.GenEmptyObj(); ROIImage = modelImage.ReduceDomain(modelRegion); HImage temp = ROIImage.GaussFilter(7); ROIImage.Dispose(); ROIImage = temp; hShapeModel = ROIImage.CreateScaledShapeModel( new HTuple(numLevels), angleStart, angleExtent, new HTuple(angleStep), scaleMin, scaleMax, new HTuple(scaleStep), new HTuple(optimization).TupleConcat("no_pregeneration"), metric, ((new HTuple(contrastLow)).TupleConcat(contrastHigh)).TupleConcat(minLength), new HTuple(minContrast)); ROIImage.Dispose(); double row, col; modelRegion.AreaCenter(out row, out col); refCoordinates = new HTuple(row, col, 0); createNewModelID = false; //初始化modelContours if (modelXLDCont == null) { modelXLDCont = new HXLDCont(); } if (modelXLDCont != null && modelXLDCont.IsInitialized()) { modelXLDCont.Dispose(); } modelXLDCont = hShapeModel.GetShapeModelContours(1); } catch { hShapeModel = null; createNewModelID = true; return(false); } return(true); }
public ROIAuxLine(double hWinImagePartWidth, double hWinImagePartHeight, AuxLineType lineType) { NumHandles = 1; // one Control points of line activeHandleIdx = 2; _AuxLineHandleXLD = new HXLDCont(); _AuxLineHandleXLD.GenEmptyObj(); _WinWidth = hWinImagePartWidth; _WinHeight = hWinImagePartHeight; _LineType = lineType; }
public ROICircularArc() { NumHandles = 4; // midpoint handle + three handles on the arc activeHandleIdx = 0; TwoPI = 2 * Math.PI; PI = Math.PI; myR = 10; arrowHandleXLD = new HXLDCont(); arrowHandleXLD.GenEmptyObj(); }
public ROICircularArc() { NumHandles = 4; // midpoint handle + three handles on the arc ActiveHandleIdx = 0; contour = new HXLDCont(); circDir = ""; arrowHandleXLD = new HXLDCont(); arrowHandleXLD.GenEmptyObj(); }
private double _WinWidth, _WinHeight; //HWindow Width, Height #endregion Fields #region Constructors public ROIAuxLine(double hWinImagePartWidth, double hWinImagePartHeight, AuxLineType lineType) { NumHandles = 1; // one Control points of line activeHandleIdx = 2; _AuxLineHandleXLD = new HXLDCont(); _AuxLineHandleXLD.GenEmptyObj(); _WinWidth = hWinImagePartWidth; _WinHeight = hWinImagePartHeight; _LineType = lineType; }
/// <summary> /// Creates the iconic object for displaying a measured /// edge from the coordinates of the end points. /// </summary> /// <returns>Contour depicting the measured edge</returns> public static HXLDCont DetermineLine(double row1, double col1, double row2, double col2) { HXLDCont edge = new HXLDCont(); HTuple rows, cols; rows = new HTuple(new double[] { row1, row2 }); cols = new HTuple(new double[] { col1, col2 }); edge.GenContourPolygonXld(rows, cols); return(edge); }
/// <summary> /// Creates the iconic object for displaying /// the arc between edges of a pair. /// </summary> /// <returns>Edge contour depicting the arc between edges of a pair</returns> public static HXLDCont DeterminePairCircularArc(double row1, double col1, double row2, double col2, double cRow, double cCol, double radius, double width, bool positive) { HXLDCont arc = new HXLDCont(); double startPhi, endPhi; startPhi = Math.Atan2(cRow - row1, col1 - cCol); endPhi = Math.Atan2(cRow - row2, col2 - cCol); arc.GenEllipseContourXld(cRow, cCol, 0.0, radius, radius, startPhi, endPhi, (positive ? "positive" : "negative"), 1.5); return(arc); }
public ROICircularArc() { NumHandles = 4; // midpoint handle + three handles on the arc activeHandleIdx = 0; contour = new HXLDCont(); circDir = ""; TwoPI = 2 * Math.PI; PI = Math.PI; arrowHandleXLD = new HXLDCont(); arrowHandleXLD.GenEmptyObj(); }
/// <summary> /// Creates and initializes a measure object based on information the ROI object /// about the ROI. /// </summary> /// <param name="roi">ROI instance</param> /// <param name="mAssist">Reference to controller class</param> public Measurement(ROI roi, MeasureAssistant mAssist) { mRoi = roi; mMeasAssist = mAssist; mROICoord = mRoi.getModelData(); mEdgeXLD = new HXLDCont(); mMeasureRegion = new HRegion(); if (mRoi is ROICircularArc) mROIType = ROI.ROI_TYPE_CIRCLEARC; else mROIType = ROI.ROI_TYPE_LINE; }
/// <summary> /// 線段的顯示 viewModel /// </summary> /// <returns></returns> public override ResultDisplayViewModel CreateDisplayViewModel() { HXLDCont cross = new HXLDCont(); var size = 15; var angle = 0.785398; cross.GenCrossContourXld(this.Row1, this.Col1, size, angle); return new ResultDisplayViewModel() { PositionX = this.Col1, PositionY = this.Row1, ImageXLD = cross, }; }
public SmartArc() { NumHandles = 4; // one at corner of circle + midpoint activeHandleIdx = 0; this.ROIMeasureType = MeasureType.Circle; _clickedPointsPositionList = new List<PositionModel>(); contour = new HXLDCont(); _pointOrder = ""; _ArcRegion = new HXLDCont(); TwoPI = 2 * Math.PI; PI = Math.PI; arrowHandleXLD = new HXLDCont(); arrowHandleXLD.GenEmptyObj(); }
/// <summary> /// 顯示 Measure 的幾何元素外觀 /// </summary> public override void UpdateXLD() { //clear mEdgeXLD.Dispose(); mEdgeXLD.GenEmptyObj(); if (mResult.Row == null) return; try { if (mResult.Row.Length > 0) { for (int i = 0; i < mResult.Row.Length; i++) { var circleXLD = new HXLDCont(); var radius = mResult.Radius[i].D; //var radius = diameter / 2.0; // circleXLD.GenCircleContourXld(mResult.Row[i].D, mResult.Col[i].D, radius, 0.0, 6.28318, "positive", 1.0); //output mEdgeXLD = mEdgeXLD.ConcatObj(circleXLD); } } } catch (Exception ex) { Hanbo.Log.LogManager.Error(ex); } }
/// <summary> /// Loads MeasureForm and initializes view functions /// to include in the MeasureAssistant. /// </summary> private void MeasureForm_Load(object sender, System.EventArgs e) { mView = new HWndCtrl(viewPort); roiController = new ROIController(); mView.useROIController(roiController); mAssistant = new MeasureAssistant(roiController); mShadow = new HXLDCont(); mView.setViewState(HWndCtrl.MODE_VIEW_NONE); mView.changeGraphicSettings(GraphicsContext.GC_LINEWIDTH, 1); roiController.NotifyRCObserver = new IconicDelegate(UpdateROIData); mAssistant.NotifyMeasureObserver = new MeasureDelegate(UpdateMeasureResults); plotGraphWindow = new FunctionPlot(panelAxis, true); openImageFileDialog.InitialDirectory = (string)(HSystem.GetSystem("image_dir").TupleSplit(";")); Init(); mView.setDispLevel(HWndCtrl.MODE_EXCLUDE_ROI); }
public static HXLDCont DetermineCrossPoint(double row, double col, double size, double phi) { var crossPoint = new HXLDCont(); crossPoint.GenCrossContourXld(row, col, size, phi); return crossPoint; }
/// <summary> /// Gets the detected contour. /// </summary> /// <returns>Detected contour</returns> public HXLDCont getDetectionResults() { HXLDCont rContours = new HXLDCont(); hmat.HomMat2dIdentity(); mContResults.GenEmptyObj(); for(int i = 0; i<count; i++) { hmat.VectorAngleToRigid(0, 0, 0, mRow[i].D, mCol[i].D, mAngle[i].D); rContours = hmat.AffineTransContourXld(mContour); mContResults = mContResults.ConcatObj(rContours); } return mContResults; }
/// <summary> /// Creates an iconic object depicting the /// measuring field. /// </summary> public void UpdateMeasureRegion() { mMeasureRegion.Dispose(); mMeasureRegion.GenEmptyObj(); if (mROIType == ROI.ROI_TYPE_CIRCLEARC) { double sPhi, extent, innerRad, outerRad; HTuple innerR, outerR, innerC, outerC; HXLDCont outCont, innerCont, contour; outCont = new HXLDCont(); innerCont = new HXLDCont(); sPhi = mMeasROI[2].D; extent = mMeasROI[3].D; outerRad = mMeasROI[4].D; innerRad = mMeasROI[5].D; innerCont.GenCircleContourXld(mMeasROI[0].D, mMeasROI[1].D, innerRad, sPhi, (sPhi + extent), (extent > 0) ? "positive" : "negative", 1.0); outCont.GenCircleContourXld(mMeasROI[0].D, mMeasROI[1].D, outerRad, (sPhi + extent), sPhi, (extent > 0) ? "negative" : "positive", 1.0); innerCont.GetContourXld(out innerR, out innerC); outCont.GetContourXld(out outerR, out outerC); innerR = innerR.TupleConcat(outerR); innerC = innerC.TupleConcat(outerC); contour = new HXLDCont(innerR, innerC); contour = contour.CloseContoursXld(); mMeasureRegion = contour.GenRegionContourXld("margin"); contour.Dispose(); innerCont.Dispose(); outCont.Dispose(); } else { mMeasureRegion.GenRectangle2(mMeasROI[0].D, mMeasROI[1].D, mMeasROI[2].D, mMeasROI[3].D, mMeasROI[4].D); } }
/// <summary> /// Creates the iconic object for displaying /// the arc between edges of a pair. /// </summary> /// <returns>Edge contour depicting the arc between edges of a pair</returns> public static HXLDCont DeterminePairCircularArc(double row1, double col1, double row2, double col2, double cRow, double cCol, double radius, double width, bool positive) { HXLDCont arc = new HXLDCont(); double startPhi, endPhi; startPhi = Math.Atan2(cRow - row1, col1 - cCol); endPhi = Math.Atan2(cRow - row2, col2 - cCol); arc.GenEllipseContourXld(cRow, cCol, 0.0, radius, radius, startPhi, endPhi, (positive ? "positive" : "negative"), 1.5); return arc; }
/// <summary> /// draw, 決定要畫什麼在 window 上 /// </summary> /// <param name="window">Halcon Window</param> public override void draw(HalconDotNet.HWindow window) { double arrowSize = 2; double crossSize = 12; double crossAngle = 0.785398; HTuple dotLineStyle = new HTuple(new int[4] { 7, 7, 7, 7 }); //Reset line Style HOperatorSet.SetLineStyle(window, null); //寫字 if (!String.IsNullOrEmpty(Name)) { HOperatorSet.SetTposition(window, this.NewCenterRow, this.NewCenterCol); if (!this.IsActive) HOperatorSet.SetColor(window, "red"); window.WriteString(Name); } // 畫箭頭, 由線段的中心點向兩端畫箭頭 window.SetLineWidth(1); //計算兩箭頭端點位置 var arrowPointRowBegin = _arrowLineRowBegin = this.NewCenterRow + (Math.Sin(_phiStart) * _halfDistance); var arrowPointColBegin = _arrowLineColBegin = this.NewCenterCol + (Math.Cos(_phiStart) * _halfDistance); var arrowPointRowEnd = _arrowLineRowEnd = this.NewCenterRow + (Math.Sin(_phiEnd) * _halfDistance); var arrowPointColEnd = _arrowLineColEnd = this.NewCenterCol + (Math.Cos(_phiEnd) * _halfDistance); window.DispArrow(this.NewCenterRow, this.NewCenterCol, arrowPointRowBegin, arrowPointColBegin, arrowSize); window.DispArrow(this.NewCenterRow, this.NewCenterCol, arrowPointRowEnd, arrowPointColEnd, arrowSize); //畫虛線,如果使用者改變了原始中心點的位置 //由兩箭頭端點連結原始的起始兩端點 if (_rawCenterRow != this.NewCenterRow || _rawCenterCol != this.NewCenterCol) { HOperatorSet.SetLineStyle(window, dotLineStyle); //決定兩個端點的連結,將座標點 以左上排序 var arrowPoints = new List<PositionModel>() { new PositionModel(){ RowBegin =arrowPointRowBegin, ColBegin = arrowPointColBegin }, new PositionModel(){ RowBegin =arrowPointRowEnd, ColBegin = arrowPointColEnd }, }; arrowPoints = arrowPoints.OrderBy(x => x.ColBegin).OrderBy(y => y.RowBegin).ToList(); for (int i = 0; i < _ROIModelPoints.Count; i++) window.DispLine(arrowPoints[i].RowBegin, arrowPoints[i].ColBegin, _ROIModelPoints[i].RowBegin, _ROIModelPoints[i].ColBegin); } //reset Style HOperatorSet.SetLineStyle(window, null); //畫ROI window.SetLineWidth(1); if (!this.IsActive) HOperatorSet.SetColor(window, "magenta"); for (var i = 0; i < _dependROIModels.Count; i++) { var line = _dependROIModels[i]; if (isLine(line)) { //draw line,ROI 的線 window.DispLine(line.RowBegin, line.ColBegin, line.RowEnd, line.ColEnd); } else { //draw point,ROI 的點 HXLDCont crossPoint = new HXLDCont(); crossPoint.GenEmptyObj(); crossPoint.GenCrossContourXld(line.RowBegin, line.ColBegin, crossSize, crossAngle); crossPoint.DispObj(window); //window.DispCross(line.RowBegin, line.ColBegin, crossSize, crossAngle); } } }
/// <summary> /// Composes set of HALCON iconic objects to display /// measure edge results /// </summary> /// <returns>Detected measure edges</returns> public HXLDCont getMeasureResults() { HXLDCont val; HXLDCont obj = new HXLDCont(); obj.GenEmptyObj(); for (int i=0; i < mMeasureList.Count; i++) { val = ((Measurement)mMeasureList[i]).getMeasureResults(); if (val.IsInitialized()) obj = obj.ConcatObj(val); } return obj; }
public static ResultDisplayViewModel CreateDisplayViewModel(GeoDataGridViewModel model, bool textOnly, int circleDistanceSetting) { ResultDisplayViewModel viewModel = null; try { //init var dispXLD = new HXLDCont(); dispXLD.Dispose(); dispXLD.GenEmptyObj(); double posX = model.Col1, posY = model.Row1; string dispName = model.Name; switch (model.GeoType) { case ViewROI.MeasureType.Angle: break; case ViewROI.MeasureType.Circle: case ViewROI.MeasureType.PointCircle: var radius = model.Distance / circleDistanceSetting; dispXLD.GenCircleContourXld(model.Row1, model.Col1, radius, 0.0, 6.28318, "positive", 1.0); viewModel = new ResultDisplayViewModel() { DisplayText = dispName, PositionX = posX, PositionY = posY, }; break; case ViewROI.MeasureType.CrossPoint: case ViewROI.MeasureType.Point: dispXLD.GenCrossContourXld(model.Row1, model.Col1, 12, 0.785398); viewModel = new ResultDisplayViewModel() { DisplayText = dispName, PositionX = posX, PositionY = posY, }; break; case ViewROI.MeasureType.Distance: case ViewROI.MeasureType.DistanceX: case ViewROI.MeasureType.DistanceY: case ViewROI.MeasureType.FitLine: case ViewROI.MeasureType.Line: case ViewROI.MeasureType.SymmetryLine: var arrowXLD = new HXLDCont(); //dispXLD.GenContourPolygonXld(new double[] { model.Row1, model.Row2 }, new double[] { model.Col1, model.Col2 }); posX = (model.Col1 + model.Col2) / 2.0; posY = (model.Row1 + model.Row2) / 2.0; viewModel = new ResultDisplayViewModel() { DisplayText = dispName, PositionX = posX, PositionY = posY, FirstArrowX = model.Col1, FirstArrowY = model.Row1, SecArrowX = model.Col2, SecArrowY = model.Row2, }; break; } // if (!textOnly && viewModel != null) viewModel.ImageXLD = dispXLD; } catch (Exception ex) { Hanbo.Log.LogManager.Error(ex); } return viewModel; }
/// <summary> /// 圓的顯示模式,文字顯示在圓心 /// </summary> /// <returns></returns> public override ResultDisplayViewModel CreateDisplayViewModel() { var dispXLD = new HXLDCont(); dispXLD.Dispose(); dispXLD.GenEmptyObj(); var row = 0.0; var col = 0.0; for (int i = 0; i < this.Row.Length; i++) { var radius = this.Radius[i].D; dispXLD.GenCircleContourXld(this.Row[i].D, this.Col[i].D, radius, 0.0, 6.28318, "positive", 1.0); row = this.Row[0].D; col = this.Col[0].D; } return new ResultDisplayViewModel() { ImageXLD = dispXLD, PositionX = col, PositionY = row, }; }
private void drawOuterArc(HalconDotNet.HWindow window) { double sPhi, extent, innerRad, outerRad; HTuple innerR, outerR, innerC, outerC; HXLDCont outCont, innerCont, contour; outCont = new HXLDCont(); innerCont = new HXLDCont(); var roiModel = this.getModelData(); var mMeasROI = genArcRegionModel(roiModel); sPhi = mMeasROI[2]; extent = mMeasROI[3]; outerRad = mMeasROI[4]; innerRad = mMeasROI[5]; //畫內圓 innerCont.GenCircleContourXld(mMeasROI[0], mMeasROI[1], innerRad, sPhi, (sPhi + extent), (extent > 0) ? "positive" : "negative", 1.0); //畫外圓 outCont.GenCircleContourXld(mMeasROI[0], mMeasROI[1], outerRad, (sPhi + extent), sPhi, (extent > 0) ? "negative" : "positive", 1.0); innerCont.GetContourXld(out innerR, out innerC); outCont.GetContourXld(out outerR, out outerC); innerR = innerR.TupleConcat(outerR); innerC = innerC.TupleConcat(outerC); contour = new HXLDCont(innerR, innerC); contour = contour.CloseContoursXld(); _ArcRegion.Dispose(); _ArcRegion = contour.GenRegionContourXld("margin"); window.DispObj(_ArcRegion); contour.Dispose(); innerCont.Dispose(); outCont.Dispose(); }
/// <summary>Constructor</summary> public MatchingResult() { hmat = new HHomMat2D(); mContResults = new HXLDCont(); }
private void init() { //default value CanCalibFlag = 1; //labeled as 'for not having been evaluated' PlateStatus = CalibrationAssistant.PS_NOT_FOUND;// "No Plate found" yet _mEstimatedPlateSize = 0; ErrorMessage = ""; //Image width and height string tmp; _mImage.GetImagePointer1(out tmp, out Width, out Height); // initialize all instances _mCaltabRegion = new HRegion(); _mMarkCenter = new HXLDCont(); _mEstimatedWCS = new HObject(); _mQualityIssuesList = new ArrayList(15); _mMarkCenterRows = new HTuple(); _mMarkCenterCols = new HTuple(); _mEstimatedPose = new HPose(); }
/// <summary> /// 顯示 Measure 的幾何元素外觀 /// </summary> public override void UpdateXLD() { //clear mEdgeXLD.Dispose(); mEdgeXLD.GenEmptyObj(); var size = 15; var angle = 0.735398; if (_Result == null) return; if (_Result.Row1 == null) return; if (_Result.Row1.Length > 0) { for (int i = 0; i < _Result.Row1.Length; i++) { var pointXLD = new HXLDCont(); pointXLD.GenCrossContourXld(_Result.Row1[i].D, _Result.Col1[i].D, size, angle); //output mEdgeXLD = mEdgeXLD.ConcatObj(pointXLD); } } }
/// <summary> /// Initializes all status flags and objects to set up /// this image for the calibration process /// </summary> /// <param name="img">Calibration image</param> /// <param name="assist">Reference to the Calibration Assistant</param> public CalibImage(HImage img, CalibrationAssistant assist) { string tmp; mImage = img; mAssistant = assist; mCanCalib = 1; //labeled as 'for not having been evaluated' mPlateStatus = CalibrationAssistant.PS_NOT_FOUND;// "No Plate found" yet mImage.GetImagePointer1(out tmp, out mWidth, out mHeight); mEstimatedPlateSize = 0; mErrorMessage = ""; // initialize all instances mCaltabRegion = new HRegion(); mMarkCenter = new HXLDCont(); mEstimatedWCS = new HObject(); mQualityIssuesList = new ArrayList(15); mMarkCenterRows = new HTuple(); mMarkCenterCols = new HTuple(); mEstimatedPose = new HPose (); }
/// <summary> /// Creates the iconic object for displaying a measured /// edge from the coordinates of the end points. /// </summary> /// <returns>Contour depicting the measured edge</returns> public static HXLDCont DetermineLine(double row1, double col1, double row2, double col2) { HXLDCont edge = new HXLDCont(); HTuple rows, cols; rows = new HTuple(new double[] { row1, row2 }); cols = new HTuple(new double[] { col1, col2 }); edge.GenContourPolygonXld(rows, cols); return edge; }
/// <summary> /// 顯示 Measure 的幾何元素外觀 /// </summary> public override void UpdateXLD() { //clear mEdgeXLD.Dispose(); mEdgeXLD.GenEmptyObj(); if (_Result == null) return; if (_Result.Row1 == null) return; if (_Result.Row1.Length > 0) { var rows = new double[] { _Result.Row1, _Result.Row2 }; var cols = new double[] { _Result.Col1, _Result.Col2 }; var pointXLD = new HXLDCont(); pointXLD.GenContourPolygonXld(rows, cols); //output mEdgeXLD = mEdgeXLD.ConcatObj(pointXLD); } }
/// <summary> /// If calibration data is available and valid, then transform the /// distance between measure result edges into world coordinates, /// else leave them the same. /// </summary> public HTuple Distance(HTuple row1, HTuple col1, HTuple row2, HTuple col2, int shift) { HTuple rows, cols, rowRect, colRect; HTuple distance = new HTuple(); HXLDCont contour; if (shift == 0) { if (mROIType == ROI.ROI_TYPE_CIRCLEARC) { double cRow, cCol, radius, extent, phi1, phi2, phi, res, length, tmp; cRow = mROICoord[0].D; cCol = mROICoord[1].D; radius = mROICoord[2].D; extent = mROICoord[4].D; HOperatorSet.TupleGenConst(new HTuple(row1.Length), 0.0, out distance); for (int i=0; i < distance.Length; i++) { phi1 = HMisc.AngleLx(cRow, cCol, row1[i].D, col1[i].D); phi2 = HMisc.AngleLx(cRow, cCol, row2[i].D, col2[i].D); if (extent < 0) { tmp = phi1; phi1 = phi2; phi2 = tmp; } phi = phi2 - phi1; if (phi < 0) phi += 2 * Math.PI; res = 0.05 * 24.0 / (radius * phi); contour = new HXLDCont(); contour.GenEllipseContourXld(cRow, cCol, 0, radius, radius, phi1, phi2, "positive", res); contour.GetContourXld(out rows, out cols); Rectify(rows, cols, out rowRect, out colRect); contour.Dispose(); contour.GenContourPolygonXld(rowRect, colRect); length = contour.LengthXld(); distance[i].D = length; contour.Dispose(); } } else if (mROIType == ROI.ROI_TYPE_LINE) { HTuple rRect1, cRect1, rRect2, cRect2; Rectify(row1, col1, out rRect1, out cRect1); Rectify(row2, col2, out rRect2, out cRect2); distance = HMisc.DistancePp(rRect1, cRect1, rRect2, cRect2); } return distance; } else { HTuple rClip1, cClip1, rShift2, cShift2; rClip1 = row1.TupleSelectRange(new HTuple(0), new HTuple(row1.Length - shift - 1)); cClip1 = col1.TupleSelectRange(new HTuple(0), new HTuple(col1.Length - shift - 1)); rShift2 = row2.TupleSelectRange(new HTuple(shift), new HTuple(row2.Length - 1)); cShift2 = col2.TupleSelectRange(new HTuple(shift), new HTuple(col2.Length - 1)); return this.Distance(rClip1, cClip1, rShift2, cShift2, 0); } }
/// <summary> /// Adds visual effects (shadows) /// to the measure results. /// </summary> /// <param name="edges"> /// Add shadows along the edges provided /// </param> public void UpdateShadowContours(HObject edges) { double shift; HXLDCont shadow1, shadow2; HHomMat2D hom2D = new HHomMat2D(); mShadow.Dispose(); mShadow.GenEmptyObj(); shift = Math.Min(0.5 * lineWidth, 2.0); hom2D.HomMat2dIdentity(); hom2D = hom2D.HomMat2dTranslate(shift, 1); shadow1 = ((HXLDCont)edges).AffineTransContourXld(hom2D); hom2D.HomMat2dIdentity(); hom2D = hom2D.HomMat2dTranslate(1, shift); shadow2 = ((HXLDCont)edges).AffineTransContourXld(hom2D); mShadow = mShadow.ConcatObj(shadow1); mShadow = mShadow.ConcatObj(shadow2); shadow1.Dispose(); shadow2.Dispose(); }
/// <summary> /// Composes set of HALCON iconic objects to display /// measure edge results /// </summary> /// <returns>Detected measure edges</returns> public HXLDCont getMeasureResults() { HXLDCont val; HXLDCont obj = new HXLDCont(); obj.GenEmptyObj(); for (int i = 0; i < mMeasureList.Count; i++) { var mMeasure = ((Measurement)mMeasureList[i]); /* 是否顯示量測的圖形 var roi = mMeasure.GetMeasureROI(); if (!roi.Visiable) continue; */ val = mMeasure.getMeasureResults(); if (val.IsInitialized()) obj = obj.ConcatObj(val); } return obj; }
/// <summary> /// 顯示 Measure 的幾何元素外觀 /// </summary> public override void UpdateXLD() { //clear display mEdgeXLD.Dispose(); mEdgeXLD.GenEmptyObj(); if (mResult.Row1 == null || mResult.Row1.TupleLength() == 0) return; HXLDCont edge = new HXLDCont(); var rows = new HTuple(new double[] { mResult.Row1, mResult.Row2 }); var cols = new HTuple(new double[] { mResult.Col1, mResult.Col2 }); edge.GenContourPolygonXld(rows, cols); mEdgeXLD = mEdgeXLD.ConcatObj(edge); }