コード例 #1
0
ファイル: HalconAPI.cs プロジェクト: zshankang/OpenHalcon
        public static void StoreIP(IntPtr proc, int parIndex, IntPtr intPtrValue)
        {
            IntPtr tuple;

            HalconAPI.HCkP(proc, HalconAPI.CreateInputTuple(proc, parIndex, 1, out tuple));
            HalconAPI.SetIP(tuple, 0, intPtrValue);
        }
コード例 #2
0
        /// <summary>Close all compute devices.</summary>
        public static void ReleaseAllComputeDevices()
        {
            IntPtr proc       = HalconAPI.PreCall(298);
            int    procResult = HalconAPI.CallProcedure(proc);

            HalconAPI.PostCall(proc, procResult);
        }
コード例 #3
0
ファイル: EngineAPI.cs プロジェクト: zshankang/OpenHalcon
        internal static void GetProgramInfo(
            IntPtr program,
            out string name,
            out bool loaded,
            out HTuple varNamesIconic,
            out HTuple varNamesCtrl,
            out HTuple varDimsIconic,
            out HTuple varDimsCtrl)
        {
            IntPtr tuple1;

            EngineAPI.HCkE(HalconAPI.CreateTuple(out tuple1));
            IntPtr tuple2;

            EngineAPI.HCkE(HalconAPI.CreateTuple(out tuple2));
            IntPtr tuple3;

            EngineAPI.HCkE(HalconAPI.CreateTuple(out tuple3));
            IntPtr tuple4;

            EngineAPI.HCkE(HalconAPI.CreateTuple(out tuple4));
            IntPtr name1;

            EngineAPI.HCkE(EngineAPI.HCenGetProgramInfo(program, out name1, out loaded, tuple1, tuple2, tuple3, tuple4));
            name           = Marshal.PtrToStringAnsi(name1);
            varNamesIconic = HalconAPI.LoadTuple(tuple1);
            varNamesCtrl   = HalconAPI.LoadTuple(tuple2);
            varDimsIconic  = HalconAPI.LoadTuple(tuple3);
            varDimsCtrl    = HalconAPI.LoadTuple(tuple4);
            EngineAPI.HCkE(HalconAPI.DestroyTuple(tuple1));
            EngineAPI.HCkE(HalconAPI.DestroyTuple(tuple2));
            EngineAPI.HCkE(HalconAPI.DestroyTuple(tuple3));
            EngineAPI.HCkE(HalconAPI.DestroyTuple(tuple4));
        }
コード例 #4
0
        /// <summary>
        ///   Searching the best grayvalue matches in a pre generated pyramid.
        ///   Instance represents: Template number.
        /// </summary>
        /// <param name="imagePyramid">Image pyramid inside of which the pattern has to be found.</param>
        /// <param name="maxError">Maximal average difference of the grayvalues. Default: 30.0</param>
        /// <param name="subPixel">Exactness in subpixels in case of 'true'. Default: "false"</param>
        /// <param name="numLevels">Number of the used resolution levels. Default: 3</param>
        /// <param name="whichLevels">Resolution level up to which the method "best match" is used. Default: "original"</param>
        /// <param name="row">Row position of the best match.</param>
        /// <param name="column">Column position of the best match.</param>
        /// <param name="error">Average divergence of the grayvalues in the best match.</param>
        public void BestMatchPreMg(
            HImage imagePyramid,
            double maxError,
            string subPixel,
            int numLevels,
            HTuple whichLevels,
            out double row,
            out double column,
            out double error)
        {
            IntPtr proc = HalconAPI.PreCall(1500);

            this.Store(proc, 0);
            HalconAPI.Store(proc, 1, (HObjectBase)imagePyramid);
            HalconAPI.StoreD(proc, 1, maxError);
            HalconAPI.StoreS(proc, 2, subPixel);
            HalconAPI.StoreI(proc, 3, numLevels);
            HalconAPI.Store(proc, 4, whichLevels);
            HalconAPI.InitOCT(proc, 0);
            HalconAPI.InitOCT(proc, 1);
            HalconAPI.InitOCT(proc, 2);
            int err1 = HalconAPI.CallProcedure(proc);

            HalconAPI.UnpinTuple(whichLevels);
            int err2       = HalconAPI.LoadD(proc, 0, err1, out row);
            int err3       = HalconAPI.LoadD(proc, 1, err2, out column);
            int procResult = HalconAPI.LoadD(proc, 2, err3, out error);

            HalconAPI.PostCall(proc, procResult);
            GC.KeepAlive((object)this);
            GC.KeepAlive((object)imagePyramid);
        }
