Beispiel #1
0
      /// <summary>
      /// Load the trained detector from files
      /// </summary>
      /// <param name="fileNames">The names of the trained latent svm file</param>
      /// <param name="classNames">The names of the class</param>
      public LatentSvmDetector(String[] fileNames, String[] classNames = null)
      {
         CvString[] fileNameStrings = new CvString[fileNames.Length];
         for (int i = 0; i < fileNames.Length ;i++)
            fileNameStrings[i] = new CvString(fileNames[i]);

         CvString[] classNameStrings = null;
         if (classNames != null)
         {
            classNameStrings = new CvString[classNames.Length];
            for (int i = 0; i < classNames.Length; i++)
               classNameStrings[i] = new CvString(classNames[i]);
         }
         try
         {
            using (VectorOfCvString fvcs = new VectorOfCvString(fileNameStrings))
            using (VectorOfCvString cvcs = new VectorOfCvString())
            {
               if (classNameStrings != null)
                  cvcs.Push(classNameStrings);

               _ptr = cveLSVMDetectorCreate(fvcs, cvcs);
            }
         }
         finally
         {
            for (int i =  0; i < fileNameStrings.Length; i++)
               fileNameStrings[i].Dispose();

            if (classNameStrings != null)
               for (int i = 0; i < classNameStrings.Length; i++)
                  classNameStrings[i].Dispose();
         }
      }
Beispiel #2
0
 /// <summary>
 /// Decodes barcode in image once it's found by the detect() method.
 /// </summary>
 /// <param name="image">grayscale or color (BGR) image containing bar code.</param>
 /// <param name="points">vector of rotated rectangle vertices found by detect() method (or some other algorithm).</param>
 /// <param name="decodedInfo">UTF8-encoded output vector of string or empty vector of string if the codes cannot be decoded.</param>
 /// <param name="decodedType">vector of BarcodeType, specifies the type of these barcodes</param>
 /// <returns>True if decode is successful</returns>
 public bool Decode(IInputArray image, IInputArray points, VectorOfCvString decodedInfo, VectorOfInt decodedType)
 {
     using (InputArray iaImage = image.GetInputArray())
         using (InputArray iaPoints = points.GetInputArray())
         {
             return(BarcodeInvoke.cveBarcodeDetectorDecode(_ptr, iaImage, iaPoints, decodedInfo, decodedType));
         }
 }
Beispiel #3
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public string[] GetLayerNames()
 {
     using (var namesVec = new VectorOfCvString())
     {
         NativeMethods.dnn_Net_getLayerNames(ptr, namesVec.CvPtr);
         GC.KeepAlive(this);
         return(namesVec.ToArray());
     }
 }
 /// <summary>
 /// Given the input frame, create input blob, run net and return recognition result.
 /// </summary>
 /// <param name="frame">The input image</param>
 /// <param name="roiRects">Vector of text detection regions of interest (Rect, CV_32SC4). ROIs is be cropped as the network inputs</param>
 /// <returns>A set of text recognition results.</returns>
 public String[] Recognize(IInputArray frame, IInputArrayOfArrays roiRects)
 {
     using (VectorOfCvString vs = new VectorOfCvString())
         using (InputArray iaFrame = frame.GetInputArray())
             using (InputArray iaRoiRects = roiRects.GetInputArray())
             {
                 DnnInvoke.cveDnnTextRecognitionModelRecognize2(_ptr, iaFrame, iaRoiRects, vs);
                 return(vs.ToArray());
             }
 }
Beispiel #5
0
 /// <summary>
 /// Decodes QR codes in image once it's found by the detect() method.
 /// </summary>
 /// <param name="img">Grayscale or color (BGR) image containing QR codes.</param>
 /// <param name="points">Vector of Quadrangle vertices found by detect() method (or some other algorithm).</param>
 /// <param name="decodedInfo">UTF8-encoded output vector of string or empty vector of string if the codes cannot be decoded.</param>
 /// <param name="straightQrcode">The optional output vector of images containing rectified and binarized QR codes</param>
 /// <returns>True if decoding is successful.</returns>
 public bool DecodeMulti(
     IInputArray img,
     IInputArray points,
     VectorOfCvString decodedInfo,
     IOutputArray straightQrcode = null)
 {
     using (InputArray iaImg = img.GetInputArray())
         using (InputArray iaPoints = points.GetInputArray())
             using (OutputArray oaStraightQrcode =
                        (straightQrcode == null ? OutputArray.GetEmpty() : straightQrcode.GetOutputArray()))
             {
                 return(CvInvoke.cveQRCodeDetectorDecodeMulti(_ptr, iaImg, iaPoints, decodedInfo, oaStraightQrcode));
             }
 }
