/// <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 void buttonCalib_Click(object sender, EventArgs e) { if (this.cTextBoxDesc.Text == "") { MessageBox.Show("请选择标定描述文件!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } try { int referenceIndex = this.listBox1.SelectedIndex; var hv_StartParameters = new HTuple(); var hv_TmpCtrl_FindCalObjParNames = new HTuple(); var hv_TmpCtrl_FindCalObjParValues = new HTuple(); hv_StartParameters[0] = 0.001 * float.Parse(this.cTextBoxFocus.Text); hv_StartParameters[1] = 0; hv_StartParameters[2] = 1e-6 * float.Parse(this.cTextBoxSx.Text); hv_StartParameters[3] = 1e-6 * float.Parse(this.cTextBoxSy.Text); hv_StartParameters[4] = this.width / 2; hv_StartParameters[5] = this.height / 2; hv_StartParameters[6] = this.width; hv_StartParameters[7] = this.height; hv_TmpCtrl_FindCalObjParNames[0] = "gap_tolerance"; hv_TmpCtrl_FindCalObjParNames[1] = "alpha"; hv_TmpCtrl_FindCalObjParNames[2] = "skip_find_caltab"; hv_TmpCtrl_FindCalObjParValues[0] = 1; hv_TmpCtrl_FindCalObjParValues[1] = 1; hv_TmpCtrl_FindCalObjParValues[2] = "false"; using (var hv_CalibHandle = new HCalibData("calibration_object", 1, 1)) { hv_CalibHandle.SetCalibDataCamParam(0, "area_scan_division", hv_StartParameters); hv_CalibHandle.SetCalibDataCalibObject(0, this.cTextBoxDesc.Text); for (var i = 0; i < this._images.Count; i++) { hv_CalibHandle.FindCalibObject(this._images[i], 0, 0, i, hv_TmpCtrl_FindCalObjParNames, hv_TmpCtrl_FindCalObjParValues); } hv_CalibHandle.SetCalibData("camera", new HTuple(0), "excluded_settings", new HTuple("sx", "sy", "cx", "cy")); this.Errors = hv_CalibHandle.CalibrateCameras(); this.CameraParameters = hv_CalibHandle.GetCalibData("camera", 0, "params"); this.CameraPose = new HPose(hv_CalibHandle.GetCalibData("calib_obj_pose", new HTuple(0, referenceIndex), new HTuple("pose"))); } } catch (Exception ex) { MessageBox.Show($"出现错误:{ex.Message},请检查标定数据!", "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } this.buttonSave.Enabled = this.Errors > 0 && this.Errors < 1; if (this.Errors < 1) { MessageBox.Show($"标定成功!误差为{this.Errors:f}pixel,请保存!", "标定成功", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Set the pose of a 3D scene. /// Instance represents: Handle of the 3D scene. /// </summary> /// <param name="toWorldPose">New pose of the 3D scene.</param> public void SetScene3dToWorldPose(HPose toWorldPose) { IntPtr proc = HalconAPI.PreCall(1205); this.Store(proc, 0); HalconAPI.Store(proc, 1, (HData)toWorldPose); int procResult = HalconAPI.CallProcedure(proc); HalconAPI.UnpinTuple((HTuple)((HData)toWorldPose)); HalconAPI.PostCall(proc, procResult); GC.KeepAlive((object)this); }
/// <summary> /// Set the pose of a camera in a 3D scene. /// Instance represents: Handle of the 3D scene. /// </summary> /// <param name="cameraIndex">Index of the camera.</param> /// <param name="pose">New pose of the camera.</param> public void SetScene3dCameraPose(int cameraIndex, HPose pose) { IntPtr proc = HalconAPI.PreCall(1210); this.Store(proc, 0); HalconAPI.StoreI(proc, 1, cameraIndex); HalconAPI.Store(proc, 2, (HData)pose); int procResult = HalconAPI.CallProcedure(proc); HalconAPI.UnpinTuple((HTuple)((HData)pose)); HalconAPI.PostCall(proc, procResult); GC.KeepAlive((object)this); }
/// <summary> /// Convert a 3D pose to a unit dual quaternion. /// Modified instance represents: Unit dual quaternion. /// </summary> /// <param name="pose">3D pose.</param> public void PoseToDualQuat(HPose pose) { IntPtr proc = HalconAPI.PreCall(2080); HalconAPI.Store(proc, 0, (HData)pose); HalconAPI.InitOCT(proc, 0); int err = HalconAPI.CallProcedure(proc); HalconAPI.UnpinTuple((HTuple)((HData)pose)); int procResult = this.Load(proc, 0, err); HalconAPI.PostCall(proc, procResult); GC.KeepAlive((object)this); }
/// <summary>Convert a dual quaternion to a 3D pose.</summary> /// <param name="dualQuaternion">Unit dual quaternion.</param> /// <returns>3D pose.</returns> public static HPose[] DualQuatToPose(HDualQuaternion[] dualQuaternion) { HTuple htuple = HData.ConcatArray((HData[])dualQuaternion); IntPtr proc = HalconAPI.PreCall(2064); HalconAPI.Store(proc, 0, htuple); HalconAPI.InitOCT(proc, 0); int err = HalconAPI.CallProcedure(proc); HalconAPI.UnpinTuple(htuple); HTuple tuple; int procResult = HTuple.LoadNew(proc, 0, err, out tuple); HalconAPI.PostCall(proc, procResult); return(HPose.SplitArray(tuple)); }
/// <summary> /// Convert a homogeneous transformation matrix into a 3D pose. /// Instance represents: Homogeneous transformation matrix. /// </summary> /// <returns>Equivalent 3D pose.</returns> public HPose HomMat3dToPose() { IntPtr proc = HalconAPI.PreCall(1934); this.Store(proc, 0); HalconAPI.InitOCT(proc, 0); int err = HalconAPI.CallProcedure(proc); this.UnpinTuple(); HPose hpose; int procResult = HPose.LoadNew(proc, 0, err, out hpose); HalconAPI.PostCall(proc, procResult); GC.KeepAlive((object)this); return(hpose); }
/// <summary> /// Get observed calibration object poses from a calibration data model. /// Instance represents: Handle of a calibration data model. /// </summary> /// <param name="cameraIdx">Index of the observing camera. Default: 0</param> /// <param name="calibObjIdx">Index of the observed calibration object. Default: 0</param> /// <param name="calibObjPoseIdx">Index of the observed calibration object pose. Default: 0</param> /// <returns>Stored observed calibration object pose relative to the observing camera.</returns> public HPose GetCalibDataObservPose(int cameraIdx, int calibObjIdx, int calibObjPoseIdx) { IntPtr proc = HalconAPI.PreCall(1972); this.Store(proc, 0); HalconAPI.StoreI(proc, 1, cameraIdx); HalconAPI.StoreI(proc, 2, calibObjIdx); HalconAPI.StoreI(proc, 3, calibObjPoseIdx); HalconAPI.InitOCT(proc, 0); int err = HalconAPI.CallProcedure(proc); HPose hpose; int procResult = HPose.LoadNew(proc, 0, err, out hpose); HalconAPI.PostCall(proc, procResult); GC.KeepAlive((object)this); return(hpose); }
/// <summary> /// Find the best matches of a calibrated descriptor model in an image and return their 3D pose. /// Instance represents: The handle to the descriptor model. /// </summary> /// <param name="image">Input image where the model should be found.</param> /// <param name="detectorParamName">The detector's parameter names. Default: []</param> /// <param name="detectorParamValue">Values of the detector's parameters. Default: []</param> /// <param name="descriptorParamName">The descriptor's parameter names. Default: []</param> /// <param name="descriptorParamValue">Values of the descriptor's parameters. Default: []</param> /// <param name="minScore">Minimum score of the instances of the models to be found. Default: 0.2</param> /// <param name="numMatches">Maximal number of found instances. Default: 1</param> /// <param name="camParam">Camera parameter (inner orientation) obtained from camera calibration.</param> /// <param name="scoreType">Score type to be evaluated in Score. Default: "num_points"</param> /// <param name="score">Score of the found instances according to the ScoreType input.</param> /// <returns>3D pose of the object.</returns> public HPose[] FindCalibDescriptorModel( HImage image, HTuple detectorParamName, HTuple detectorParamValue, HTuple descriptorParamName, HTuple descriptorParamValue, HTuple minScore, int numMatches, HCamPar camParam, HTuple scoreType, out HTuple score) { IntPtr proc = HalconAPI.PreCall(948); this.Store(proc, 0); HalconAPI.Store(proc, 1, (HObjectBase)image); HalconAPI.Store(proc, 1, detectorParamName); HalconAPI.Store(proc, 2, detectorParamValue); HalconAPI.Store(proc, 3, descriptorParamName); HalconAPI.Store(proc, 4, descriptorParamValue); HalconAPI.Store(proc, 5, minScore); HalconAPI.StoreI(proc, 6, numMatches); HalconAPI.Store(proc, 7, (HData)camParam); HalconAPI.Store(proc, 8, scoreType); HalconAPI.InitOCT(proc, 0); HalconAPI.InitOCT(proc, 1); int err1 = HalconAPI.CallProcedure(proc); HalconAPI.UnpinTuple(detectorParamName); HalconAPI.UnpinTuple(detectorParamValue); HalconAPI.UnpinTuple(descriptorParamName); HalconAPI.UnpinTuple(descriptorParamValue); HalconAPI.UnpinTuple(minScore); HalconAPI.UnpinTuple((HTuple)((HData)camParam)); HalconAPI.UnpinTuple(scoreType); HTuple tuple; int err2 = HTuple.LoadNew(proc, 0, err1, out tuple); int procResult = HTuple.LoadNew(proc, 1, err2, out score); HalconAPI.PostCall(proc, procResult); HPose[] hposeArray = HPose.SplitArray(tuple); GC.KeepAlive((object)this); GC.KeepAlive((object)image); return(hposeArray); }
/// <summary> /// Return the contour representation of a 3D shape model view. /// Instance represents: Handle of the 3D shape model. /// </summary> /// <param name="level">Pyramid level for which the contour representation should be returned. Default: 1</param> /// <param name="view">View for which the contour representation should be returned. Default: 1</param> /// <param name="viewPose">3D pose of the 3D shape model at the current view.</param> /// <returns>Contour representation of the model view.</returns> public HXLDCont GetShapeModel3dContours(int level, int view, out HPose viewPose) { IntPtr proc = HalconAPI.PreCall(1056); this.Store(proc, 0); HalconAPI.StoreI(proc, 1, level); HalconAPI.StoreI(proc, 2, view); HalconAPI.InitOCT(proc, 1); HalconAPI.InitOCT(proc, 0); int err1 = HalconAPI.CallProcedure(proc); HXLDCont hxldCont; int err2 = HXLDCont.LoadNew(proc, 1, err1, out hxldCont); int procResult = HPose.LoadNew(proc, 0, err2, out viewPose); HalconAPI.PostCall(proc, procResult); GC.KeepAlive((object)this); return(hxldCont); }
/// <summary> /// Transform a pose that refers to the coordinate system of a 3D object model to a pose that refers to the reference coordinate system of a 3D shape model and vice versa. /// Instance represents: Handle of the 3D shape model. /// </summary> /// <param name="poseIn">Pose to be transformed in the source system.</param> /// <param name="transformation">Direction of the transformation. Default: "ref_to_model"</param> /// <returns>Transformed 3D pose in the target system.</returns> public HPose TransPoseShapeModel3d(HPose poseIn, string transformation) { IntPtr proc = HalconAPI.PreCall(1054); this.Store(proc, 0); HalconAPI.Store(proc, 1, (HData)poseIn); HalconAPI.StoreS(proc, 2, transformation); HalconAPI.InitOCT(proc, 0); int err = HalconAPI.CallProcedure(proc); HalconAPI.UnpinTuple((HTuple)((HData)poseIn)); HPose hpose; int procResult = HPose.LoadNew(proc, 0, err, out hpose); HalconAPI.PostCall(proc, procResult); GC.KeepAlive((object)this); return(hpose); }
/// <summary>Refine the pose of a surface model in a 3D scene and in images.</summary> /// <param name="image">Images of the scene.</param> /// <param name="surfaceModelID">Handle of the surface model.</param> /// <param name="objectModel3D">Handle of the 3D object model containing the scene.</param> /// <param name="initialPose">Initial pose of the surface model in the scene.</param> /// <param name="minScore">Minimum score of the returned poses. Default: 0</param> /// <param name="returnResultHandle">Enable returning a result handle in SurfaceMatchingResultID. Default: "false"</param> /// <param name="genParamName">Names of the generic parameters. Default: []</param> /// <param name="genParamValue">Values of the generic parameters. Default: []</param> /// <param name="score">Score of the found instances of the model.</param> /// <param name="surfaceMatchingResultID">Handle of the matching result, if enabled in ReturnResultHandle.</param> /// <returns>3D pose of the surface model in the scene.</returns> public static HPose[] RefineSurfaceModelPoseImage( HImage image, HSurfaceModel surfaceModelID, HObjectModel3D objectModel3D, HPose[] initialPose, HTuple minScore, string returnResultHandle, HTuple genParamName, HTuple genParamValue, out HTuple score, out HSurfaceMatchingResult[] surfaceMatchingResultID) { HTuple htuple = HData.ConcatArray((HData[])initialPose); IntPtr proc = HalconAPI.PreCall(2084); HalconAPI.Store(proc, 1, (HObjectBase)image); HalconAPI.Store(proc, 0, (HTool)surfaceModelID); HalconAPI.Store(proc, 1, (HTool)objectModel3D); HalconAPI.Store(proc, 2, htuple); HalconAPI.Store(proc, 3, minScore); HalconAPI.StoreS(proc, 4, returnResultHandle); HalconAPI.Store(proc, 5, genParamName); HalconAPI.Store(proc, 6, genParamValue); HalconAPI.InitOCT(proc, 0); HalconAPI.InitOCT(proc, 1); HalconAPI.InitOCT(proc, 2); int err1 = HalconAPI.CallProcedure(proc); HalconAPI.UnpinTuple(htuple); HalconAPI.UnpinTuple(minScore); HalconAPI.UnpinTuple(genParamName); HalconAPI.UnpinTuple(genParamValue); HTuple tuple; int err2 = HTuple.LoadNew(proc, 0, err1, out tuple); int err3 = HTuple.LoadNew(proc, 1, HTupleType.DOUBLE, err2, out score); int procResult = HSurfaceMatchingResult.LoadNew(proc, 2, err3, out surfaceMatchingResultID); HalconAPI.PostCall(proc, procResult); HPose[] hposeArray = HPose.SplitArray(tuple); GC.KeepAlive((object)image); GC.KeepAlive((object)surfaceModelID); GC.KeepAlive((object)objectModel3D); return(hposeArray); }
/// <summary>Find the best matches of a surface model in a 3D scene and images.</summary> /// <param name="image">Images of the scene.</param> /// <param name="surfaceModelID">Handle of the surface model.</param> /// <param name="objectModel3D">Handle of the 3D object model containing the scene.</param> /// <param name="relSamplingDistance">Scene sampling distance relative to the diameter of the surface model. Default: 0.05</param> /// <param name="keyPointFraction">Fraction of sampled scene points used as key points. Default: 0.2</param> /// <param name="minScore">Minimum score of the returned poses. Default: 0</param> /// <param name="returnResultHandle">Enable returning a result handle in SurfaceMatchingResultID. Default: "false"</param> /// <param name="genParamName">Names of the generic parameters. Default: []</param> /// <param name="genParamValue">Values of the generic parameters. Default: []</param> /// <param name="score">Score of the found instances of the surface model.</param> /// <param name="surfaceMatchingResultID">Handle of the matching result, if enabled in ReturnResultHandle.</param> /// <returns>3D pose of the surface model in the scene.</returns> public static HPose[] FindSurfaceModelImage( HImage image, HSurfaceModel surfaceModelID, HObjectModel3D objectModel3D, double relSamplingDistance, double keyPointFraction, HTuple minScore, string returnResultHandle, HTuple genParamName, HTuple genParamValue, out HTuple score, out HSurfaceMatchingResult[] surfaceMatchingResultID) { IntPtr proc = HalconAPI.PreCall(2069); HalconAPI.Store(proc, 1, (HObjectBase)image); HalconAPI.Store(proc, 0, (HTool)surfaceModelID); HalconAPI.Store(proc, 1, (HTool)objectModel3D); HalconAPI.StoreD(proc, 2, relSamplingDistance); HalconAPI.StoreD(proc, 3, keyPointFraction); HalconAPI.Store(proc, 4, minScore); HalconAPI.StoreS(proc, 5, returnResultHandle); HalconAPI.Store(proc, 6, genParamName); HalconAPI.Store(proc, 7, genParamValue); HalconAPI.InitOCT(proc, 0); HalconAPI.InitOCT(proc, 1); HalconAPI.InitOCT(proc, 2); int err1 = HalconAPI.CallProcedure(proc); HalconAPI.UnpinTuple(minScore); HalconAPI.UnpinTuple(genParamName); HalconAPI.UnpinTuple(genParamValue); HTuple tuple; int err2 = HTuple.LoadNew(proc, 0, err1, out tuple); int err3 = HTuple.LoadNew(proc, 1, HTupleType.DOUBLE, err2, out score); int procResult = HSurfaceMatchingResult.LoadNew(proc, 2, err3, out surfaceMatchingResultID); HalconAPI.PostCall(proc, procResult); HPose[] hposeArray = HPose.SplitArray(tuple); GC.KeepAlive((object)image); GC.KeepAlive((object)surfaceModelID); GC.KeepAlive((object)objectModel3D); return(hposeArray); }
/// <summary> /// Set observed calibration object poses in a calibration data model. /// Instance represents: Handle of a calibration data model. /// </summary> /// <param name="cameraIdx">Index of the observing camera. Default: 0</param> /// <param name="calibObjIdx">Index of the calibration object. Default: 0</param> /// <param name="calibObjPoseIdx">Index of the observed calibration object. Default: 0</param> /// <param name="objInCameraPose">Pose of the observed calibration object relative to the observing camera.</param> public void SetCalibDataObservPose( int cameraIdx, int calibObjIdx, int calibObjPoseIdx, HPose objInCameraPose) { IntPtr proc = HalconAPI.PreCall(1973); this.Store(proc, 0); HalconAPI.StoreI(proc, 1, cameraIdx); HalconAPI.StoreI(proc, 2, calibObjIdx); HalconAPI.StoreI(proc, 3, calibObjPoseIdx); HalconAPI.Store(proc, 4, (HData)objInCameraPose); int procResult = HalconAPI.CallProcedure(proc); HalconAPI.UnpinTuple((HTuple)((HData)objInCameraPose)); HalconAPI.PostCall(proc, procResult); GC.KeepAlive((object)this); }
/// <summary> /// Add an instance of a 3D object model to a 3D scene. /// Instance represents: Handle of the 3D scene. /// </summary> /// <param name="objectModel3D">Handle of the 3D object model.</param> /// <param name="pose">Pose of the 3D object model.</param> /// <returns>Index of the new instance in the 3D scene.</returns> public int AddScene3dInstance(HObjectModel3D objectModel3D, HPose pose) { IntPtr proc = HalconAPI.PreCall(1217); this.Store(proc, 0); HalconAPI.Store(proc, 1, (HTool)objectModel3D); HalconAPI.Store(proc, 2, (HData)pose); HalconAPI.InitOCT(proc, 0); int err = HalconAPI.CallProcedure(proc); HalconAPI.UnpinTuple((HTuple)((HData)pose)); int intValue; int procResult = HalconAPI.LoadI(proc, 0, err, out intValue); HalconAPI.PostCall(proc, procResult); GC.KeepAlive((object)this); GC.KeepAlive((object)objectModel3D); return(intValue); }
/// <summary> /// Refine the pose of a surface model in a 3D scene and in images. /// Modified instance represents: Handle of the matching result, if enabled in ReturnResultHandle. /// </summary> /// <param name="image">Images of the scene.</param> /// <param name="surfaceModelID">Handle of the surface model.</param> /// <param name="objectModel3D">Handle of the 3D object model containing the scene.</param> /// <param name="initialPose">Initial pose of the surface model in the scene.</param> /// <param name="minScore">Minimum score of the returned poses. Default: 0</param> /// <param name="returnResultHandle">Enable returning a result handle in SurfaceMatchingResultID. Default: "false"</param> /// <param name="genParamName">Names of the generic parameters. Default: []</param> /// <param name="genParamValue">Values of the generic parameters. Default: []</param> /// <param name="score">Score of the found instances of the model.</param> /// <returns>3D pose of the surface model in the scene.</returns> public HPose RefineSurfaceModelPoseImage( HImage image, HSurfaceModel surfaceModelID, HObjectModel3D objectModel3D, HPose initialPose, double minScore, string returnResultHandle, HTuple genParamName, HTuple genParamValue, out HTuple score) { this.Dispose(); IntPtr proc = HalconAPI.PreCall(2084); HalconAPI.Store(proc, 1, (HObjectBase)image); HalconAPI.Store(proc, 0, (HTool)surfaceModelID); HalconAPI.Store(proc, 1, (HTool)objectModel3D); HalconAPI.Store(proc, 2, (HData)initialPose); HalconAPI.StoreD(proc, 3, minScore); HalconAPI.StoreS(proc, 4, returnResultHandle); HalconAPI.Store(proc, 5, genParamName); HalconAPI.Store(proc, 6, genParamValue); HalconAPI.InitOCT(proc, 2); HalconAPI.InitOCT(proc, 0); HalconAPI.InitOCT(proc, 1); int err1 = HalconAPI.CallProcedure(proc); HalconAPI.UnpinTuple((HTuple)((HData)initialPose)); HalconAPI.UnpinTuple(genParamName); HalconAPI.UnpinTuple(genParamValue); int err2 = this.Load(proc, 2, err1); HPose hpose; int err3 = HPose.LoadNew(proc, 0, err2, out hpose); int procResult = HTuple.LoadNew(proc, 1, HTupleType.DOUBLE, err3, out score); HalconAPI.PostCall(proc, procResult); GC.KeepAlive((object)this); GC.KeepAlive((object)image); GC.KeepAlive((object)surfaceModelID); GC.KeepAlive((object)objectModel3D); return(hpose); }
/// <summary> /// Find the best matches of a surface model in a 3D scene. /// Modified instance represents: Handle of the matching result, if enabled in ReturnResultHandle. /// </summary> /// <param name="surfaceModelID">Handle of the surface model.</param> /// <param name="objectModel3D">Handle of the 3D object model containing the scene.</param> /// <param name="relSamplingDistance">Scene sampling distance relative to the diameter of the surface model. Default: 0.05</param> /// <param name="keyPointFraction">Fraction of sampled scene points used as key points. Default: 0.2</param> /// <param name="minScore">Minimum score of the returned poses. Default: 0</param> /// <param name="returnResultHandle">Enable returning a result handle in SurfaceMatchingResultID. Default: "false"</param> /// <param name="genParamName">Names of the generic parameters. Default: []</param> /// <param name="genParamValue">Values of the generic parameters. Default: []</param> /// <param name="score">Score of the found instances of the surface model.</param> /// <returns>3D pose of the surface model in the scene.</returns> public HPose FindSurfaceModel( HSurfaceModel surfaceModelID, HObjectModel3D objectModel3D, double relSamplingDistance, double keyPointFraction, double minScore, string returnResultHandle, HTuple genParamName, HTuple genParamValue, out HTuple score) { this.Dispose(); IntPtr proc = HalconAPI.PreCall(1042); HalconAPI.Store(proc, 0, (HTool)surfaceModelID); HalconAPI.Store(proc, 1, (HTool)objectModel3D); HalconAPI.StoreD(proc, 2, relSamplingDistance); HalconAPI.StoreD(proc, 3, keyPointFraction); HalconAPI.StoreD(proc, 4, minScore); HalconAPI.StoreS(proc, 5, returnResultHandle); HalconAPI.Store(proc, 6, genParamName); HalconAPI.Store(proc, 7, genParamValue); HalconAPI.InitOCT(proc, 2); HalconAPI.InitOCT(proc, 0); HalconAPI.InitOCT(proc, 1); int err1 = HalconAPI.CallProcedure(proc); HalconAPI.UnpinTuple(genParamName); HalconAPI.UnpinTuple(genParamValue); int err2 = this.Load(proc, 2, err1); HPose hpose; int err3 = HPose.LoadNew(proc, 0, err2, out hpose); int procResult = HTuple.LoadNew(proc, 1, HTupleType.DOUBLE, err3, out score); HalconAPI.PostCall(proc, procResult); GC.KeepAlive((object)this); GC.KeepAlive((object)surfaceModelID); GC.KeepAlive((object)objectModel3D); return(hpose); }
/// <summary> /// Find the best matches of a 3D shape model in an image. /// Instance represents: Handle of the 3D shape model. /// </summary> /// <param name="image">Input image in which the model should be found.</param> /// <param name="minScore">Minimum score of the instances of the model to be found. Default: 0.7</param> /// <param name="greediness">"Greediness" of the search heuristic (0: safe but slow; 1: fast but matches may be missed). Default: 0.9</param> /// <param name="numLevels">Number of pyramid levels used in the matching (and lowest pyramid level to use if $|NumLevels| = 2$). Default: 0</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="covPose">6 standard deviations or 36 covariances of the pose parameters.</param> /// <param name="score">Score of the found instances of the 3D shape model.</param> /// <returns>3D pose of the 3D shape model.</returns> public HPose[] FindShapeModel3d( HImage image, double minScore, double greediness, HTuple numLevels, HTuple genParamName, HTuple genParamValue, out HTuple covPose, out HTuple score) { IntPtr proc = HalconAPI.PreCall(1058); this.Store(proc, 0); HalconAPI.Store(proc, 1, (HObjectBase)image); HalconAPI.StoreD(proc, 1, minScore); HalconAPI.StoreD(proc, 2, greediness); HalconAPI.Store(proc, 3, numLevels); HalconAPI.Store(proc, 4, genParamName); HalconAPI.Store(proc, 5, genParamValue); HalconAPI.InitOCT(proc, 0); HalconAPI.InitOCT(proc, 1); HalconAPI.InitOCT(proc, 2); int err1 = HalconAPI.CallProcedure(proc); HalconAPI.UnpinTuple(numLevels); HalconAPI.UnpinTuple(genParamName); HalconAPI.UnpinTuple(genParamValue); HTuple tuple; int err2 = HTuple.LoadNew(proc, 0, err1, out tuple); int err3 = HTuple.LoadNew(proc, 1, HTupleType.DOUBLE, err2, out covPose); int procResult = HTuple.LoadNew(proc, 2, HTupleType.DOUBLE, err3, out score); HalconAPI.PostCall(proc, procResult); HPose[] hposeArray = HPose.SplitArray(tuple); GC.KeepAlive((object)this); GC.KeepAlive((object)image); return(hposeArray); }
/// <summary> /// Create a descriptor model for calibrated perspective matching. /// Modified instance represents: The handle to the descriptor model. /// </summary> /// <param name="template">Input image whose domain will be used to create the model.</param> /// <param name="camParam">The parameters of the internal orientation of the camera.</param> /// <param name="referencePose">The reference pose of the object in the reference image.</param> /// <param name="detectorType">The type of the detector. Default: "lepetit"</param> /// <param name="detectorParamName">The detector's parameter names. Default: []</param> /// <param name="detectorParamValue">Values of the detector's parameters. Default: []</param> /// <param name="descriptorParamName">The descriptor's parameter names. Default: []</param> /// <param name="descriptorParamValue">Values of the descriptor's parameters. Default: []</param> /// <param name="seed">The seed for the random number generator. Default: 42</param> public void CreateCalibDescriptorModel( HImage template, HCamPar camParam, HPose referencePose, string detectorType, HTuple detectorParamName, HTuple detectorParamValue, HTuple descriptorParamName, HTuple descriptorParamValue, int seed) { this.Dispose(); IntPtr proc = HalconAPI.PreCall(952); HalconAPI.Store(proc, 1, (HObjectBase)template); HalconAPI.Store(proc, 0, (HData)camParam); HalconAPI.Store(proc, 1, (HData)referencePose); HalconAPI.StoreS(proc, 2, detectorType); HalconAPI.Store(proc, 3, detectorParamName); HalconAPI.Store(proc, 4, detectorParamValue); HalconAPI.Store(proc, 5, descriptorParamName); HalconAPI.Store(proc, 6, descriptorParamValue); HalconAPI.StoreI(proc, 7, seed); HalconAPI.InitOCT(proc, 0); int err = HalconAPI.CallProcedure(proc); HalconAPI.UnpinTuple((HTuple)((HData)camParam)); HalconAPI.UnpinTuple((HTuple)((HData)referencePose)); HalconAPI.UnpinTuple(detectorParamName); HalconAPI.UnpinTuple(detectorParamValue); HalconAPI.UnpinTuple(descriptorParamName); HalconAPI.UnpinTuple(descriptorParamValue); int procResult = this.Load(proc, 0, err); HalconAPI.PostCall(proc, procResult); GC.KeepAlive((object)this); GC.KeepAlive((object)template); }
/// <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(); }
private void btnCalib_Click(object sender, EventArgs e) { try { this.CameraParam = new HTuple(double.Parse(this.tbxFocus.Text), double.Parse(this.tbxKappa.Text), double.Parse(this.tbxSx.Text), double.Parse(this.tbxSy.Text), double.Parse(this.tbxCx.Text), double.Parse(this.tbxCy.Text), int.Parse(this.tbxWidth.Text), int.Parse(this.tbxHeight.Text)); this.hv_WorldX = new HTuple(); this.hv_WorldY = new HTuple(); this.hv_WorldZ = new HTuple(); this.hv_ImageRow = new HTuple(); this.hv_ImageColumn = new HTuple(); foreach (DataRow dr in this.CalData.Rows) { this.hv_WorldX = this.hv_WorldX.TupleConcat((double)dr["x"]); this.hv_WorldY = this.hv_WorldY.TupleConcat((double)dr["y"]); this.hv_WorldZ = this.hv_WorldZ.TupleConcat((double)dr["z"]); this.hv_ImageRow = this.hv_ImageRow.TupleConcat((double)dr["r"]); this.hv_ImageColumn = this.hv_ImageColumn.TupleConcat((double)dr["c"]); } this.Pose = HImage.VectorToPose(this.hv_WorldX, this.hv_WorldY, this.hv_WorldZ, this.hv_ImageRow, this.hv_ImageColumn, this.CameraParam, "planar_analytic", "error", out this.error); this.tbxTx.Text = this.Pose[0].D.ToString(CultureInfo.InvariantCulture); this.tbxTy.Text = this.Pose[1].D.ToString(CultureInfo.InvariantCulture); this.tbxTz.Text = this.Pose[2].D.ToString(CultureInfo.InvariantCulture); this.tbxAlpha.Text = this.Pose[3].D.ToString(CultureInfo.InvariantCulture); this.tbxBeta.Text = this.Pose[4].D.ToString(CultureInfo.InvariantCulture); this.tbxGamma.Text = this.Pose[5].D.ToString(CultureInfo.InvariantCulture); this.tbxType.Text = this.Pose[6].I.ToString(); this.tbxError.Text = this.Error.ToString(CultureInfo.InvariantCulture); } catch (Exception ex) { MessageBox.Show("出现错误:" + ex.Message, "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
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> /// 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 (); }
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(); }