コード例 #5
0
        /// <summary>
        ///   Searching the best matching of a template and an image with rotation.
        ///   Instance represents: Template number.
        /// </summary>
        /// <param name="image">Input image inside of which the pattern has to be found.</param>
        /// <param name="angleStart">Smallest Rotation of the pattern. Default: -0.39</param>
        /// <param name="angleExtend">Maximum positive Extension of AngleStart. Default: 0.79</param>
        /// <param name="maxError">Maximum average difference of the grayvalues. Default: 30.0</param>
        /// <param name="subPixel">Subpixel accuracy in case of 'true'. Default: "false"</param>
        /// <param name="row">Row position of the best match.</param>
        /// <param name="column">Column position of the best match.</param>
        /// <param name="angle">Rotation angle of pattern.</param>
        /// <param name="error">Average divergence of the grayvalues of the best match.</param>
        public void BestMatchRot(
            HImage image,
            double angleStart,
            double angleExtend,
            double maxError,
            string subPixel,
            out HTuple row,
            out HTuple column,
            out HTuple angle,
            out HTuple error)
        {
            IntPtr proc = HalconAPI.PreCall(1504);

            this.Store(proc, 0);
            HalconAPI.Store(proc, 1, (HObjectBase)image);
            HalconAPI.StoreD(proc, 1, angleStart);
            HalconAPI.StoreD(proc, 2, angleExtend);
            HalconAPI.StoreD(proc, 3, maxError);
            HalconAPI.StoreS(proc, 4, subPixel);
            HalconAPI.InitOCT(proc, 0);
            HalconAPI.InitOCT(proc, 1);
            HalconAPI.InitOCT(proc, 2);
            HalconAPI.InitOCT(proc, 3);
            int err1       = HalconAPI.CallProcedure(proc);
            int err2       = HTuple.LoadNew(proc, 0, HTupleType.DOUBLE, err1, out row);
            int err3       = HTuple.LoadNew(proc, 1, HTupleType.DOUBLE, err2, out column);
            int err4       = HTuple.LoadNew(proc, 2, HTupleType.DOUBLE, err3, out angle);
            int procResult = HTuple.LoadNew(proc, 3, HTupleType.DOUBLE, err4, out error);

            HalconAPI.PostCall(proc, procResult);
            GC.KeepAlive((object)this);
            GC.KeepAlive((object)image);
        }
コード例 #6
0
        /// <summary>
        ///   Return the parameters of an OCR classifier.
        ///   Instance represents: Handle of the OCR classifier.
        /// </summary>
        /// <param name="widthCharacter">Width of the rectangle to which the gray values of the segmented character are zoomed.</param>
        /// <param name="heightCharacter">Height of the rectangle to which the gray values of the segmented character are zoomed.</param>
        /// <param name="interpolation">Interpolation mode for the zooming of the characters.</param>
        /// <param name="features">Features to be used for classification.</param>
        /// <param name="characters">Characters of the character set to be read.</param>
        /// <param name="preprocessing">Type of preprocessing used to transform the feature vectors.</param>
        /// <param name="numTrees">Number of different trees used during the classifcation.</param>
        public void GetParamsOcrClassKnn(
            out int widthCharacter,
            out int heightCharacter,
            out string interpolation,
            out string features,
            out HTuple characters,
            out string preprocessing,
            out int numTrees)
        {
            IntPtr proc = HalconAPI.PreCall(657);

            this.Store(proc, 0);
            HalconAPI.InitOCT(proc, 0);
            HalconAPI.InitOCT(proc, 1);
            HalconAPI.InitOCT(proc, 2);
            HalconAPI.InitOCT(proc, 3);
            HalconAPI.InitOCT(proc, 4);
            HalconAPI.InitOCT(proc, 5);
            HalconAPI.InitOCT(proc, 6);
            int err1       = HalconAPI.CallProcedure(proc);
            int err2       = HalconAPI.LoadI(proc, 0, err1, out widthCharacter);
            int err3       = HalconAPI.LoadI(proc, 1, err2, out heightCharacter);
            int err4       = HalconAPI.LoadS(proc, 2, err3, out interpolation);
            int err5       = HalconAPI.LoadS(proc, 3, err4, out features);
            int err6       = HTuple.LoadNew(proc, 4, err5, out characters);
            int err7       = HalconAPI.LoadS(proc, 5, err6, out preprocessing);
            int procResult = HalconAPI.LoadI(proc, 6, err7, out numTrees);

            HalconAPI.PostCall(proc, procResult);
            GC.KeepAlive((object)this);
        }
コード例 #7
0
        /// <summary>
        ///   Classify a single character with an OCR classifier.
        ///   Instance represents: Handle of the k-NN classifier.
        /// </summary>
        /// <param name="character">Character to be recognized.</param>
        /// <param name="image">Gray values of the character.</param>
        /// <param name="numClasses">Number of maximal classes to determine. Default: 1</param>
        /// <param name="numNeighbors">Number of neighbors to consider. Default: 1</param>
        /// <param name="confidence">Confidence(s) of the class(es) of the character.</param>
        /// <returns>Results of classifying the character with the k-NN.</returns>
        public string DoOcrSingleClassKnn(
            HRegion character,
            HImage image,
            HTuple numClasses,
            HTuple numNeighbors,
            out double confidence)
        {
            IntPtr proc = HalconAPI.PreCall(659);

            this.Store(proc, 0);
            HalconAPI.Store(proc, 1, (HObjectBase)character);
            HalconAPI.Store(proc, 2, (HObjectBase)image);
            HalconAPI.Store(proc, 1, numClasses);
            HalconAPI.Store(proc, 2, numNeighbors);
            HalconAPI.InitOCT(proc, 0);
            HalconAPI.InitOCT(proc, 1);
            int err1 = HalconAPI.CallProcedure(proc);

            HalconAPI.UnpinTuple(numClasses);
            HalconAPI.UnpinTuple(numNeighbors);
            string stringValue;
            int    err2       = HalconAPI.LoadS(proc, 0, err1, out stringValue);
            int    procResult = HalconAPI.LoadD(proc, 1, err2, out confidence);

            HalconAPI.PostCall(proc, procResult);
            GC.KeepAlive((object)this);
            GC.KeepAlive((object)character);
            GC.KeepAlive((object)image);
            return(stringValue);
        }