Beispiel #6
0
 /// <summary>
 /// Both detects and decodes barcode
 /// </summary>
 /// <param name="image">grayscale or color (BGR) image containing barcode.</param>
 /// <param name="decodedInfo">UTF8-encoded output vector of string(s) or empty vector of string if the codes cannot be decoded.</param>
 /// <param name="decodedType">vector of BarcodeType, specifies the type of these barcodes</param>
 /// <param name="points">Optional output vector of vertices of the found  barcode rectangle. Will be empty if not found.</param>
 /// <returns>True if barcode is detected and decoded.</returns>
 public bool DetectAndDecode(
     IInputArray image,
     VectorOfCvString decodedInfo,
     VectorOfInt decodedType,
     IOutputArray points = null)
 {
     using (InputArray iaImage = image.GetInputArray())
         using (OutputArray oaPoints = points == null ? OutputArray.GetEmpty() : points.GetOutputArray())
             return(BarcodeInvoke.cveBarcodeDetectorDetectAndDecode(
                        _ptr,
                        iaImage,
                        decodedInfo,
                        decodedType,
                        oaPoints));
 }
Beispiel #7
0
 /// <summary>
 /// Both detects and decodes QR code.
 /// </summary>
 /// <param name="img">Supports grayscale or color (BGR) image</param>
 /// <param name="points">Optional output array of vertices of the found QR code quadrangle. Will be empty if not found.</param>
 /// <returns>The array of decoded string.</returns>
 public String[] DetectAndDecode(
     IInputArray img,
     IOutputArrayOfArrays points)
 {
     using (InputArray iaImg = img.GetInputArray())
         using (OutputArray oaPoints = points == null? OutputArray.GetEmpty() : points.GetOutputArray())
             using (VectorOfCvString result = new VectorOfCvString())
             {
                 WeChatQRCodeInvoke.cveWeChatQRCodeDetectAndDecode(
                     _ptr,
                     iaImg,
                     oaPoints,
                     result);
                 return(result.ToArray());
             }
 }
        /// <summary>
        /// Load the trained detector from files
        /// </summary>
        /// <param name="fileNames">The names of the trained latent svm file</param>
        /// <param name="classNames">The names of the class</param>
        public LatentSvmDetector(String[] fileNames, String[] classNames = null)
        {
            CvString[] fileNameStrings = new CvString[fileNames.Length];
            for (int i = 0; i < fileNames.Length; i++)
            {
                fileNameStrings[i] = new CvString(fileNames[i]);
            }

            CvString[] classNameStrings = null;
            if (classNames != null)
            {
                classNameStrings = new CvString[classNames.Length];
                for (int i = 0; i < classNames.Length; i++)
                {
                    classNameStrings[i] = new CvString(classNames[i]);
                }
            }
            try
            {
                using (VectorOfCvString fvcs = new VectorOfCvString(fileNameStrings))
                    using (VectorOfCvString cvcs = new VectorOfCvString())
                    {
                        if (classNameStrings != null)
                        {
                            cvcs.Push(classNameStrings);
                        }

                        _ptr = CvInvoke.cveLSVMDetectorCreate(fvcs, cvcs);
                    }
            }
            finally
            {
                for (int i = 0; i < fileNameStrings.Length; i++)
                {
                    fileNameStrings[i].Dispose();
                }

                if (classNameStrings != null)
                {
                    for (int i = 0; i < classNameStrings.Length; i++)
                    {
                        classNameStrings[i].Dispose();
                    }
                }
            }
        }
Beispiel #9
0
        /// <summary>
        /// Both detects and decodes barcode
        /// </summary>
        /// <returns>The barcode found. If nothing is found, an empty array is returned.</returns>
        public Barcode[] DetectAndDecode(IInputArray image)
        {
            using (VectorOfCvString decodedInfoVec = new VectorOfCvString())
                using (VectorOfInt decodedTypeVec = new VectorOfInt())
                    //using (VectorOfMat pointsVec = new VectorOfMat())
                    //using (VectorOfPointF pointsVec = new VectorOfPointF())
                    using (Mat pointsVec = new Mat())
                    {
                        if (!DetectAndDecode(image, decodedInfoVec, decodedTypeVec, pointsVec))
                        {
                            return(new Barcode[0]);
                        }

                        PointF[] points = new PointF[4 * pointsVec.Rows];

                        if (points.Length > 0)
                        {
                            GCHandle handle = GCHandle.Alloc(points, GCHandleType.Pinned);
                            CvInvoke.cveMemcpy(handle.AddrOfPinnedObject(), pointsVec.DataPointer,
                                               points.Length * Marshal.SizeOf <PointF>());
                            handle.Free();
                        }


                        string[] decodedInfo = decodedInfoVec.ToArray();
                        int[]    decodedType = decodedTypeVec.ToArray();
                        //Point[][] points = WeChatQRCode.VectorOfMatToPoints(pointsVec);
                        //points = pointsVec.ToArray();
                        Barcode[] barcodes = new Barcode[decodedInfo.Length];
                        for (int i = 0; i < barcodes.Length; i++)
                        {
                            Barcode barcode = new Barcode();
                            barcode.DecodedInfo = decodedInfo[i];
                            barcode.Type        = (BarcodeType)decodedType[i];
                            PointF[] region = new PointF[4];
                            Array.Copy(points, 4 * i, region, 0, 4);
                            barcode.Points = region;

                            barcodes[i] = barcode;
                        }

                        return(barcodes);
                    }
        }