コード例 #8
0
        public override void Store(IntPtr proc, int parIndex)
        {
            IntPtr tuple;

            HalconAPI.HCkP(proc, HalconAPI.GetInputTuple(proc, parIndex, out tuple));
            this.StoreData(proc, tuple);
        }
コード例 #9
0
        /// <summary>
        ///   Visualize images using gnuplot.
        ///   Instance represents: Identifier for the gnuplot output stream.
        /// </summary>
        /// <param name="image">Image to be plotted.</param>
        /// <param name="samplesX">Number of samples in the x-direction. Default: 64</param>
        /// <param name="samplesY">Number of samples in the y-direction. Default: 64</param>
        /// <param name="viewRotX">Rotation of the plot about the x-axis. Default: 60</param>
        /// <param name="viewRotZ">Rotation of the plot about the z-axis. Default: 30</param>
        /// <param name="hidden3D">Plot the image with hidden surfaces removed. Default: "hidden3d"</param>
        public void GnuplotPlotImage(
            HImage image,
            int samplesX,
            int samplesY,
            HTuple viewRotX,
            HTuple viewRotZ,
            string hidden3D)
        {
            IntPtr proc = HalconAPI.PreCall(1297);

            this.Store(proc, 0);
            HalconAPI.Store(proc, 1, (HObjectBase)image);
            HalconAPI.StoreI(proc, 1, samplesX);
            HalconAPI.StoreI(proc, 2, samplesY);
            HalconAPI.Store(proc, 3, viewRotX);
            HalconAPI.Store(proc, 4, viewRotZ);
            HalconAPI.StoreS(proc, 5, hidden3D);
            int procResult = HalconAPI.CallProcedure(proc);

            HalconAPI.UnpinTuple(viewRotX);
            HalconAPI.UnpinTuple(viewRotZ);
            HalconAPI.PostCall(proc, procResult);
            GC.KeepAlive((object)this);
            GC.KeepAlive((object)image);
        }
コード例 #10
0
        /// <summary>
        ///   Convert a screw into a dual quaternion.
        ///   Modified instance represents: Dual quaternion.
        /// </summary>
        /// <param name="screwFormat">Format of the screw parameters. Default: "moment"</param>
        /// <param name="axisDirectionX">X component of the direction vector of the screw axis.</param>
        /// <param name="axisDirectionY">Y component of the direction vector of the screw axis.</param>
        /// <param name="axisDirectionZ">Z component of the direction vector of the screw axis.</param>
        /// <param name="axisMomentOrPointX">X component of the moment vector or a point on the screw axis.</param>
        /// <param name="axisMomentOrPointY">Y component of the moment vector or a point on the screw axis.</param>
        /// <param name="axisMomentOrPointZ">Z component of the moment vector or a point on the screw axis.</param>
        /// <param name="rotation">Rotation angle in radians.</param>
        /// <param name="translation">Translation.</param>
        public void ScrewToDualQuat(
            string screwFormat,
            double axisDirectionX,
            double axisDirectionY,
            double axisDirectionZ,
            double axisMomentOrPointX,
            double axisMomentOrPointY,
            double axisMomentOrPointZ,
            double rotation,
            double translation)
        {
            IntPtr proc = HalconAPI.PreCall(2086);

            HalconAPI.StoreS(proc, 0, screwFormat);
            HalconAPI.StoreD(proc, 1, axisDirectionX);
            HalconAPI.StoreD(proc, 2, axisDirectionY);
            HalconAPI.StoreD(proc, 3, axisDirectionZ);
            HalconAPI.StoreD(proc, 4, axisMomentOrPointX);
            HalconAPI.StoreD(proc, 5, axisMomentOrPointY);
            HalconAPI.StoreD(proc, 6, axisMomentOrPointZ);
            HalconAPI.StoreD(proc, 7, rotation);
            HalconAPI.StoreD(proc, 8, translation);
            HalconAPI.InitOCT(proc, 0);
            int err        = HalconAPI.CallProcedure(proc);
            int procResult = this.Load(proc, 0, err);

            HalconAPI.PostCall(proc, procResult);
            GC.KeepAlive((object)this);
        }
コード例 #11
0
        /// <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);
        }
コード例 #12
0
        /// <summary>
        ///   Selects an optimal subset from a set of features to solve a certain  classification problem.
        ///   Instance represents: Handle of the training data.
        /// </summary>
        /// <param name="selectionMethod">Method to perform the selection. Default: "greedy"</param>
        /// <param name="genParamName">Names of generic parameters to configure the selection process and the classifier. Default: []</param>
        /// <param name="genParamValue">Values of generic parameters to configure the  selection process and the classifier. Default: []</param>
        /// <param name="selectedFeatureIndices">The selected feature set, contains  indices or names.</param>
        /// <param name="score">The achieved score using two-fold cross-validation.</param>
        /// <returns>A trained k-NN classifier using only the selected  features.</returns>
        public HClassKnn SelectFeatureSetKnn(
            string selectionMethod,
            string genParamName,
            double genParamValue,
            out HTuple selectedFeatureIndices,
            out HTuple score)
        {
            IntPtr proc = HalconAPI.PreCall(1802);

            this.Store(proc, 0);
            HalconAPI.StoreS(proc, 1, selectionMethod);
            HalconAPI.StoreS(proc, 2, genParamName);
            HalconAPI.StoreD(proc, 3, genParamValue);
            HalconAPI.InitOCT(proc, 0);
            HalconAPI.InitOCT(proc, 1);
            HalconAPI.InitOCT(proc, 2);
            int       err1 = HalconAPI.CallProcedure(proc);
            HClassKnn hclassKnn;
            int       err2       = HClassKnn.LoadNew(proc, 0, err1, out hclassKnn);
            int       err3       = HTuple.LoadNew(proc, 1, err2, out selectedFeatureIndices);
            int       procResult = HTuple.LoadNew(proc, 2, HTupleType.DOUBLE, err3, out score);

            HalconAPI.PostCall(proc, procResult);
            GC.KeepAlive((object)this);
            return(hclassKnn);
        }
コード例 #13
0
        /// <summary>
        ///   Selects an optimal subset from a set of features to solve a certain  classification problem.
        ///   Modified instance represents: A trained k-NN classifier using only the selected  features.
        /// </summary>
        /// <param name="classTrainDataHandle">Handle of the training data.</param>
        /// <param name="selectionMethod">Method to perform the selection. Default: "greedy"</param>
        /// <param name="genParamName">Names of generic parameters to configure the selection process and the classifier. Default: []</param>
        /// <param name="genParamValue">Values of generic parameters to configure the  selection process and the classifier. Default: []</param>
        /// <param name="score">The achieved score using two-fold cross-validation.</param>
        /// <returns>The selected feature set, contains  indices or names.</returns>
        public HTuple SelectFeatureSetKnn(
            HClassTrainData classTrainDataHandle,
            string selectionMethod,
            string genParamName,
            double genParamValue,
            out HTuple score)
        {
            this.Dispose();
            IntPtr proc = HalconAPI.PreCall(1802);

            HalconAPI.Store(proc, 0, (HTool)classTrainDataHandle);
            HalconAPI.StoreS(proc, 1, selectionMethod);
            HalconAPI.StoreS(proc, 2, genParamName);
            HalconAPI.StoreD(proc, 3, genParamValue);
            HalconAPI.InitOCT(proc, 0);
            HalconAPI.InitOCT(proc, 1);
            HalconAPI.InitOCT(proc, 2);
            int    err1 = HalconAPI.CallProcedure(proc);
            int    err2 = this.Load(proc, 0, err1);
            HTuple tuple;
            int    err3       = HTuple.LoadNew(proc, 1, err2, out tuple);
            int    procResult = HTuple.LoadNew(proc, 2, HTupleType.DOUBLE, err3, out score);

            HalconAPI.PostCall(proc, procResult);
            GC.KeepAlive((object)this);
            GC.KeepAlive((object)classTrainDataHandle);
            return(tuple);
        }
コード例 #14
0
ファイル: HalconAPI.cs プロジェクト: zshankang/OpenHalcon
        public static int LoadD(IntPtr proc, int parIndex, int err, out double doubleValue)
        {
            if (HalconAPI.IsFailure(err))
            {
                doubleValue = -1.0;
                return(err);
            }
            IntPtr tuple = IntPtr.Zero;

            HalconAPI.GetOutputTuple(proc, parIndex, out tuple);
            err = HalconAPI.HCkSingle(tuple, HTupleType.DOUBLE);
            if (err == 2)
            {
                return(HalconAPI.GetD(tuple, 0, out doubleValue));
            }
            err = HalconAPI.HCkSingle(tuple, HTupleType.INTEGER);
            if (err != 2)
            {
                doubleValue = -1.0;
                return(err);
            }
            int intValue = -1;

            err         = HalconAPI.GetI(tuple, 0, out intValue);
            doubleValue = (double)intValue;
            return(err);
        }
コード例 #15
0
ファイル: HFramegrabber.cs プロジェクト: zshankang/OpenHalcon
        /// <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);
        }
コード例 #16
0
        /// <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);
        }