Beispiel #10
0
 /// <summary>
 /// Detect objects by template matching. Matches globally at the lowest pyramid level, then refines locally stepping up the pyramid.
 /// </summary>
 /// <param name="sources">Source images, one for each modality.</param>
 /// <param name="threshold">Similarity threshold, a percentage between 0 and 100.</param>
 /// <param name="matches">Template matches, sorted by similarity score.</param>
 /// <param name="classIds">If non-empty, only search for the desired object classes.</param>
 /// <param name="quantizedImages">Optionally return vector&lt;Mat&gt; of quantized images.</param>
 /// <param name="masks">The masks for consideration during matching. The masks should be CV_8UC1 where 255 represents a valid pixel. If non-empty, the vector must be the same size as sources. Each element must be empty or the same size as its corresponding source.</param>
 public void Match(
     VectorOfMat sources,
     float threshold,
     VectorOfLinemodMatch matches,
     VectorOfCvString classIds            = null,
     IOutputArrayOfArrays quantizedImages = null,
     VectorOfMat masks = null)
 {
     using (OutputArray oaQuantizedImages =
                quantizedImages == null ? OutputArray.GetEmpty() : quantizedImages.GetOutputArray())
     {
         LinemodInvoke.cveLinemodDetectorMatch(
             _ptr,
             sources,
             threshold,
             matches,
             classIds,
             oaQuantizedImages,
             masks
             );
     }
 }
Beispiel #11
0
 /// <summary>
 /// Get the list of parameter definitions
 /// </summary>
 /// <param name="algorithm">The algorithm to retrieve the parameter list from</param>
 /// <returns>The list of parameter definitions</returns>
 public static ParamDef[] GetParams(this IAlgorithm algorithm)
 {
     using (VectorOfCvString names = new VectorOfCvString())
         using (VectorOfInt types = new VectorOfInt())
             using (VectorOfCvString helps = new VectorOfCvString())
             {
                 CvInvoke.cveAlgorithmGetParams(algorithm.AlgorithmPtr, names, types, helps);
                 ParamDef[] results = new ParamDef[names.Size];
                 for (int i = 0; i < results.Length; i++)
                 {
                     ParamDef t = new ParamDef();
                     using (CvString n = names[i])
                         using (CvString h = helps[i])
                         {
                             t.Name = n.ToString();
                             t.Type = (ParamType)types[i];
                             t.Help = h.ToString();
                         }
                     results[i] = t;
                 }
                 return(results);
             }
 }
Beispiel #12
0
        /// <summary>
        /// Both detects and decodes QR code.
        /// </summary>
        /// <param name="img">Supports grayscale or color (BGR) image</param>
        /// <returns>The detected QRCode.</returns>
        public QRCode[] DetectAndDecode(IInputArray img)
        {
            using (InputArray iaImg = img.GetInputArray())
                using (VectorOfMat pointsVec = new VectorOfMat())
                    using (VectorOfCvString result = new VectorOfCvString())
                    {
                        String[] codes = DetectAndDecode(img, pointsVec);
                        if (codes.Length == 0)
                        {
                            return(new QRCode[0]);
                        }
                        Point[][] points = WeChatQRCode.VectorOfMatToPoints(pointsVec);

                        QRCode[] results = new QRCode[codes.Length];
                        for (int i = 0; i < codes.Length; i++)
                        {
                            QRCode c = new QRCode();
                            c.Code     = codes[i];
                            c.Region   = points[i];
                            results[i] = c;
                        }
                        return(results);
                    }
        }
Beispiel #13
0
 /// <summary>
 /// Runs forward pass to compute outputs of layers listed in outBlobNames.
 /// </summary>
 /// <param name="outputBlobs">Contains blobs for first outputs of specified layers.</param>
 /// <param name="outBlobNames">Names for layers which outputs are needed to get</param>
 public void Forward(IOutputArrayOfArrays outputBlobs, String[] outBlobNames)
 {
     using (OutputArray oaOutputBlobs = outputBlobs.GetOutputArray())
         using (VectorOfCvString vcs = new VectorOfCvString(outBlobNames))
             DnnInvoke.cveDnnNetForward3(_ptr, oaOutputBlobs, vcs);
 }