コード例 #17
0
        /// <summary>
        ///   Classify a related group of characters with an OCR classifier.
        ///   Instance represents: Handle of the OCR classifier.
        /// </summary>
        /// <param name="character">Characters to be recognized.</param>
        /// <param name="image">Gray values of the characters.</param>
        /// <param name="expression">Expression describing the allowed word structure.</param>
        /// <param name="numAlternatives">Number of classes per character considered for the internal word correction. Default: 3</param>
        /// <param name="numCorrections">Maximum number of corrected characters. Default: 2</param>
        /// <param name="confidence">Confidence of the class of the characters.</param>
        /// <param name="word">Word text after classification and correction.</param>
        /// <param name="score">Measure of similarity between corrected word and uncorrected classification results.</param>
        /// <returns>Result of classifying the characters with the k-NN.</returns>
        public string DoOcrWordKnn(
            HRegion character,
            HImage image,
            string expression,
            int numAlternatives,
            int numCorrections,
            out double confidence,
            out string word,
            out double score)
        {
            IntPtr proc = HalconAPI.PreCall(647);

            this.Store(proc, 0);
            HalconAPI.Store(proc, 1, (HObjectBase)character);
            HalconAPI.Store(proc, 2, (HObjectBase)image);
            HalconAPI.StoreS(proc, 1, expression);
            HalconAPI.StoreI(proc, 2, numAlternatives);
            HalconAPI.StoreI(proc, 3, numCorrections);
            HalconAPI.InitOCT(proc, 0);
            HalconAPI.InitOCT(proc, 1);
            HalconAPI.InitOCT(proc, 2);
            HalconAPI.InitOCT(proc, 3);
            int    err1 = HalconAPI.CallProcedure(proc);
            string stringValue;
            int    err2       = HalconAPI.LoadS(proc, 0, err1, out stringValue);
            int    err3       = HalconAPI.LoadD(proc, 1, err2, out confidence);
            int    err4       = HalconAPI.LoadS(proc, 2, err3, out word);
            int    procResult = HalconAPI.LoadD(proc, 3, err4, out score);

            HalconAPI.PostCall(proc, procResult);
            GC.KeepAlive((object)this);
            GC.KeepAlive((object)character);
            GC.KeepAlive((object)image);
            return(stringValue);
        }
コード例 #18
0
ファイル: HSocket.cs プロジェクト: zshankang/OpenHalcon
        /// <summary>Close all opened sockets.</summary>
        public static void CloseAllSockets()
        {
            IntPtr proc       = HalconAPI.PreCall(339);
            int    procResult = HalconAPI.CallProcedure(proc);

            HalconAPI.PostCall(proc, procResult);
        }
コード例 #19
0
        /// <summary>
        ///   Classify a single character with an OCR classifier.
        ///   Instance represents: Handle of the k-NN classifier.
        /// </summary>
        /// <param name="character">Character to be recognized.</param>
        /// <param name="image">Gray values of the character.</param>
        /// <param name="numClasses">Number of maximal classes to determine. Default: 1</param>
        /// <param name="numNeighbors">Number of neighbors to consider. Default: 1</param>
        /// <param name="confidence">Confidence(s) of the class(es) of the character.</param>
        /// <returns>Results of classifying the character with the k-NN.</returns>
        public HTuple DoOcrSingleClassKnn(
            HRegion character,
            HImage image,
            HTuple numClasses,
            HTuple numNeighbors,
            out HTuple confidence)
        {
            IntPtr proc = HalconAPI.PreCall(659);

            this.Store(proc, 0);
            HalconAPI.Store(proc, 1, (HObjectBase)character);
            HalconAPI.Store(proc, 2, (HObjectBase)image);
            HalconAPI.Store(proc, 1, numClasses);
            HalconAPI.Store(proc, 2, numNeighbors);
            HalconAPI.InitOCT(proc, 0);
            HalconAPI.InitOCT(proc, 1);
            int err1 = HalconAPI.CallProcedure(proc);

            HalconAPI.UnpinTuple(numClasses);
            HalconAPI.UnpinTuple(numNeighbors);
            HTuple tuple;
            int    err2       = HTuple.LoadNew(proc, 0, err1, out tuple);
            int    procResult = HTuple.LoadNew(proc, 1, HTupleType.DOUBLE, err2, out confidence);

            HalconAPI.PostCall(proc, procResult);
            GC.KeepAlive((object)this);
            GC.KeepAlive((object)character);
            GC.KeepAlive((object)image);
            return(tuple);
        }
コード例 #20
0
ファイル: HXLDPoly.cs プロジェクト: zshankang/OpenHalcon
        /// <summary>
        ///   Combine road hypotheses from two resolution levels.
        ///   Instance represents: XLD polygons to be examined.
        /// </summary>
        /// <param name="modParallels">Modified parallels obtained from EdgePolygons.</param>
        /// <param name="extParallels">Extended parallels obtained from EdgePolygons.</param>
        /// <param name="centerLines">Road-center-line polygons to be examined.</param>
        /// <param name="maxAngleParallel">Maximum angle between two parallel line segments. Default: 0.523598775598</param>
        /// <param name="maxAngleColinear">Maximum angle between two collinear line segments. Default: 0.261799387799</param>
        /// <param name="maxDistanceParallel">Maximum distance between two parallel line segments. Default: 40</param>
        /// <param name="maxDistanceColinear">Maximum distance between two collinear line segments. Default: 40</param>
        /// <returns>Roadsides found.</returns>
        public HXLDPoly CombineRoadsXld(
            HXLDModPara modParallels,
            HXLDExtPara extParallels,
            HXLDPoly centerLines,
            double maxAngleParallel,
            double maxAngleColinear,
            double maxDistanceParallel,
            double maxDistanceColinear)
        {
            IntPtr proc = HalconAPI.PreCall(37);

            this.Store(proc, 1);
            HalconAPI.Store(proc, 2, (HObjectBase)modParallels);
            HalconAPI.Store(proc, 3, (HObjectBase)extParallels);
            HalconAPI.Store(proc, 4, (HObjectBase)centerLines);
            HalconAPI.StoreD(proc, 0, maxAngleParallel);
            HalconAPI.StoreD(proc, 1, maxAngleColinear);
            HalconAPI.StoreD(proc, 2, maxDistanceParallel);
            HalconAPI.StoreD(proc, 3, maxDistanceColinear);
            HalconAPI.InitOCT(proc, 1);
            int      err = HalconAPI.CallProcedure(proc);
            HXLDPoly hxldPoly;
            int      procResult = HXLDPoly.LoadNew(proc, 1, err, out hxldPoly);

            HalconAPI.PostCall(proc, procResult);
            GC.KeepAlive((object)this);
            GC.KeepAlive((object)modParallels);
            GC.KeepAlive((object)extParallels);
            GC.KeepAlive((object)centerLines);
            return(hxldPoly);
        }
コード例 #21
0
        /// <summary>
        ///   Create an OCR classifier using a k-Nearest Neighbor (k-NN) classifier.
        ///   Modified instance represents: Handle of the k-NN classifier.
        /// </summary>
        /// <param name="widthCharacter">Width of the rectangle to which the gray values of the segmented character are zoomed. Default: 8</param>
        /// <param name="heightCharacter">Height of the rectangle to which the gray values of the segmented character are zoomed. Default: 10</param>
        /// <param name="interpolation">Interpolation mode for the zooming of the characters. Default: "constant"</param>
        /// <param name="features">Features to be used for classification. Default: "default"</param>
        /// <param name="characters">All characters of the character set to be read. Default: ["0","1","2","3","4","5","6","7","8","9"]</param>
        /// <param name="genParamName">This parameter is not yet supported. Default: []</param>
        /// <param name="genParamValue">This parameter is not yet supported. Default: []</param>
        public HOCRKnn(
            int widthCharacter,
            int heightCharacter,
            string interpolation,
            HTuple features,
            HTuple characters,
            HTuple genParamName,
            HTuple genParamValue)
        {
            IntPtr proc = HalconAPI.PreCall(654);

            HalconAPI.StoreI(proc, 0, widthCharacter);
            HalconAPI.StoreI(proc, 1, heightCharacter);
            HalconAPI.StoreS(proc, 2, interpolation);
            HalconAPI.Store(proc, 3, features);
            HalconAPI.Store(proc, 4, characters);
            HalconAPI.Store(proc, 5, genParamName);
            HalconAPI.Store(proc, 6, genParamValue);
            HalconAPI.InitOCT(proc, 0);
            int err = HalconAPI.CallProcedure(proc);

            HalconAPI.UnpinTuple(features);
            HalconAPI.UnpinTuple(characters);
            HalconAPI.UnpinTuple(genParamName);
            HalconAPI.UnpinTuple(genParamValue);
            int procResult = this.Load(proc, 0, err);

            HalconAPI.PostCall(proc, procResult);
            GC.KeepAlive((object)this);
        }
コード例 #22
0
ファイル: HXLDPoly.cs プロジェクト: zshankang/OpenHalcon
        /// <summary>
        ///   Return an XLD polygon's data (as lines).
        ///   Instance represents: Input XLD polygons.
        /// </summary>
        /// <param name="beginRow">Row coordinates of the lines' start points.</param>
        /// <param name="beginCol">Column coordinates of the lines' start points.</param>
        /// <param name="endRow">Column coordinates of the lines' end points.</param>
        /// <param name="endCol">Column coordinates of the lines' end points.</param>
        /// <param name="length">Lengths of the line segments.</param>
        /// <param name="phi">Angles of the line segments.</param>
        public void GetLinesXld(
            out HTuple beginRow,
            out HTuple beginCol,
            out HTuple endRow,
            out HTuple endCol,
            out HTuple length,
            out HTuple phi)
        {
            IntPtr proc = HalconAPI.PreCall(43);

            this.Store(proc, 1);
            HalconAPI.InitOCT(proc, 0);
            HalconAPI.InitOCT(proc, 1);
            HalconAPI.InitOCT(proc, 2);
            HalconAPI.InitOCT(proc, 3);
            HalconAPI.InitOCT(proc, 4);
            HalconAPI.InitOCT(proc, 5);
            int err1       = HalconAPI.CallProcedure(proc);
            int err2       = HTuple.LoadNew(proc, 0, HTupleType.DOUBLE, err1, out beginRow);
            int err3       = HTuple.LoadNew(proc, 1, HTupleType.DOUBLE, err2, out beginCol);
            int err4       = HTuple.LoadNew(proc, 2, HTupleType.DOUBLE, err3, out endRow);
            int err5       = HTuple.LoadNew(proc, 3, HTupleType.DOUBLE, err4, out endCol);
            int err6       = HTuple.LoadNew(proc, 4, HTupleType.DOUBLE, err5, out length);
            int procResult = HTuple.LoadNew(proc, 5, HTupleType.DOUBLE, err6, out phi);

            HalconAPI.PostCall(proc, procResult);
            GC.KeepAlive((object)this);
        }
コード例 #23
0
        /// <summary>
        ///   Preparing a pattern for template matching with rotation.
        ///   Modified instance represents: Template number.
        /// </summary>
        /// <param name="template">Input image whose domain will be processed for the pattern matching.</param>
        /// <param name="numLevel">Maximal number of pyramid levels. Default: 4</param>
        /// <param name="angleStart">Smallest Rotation of the pattern. Default: -0.39</param>
        /// <param name="angleExtend">Maximum positive Extension of AngleStart. Default: 0.79</param>
        /// <param name="angleStep">Step rate (angle precision) of matching. Default: 0.0982</param>
        /// <param name="optimize">Kind of optimizing. Default: "sort"</param>
        /// <param name="grayValues">Kind of grayvalues. Default: "original"</param>
        public HTemplate(
            HImage template,
            int numLevel,
            double angleStart,
            double angleExtend,
            double angleStep,
            string optimize,
            string grayValues)
        {
            IntPtr proc = HalconAPI.PreCall(1488);

            HalconAPI.Store(proc, 1, (HObjectBase)template);
            HalconAPI.StoreI(proc, 0, numLevel);
            HalconAPI.StoreD(proc, 1, angleStart);
            HalconAPI.StoreD(proc, 2, angleExtend);
            HalconAPI.StoreD(proc, 3, angleStep);
            HalconAPI.StoreS(proc, 4, optimize);
            HalconAPI.StoreS(proc, 5, grayValues);
            HalconAPI.InitOCT(proc, 0);
            int err        = HalconAPI.CallProcedure(proc);
            int procResult = this.Load(proc, 0, err);

            HalconAPI.PostCall(proc, procResult);
            GC.KeepAlive((object)this);
            GC.KeepAlive((object)template);
        }
コード例 #24
0
ファイル: HXLDPoly.cs プロジェクト: zshankang/OpenHalcon
        /// <summary>
        ///   Compute the mapping between the distorted image and the rectified image based upon the points of a regular grid.
        ///   Instance represents: Input contours.
        /// </summary>
        /// <param name="image">Input image.</param>
        /// <param name="meshes">Output contours.</param>
        /// <param name="gridSpacing">Distance of the grid points in the rectified image.</param>
        /// <param name="rotation">Rotation to be applied to the point grid. Default: "auto"</param>
        /// <param name="row">Row coordinates of the grid points.</param>
        /// <param name="column">Column coordinates of the grid points.</param>
        /// <param name="mapType">Type of mapping. Default: "bilinear"</param>
        /// <returns>Image containing the mapping data.</returns>
        public HImage GenGridRectificationMap(
            HImage image,
            out HXLDPoly meshes,
            int gridSpacing,
            string rotation,
            HTuple row,
            HTuple column,
            string mapType)
        {
            IntPtr proc = HalconAPI.PreCall(1159);

            this.Store(proc, 2);
            HalconAPI.Store(proc, 1, (HObjectBase)image);
            HalconAPI.StoreI(proc, 0, gridSpacing);
            HalconAPI.StoreS(proc, 1, rotation);
            HalconAPI.Store(proc, 2, row);
            HalconAPI.Store(proc, 3, column);
            HalconAPI.StoreS(proc, 4, mapType);
            HalconAPI.InitOCT(proc, 1);
            HalconAPI.InitOCT(proc, 2);
            int err1 = HalconAPI.CallProcedure(proc);

            HalconAPI.UnpinTuple(row);
            HalconAPI.UnpinTuple(column);
            HImage himage;
            int    err2       = HImage.LoadNew(proc, 1, err1, out himage);
            int    procResult = HXLDPoly.LoadNew(proc, 2, err2, out meshes);

            HalconAPI.PostCall(proc, procResult);
            GC.KeepAlive((object)this);
            GC.KeepAlive((object)image);
            return(himage);
        }
コード例 #25
0
        /// <summary>
        ///   Searching the best matching of a template and an image.
        ///   Instance represents: Template number.
        /// </summary>
        /// <param name="image">Input image inside of which the pattern has to be found.</param>
        /// <param name="maxError">Maximum average difference of the grayvalues. Default: 20.0</param>
        /// <param name="subPixel">Subpixel accuracy in case of 'true'. Default: "false"</param>
        /// <param name="row">Row position of the best match.</param>
        /// <param name="column">Column position of the best match.</param>
        /// <param name="error">Average divergence of the grayvalues of the best match.</param>
        public void BestMatch(
            HImage image,
            double maxError,
            string subPixel,
            out double row,
            out double column,
            out double error)
        {
            IntPtr proc = HalconAPI.PreCall(1505);

            this.Store(proc, 0);
            HalconAPI.Store(proc, 1, (HObjectBase)image);
            HalconAPI.StoreD(proc, 1, maxError);
            HalconAPI.StoreS(proc, 2, subPixel);
            HalconAPI.InitOCT(proc, 0);
            HalconAPI.InitOCT(proc, 1);
            HalconAPI.InitOCT(proc, 2);
            int err1       = HalconAPI.CallProcedure(proc);
            int err2       = HalconAPI.LoadD(proc, 0, err1, out row);
            int err3       = HalconAPI.LoadD(proc, 1, err2, out column);
            int procResult = HalconAPI.LoadD(proc, 2, err3, out error);

            HalconAPI.PostCall(proc, procResult);
            GC.KeepAlive((object)this);
            GC.KeepAlive((object)image);
        }
コード例 #26
0
ファイル: HXLDPoly.cs プロジェクト: zshankang/OpenHalcon
        /// <summary>
        ///   Read XLD polygons from a DXF file.
        ///   Modified instance represents: Read XLD polygons.
        /// </summary>
        /// <param name="fileName">Name of the DXF file.</param>
        /// <param name="genParamName">Names of the generic parameters that can be adjusted for the DXF input. Default: []</param>
        /// <param name="genParamValue">Values of the generic parameters that can be adjusted for the DXF input. Default: []</param>
        /// <returns>Status information.</returns>
        public HTuple ReadPolygonXldDxf(
            string fileName,
            HTuple genParamName,
            HTuple genParamValue)
        {
            this.Dispose();
            IntPtr proc = HalconAPI.PreCall(1634);

            HalconAPI.StoreS(proc, 0, fileName);
            HalconAPI.Store(proc, 1, genParamName);
            HalconAPI.Store(proc, 2, genParamValue);
            HalconAPI.InitOCT(proc, 1);
            HalconAPI.InitOCT(proc, 0);
            int err1 = HalconAPI.CallProcedure(proc);

            HalconAPI.UnpinTuple(genParamName);
            HalconAPI.UnpinTuple(genParamValue);
            int    err2 = this.Load(proc, 1, err1);
            HTuple tuple;
            int    procResult = HTuple.LoadNew(proc, 0, err2, out tuple);

            HalconAPI.PostCall(proc, procResult);
            GC.KeepAlive((object)this);
            return(tuple);
        }
コード例 #27
0
        /// <summary>Deactivate all compute devices.</summary>
        public static void DeactivateAllComputeDevices()
        {
            IntPtr proc       = HalconAPI.PreCall(300);
            int    procResult = HalconAPI.CallProcedure(proc);

            HalconAPI.PostCall(proc, procResult);
        }
コード例 #28
0
ファイル: HXLDPoly.cs プロジェクト: zshankang/OpenHalcon
        /// <summary>
        ///   Select contours or polygons using shape features.
        ///   Instance represents: Contours or polygons to be examined.
        /// </summary>
        /// <param name="features">Shape features to be checked. Default: "area"</param>
        /// <param name="operation">Operation type between the individual features. Default: "and"</param>
        /// <param name="min">Lower limits of the features or 'min'. Default: 150.0</param>
        /// <param name="max">Upper limits of the features or 'max'. Default: 99999.0</param>
        /// <returns>Contours or polygons fulfilling the condition(s).</returns>
        public HXLDPoly SelectShapeXld(
            HTuple features,
            string operation,
            HTuple min,
            HTuple max)
        {
            IntPtr proc = HalconAPI.PreCall(1678);

            this.Store(proc, 1);
            HalconAPI.Store(proc, 0, features);
            HalconAPI.StoreS(proc, 1, operation);
            HalconAPI.Store(proc, 2, min);
            HalconAPI.Store(proc, 3, max);
            HalconAPI.InitOCT(proc, 1);
            int err = HalconAPI.CallProcedure(proc);

            HalconAPI.UnpinTuple(features);
            HalconAPI.UnpinTuple(min);
            HalconAPI.UnpinTuple(max);
            HXLDPoly hxldPoly;
            int      procResult = HXLDPoly.LoadNew(proc, 1, err, out hxldPoly);

            HalconAPI.PostCall(proc, procResult);
            GC.KeepAlive((object)this);
            return(hxldPoly);
        }
コード例 #29
0
ファイル: EngineAPI.cs プロジェクト: zshankang/OpenHalcon
        internal static int StoreTupleVector(HTupleVector inVector, IntPtr vectorHandle)
        {
            int dimension = inVector.Dimension;
            int length    = inVector.Length;

            if (dimension == 1)
            {
                for (int index = length - 1; index >= 0; --index)
                {
                    IntPtr tuple;
                    EngineAPI.HCkE(HalconAPI.CreateTuple(out tuple));
                    HalconAPI.StoreTuple(tuple, inVector[index].T);
                    EngineAPI.HCkE(EngineAPI.SetTupleVectorTuple(vectorHandle, index, tuple));
                    EngineAPI.HCkE(HalconAPI.DestroyTuple(tuple));
                }
            }
            else
            {
                for (int index = length - 1; index >= 0; --index)
                {
                    IntPtr vectorHandle1;
                    EngineAPI.HCkE(EngineAPI.CreateTupleVector(inVector[index], out vectorHandle1));
                    EngineAPI.HCkE(EngineAPI.SetTupleVectorVector(vectorHandle, index, vectorHandle1));
                    EngineAPI.HCkE(EngineAPI.DestroyTupleVector(vectorHandle1));
                }
            }
            GC.KeepAlive((object)inVector);
            return(2);
        }
コード例 #30
0
ファイル: HalconAPI.cs プロジェクト: zshankang/OpenHalcon
        public static void StoreD(IntPtr proc, int parIndex, double doubleValue)
        {
            IntPtr tuple;

            HalconAPI.HCkP(proc, HalconAPI.CreateInputTuple(proc, parIndex, 1, out tuple));
            HalconAPI.SetD(tuple, 0, doubleValue);
        }