Esempio n. 1
0
 /// <summary>
 /// Returns a training set of descriptors.
 /// </summary>
 /// <returns></returns>
 public Mat[] GetDescriptors()
 {
     using (var descriptors = new VectorOfMat())
     {
         NativeMethods.features2d_BOWTrainer_getDescriptors(ptr, descriptors.CvPtr);
         return(descriptors.ToArray());
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Returns a training set of descriptors.
 /// </summary>
 /// <returns></returns>
 public Mat[] GetDescriptors()
 {
     using var descriptors = new VectorOfMat();
     NativeMethods.HandleException(
         NativeMethods.features2d_BOWTrainer_getDescriptors(ptr, descriptors.CvPtr));
     GC.KeepAlive(this);
     return(descriptors.ToArray());
 }
Esempio n. 3
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public Mat[] GetMatVector()
 {
     ThrowIfDisposed();
     using var vec = new VectorOfMat();
     NativeMethods.HandleException(
         NativeMethods.core_InputArray_getMatVector(ptr, vec.CvPtr));
     GC.KeepAlive(this);
     return(vec.ToArray());
 }
 /// <summary>
 /// Get train descriptors collection.
 /// </summary>
 /// <returns></returns>
 public Mat[] GetTrainDescriptors()
 {
     ThrowIfDisposed();
     using (var matVec = new VectorOfMat())
     {
         NativeMethods.features2d_DescriptorMatcher_getTrainDescriptors(ptr, matVec.CvPtr);
         return(matVec.ToArray());
     }
 }
Esempio n. 5
0
        //public Mat getMat_(int idx = -1) { }
        //public UMat getUMat(int idx = -1) const;

        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public Mat[] GetMatVector()
        {
            ThrowIfDisposed();
            using (var vec = new VectorOfMat())
            {
                NativeMethods.core_InputArray_getMatVector(ptr, vec.CvPtr);
                return(vec.ToArray());
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Get train descriptors collection.
 /// </summary>
 /// <returns></returns>
 public Mat[] GetTrainDescriptors()
 {
     ThrowIfDisposed();
     using var matVec = new VectorOfMat();
     NativeMethods.HandleException(
         NativeMethods.features2d_DescriptorMatcher_getTrainDescriptors(ptr, matVec.CvPtr));
     GC.KeepAlive(this);
     return matVec.ToArray();
 }
Esempio n. 7
0
        /// <summary>
        /// Returns covariation matrices.
        /// Returns vector of covariation matrices. Number of matrices is the number of
        /// gaussian mixtures, each matrix is a square floating-point matrix NxN, where N is the space dimensionality.
        /// </summary>
        public Mat[] GetCovs()
        {
            ThrowIfDisposed();

            using (var vec = new VectorOfMat())
            {
                NativeMethods.ml_EM_getCovs(ptr, vec.CvPtr);
                return(vec.ToArray());
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Loads a multi-page image from a file.
        /// </summary>
        /// <param name="filename">Name of file to be loaded.</param>
        /// <param name="mats">A vector of Mat objects holding each page, if more than one.</param>
        /// <param name="flags">Flag that can take values of @ref cv::ImreadModes, default with IMREAD_ANYCOLOR.</param>
        /// <returns></returns>
        public static bool ImReadMulti(string filename, out Mat[] mats, ImreadModes flags = ImreadModes.AnyColor)
        {
            if (filename == null)
            {
                throw new ArgumentNullException(nameof(filename));
            }

            using var matsVec = new VectorOfMat();
            NativeMethods.HandleException(
                NativeMethods.imgcodecs_imreadmulti(filename, matsVec.CvPtr, (int)flags, out var ret));
            mats = matsVec.ToArray();
            return(ret != 0);
        }
Esempio n. 9
0
        /// <summary>
        /// Returns covariation matrices.
        /// Returns vector of covariation matrices. Number of matrices is the number of
        /// gaussian mixtures, each matrix is a square floating-point matrix NxN, where N is the space dimensionality.
        /// </summary>
        public Mat[] GetCovs()
        {
            if (disposed)
            {
                throw new ObjectDisposedException(GetType().Name);
            }

            using (var vec = new VectorOfMat())
            {
                NativeMethods.ml_EM_getCovs(ptr, vec.CvPtr);
                return(vec.ToArray());
            }
        }
Esempio n. 10
0
        /// <summary>
        ///
        /// </summary>
        public override void AssignResult()
        {
            if (!IsReady())
            {
                throw new NotSupportedException();
            }

            using var vectorOfMat = new VectorOfMat();
            NativeMethods.HandleException(
                NativeMethods.core_OutputArray_getVectorOfMat(ptr, vectorOfMat.CvPtr));
            GC.KeepAlive(this);
            list.Clear();
            list.AddRange(vectorOfMat.ToArray());
        }
Esempio n. 11
0
        /// <summary>
        ///
        /// </summary>
        public override void AssignResult()
        {
            if (!IsReady())
            {
                throw new NotSupportedException();
            }

            // Matで結果取得
            using (var vectorOfMat = new VectorOfMat())
            {
                NativeMethods.core_OutputArray_getVectorOfMat(ptr, vectorOfMat.CvPtr);
                list.Clear();
                list.AddRange(vectorOfMat.ToArray());
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Compute the different channels to be processed independently in the N&M algorithm [Neumann12]
        /// </summary>
        /// <param name="src">The source image</param>
        /// <returns>Channels</returns>
        public static Mat[] ComputeNMChannels(Mat src, ERFilter.Mode mode)
        {
            if (src == null)
            {
                throw new ArgumentNullException("nameof(src)");
            }
            src.ThrowIfDisposed();

            IntPtr mvPtr;

            NativeMethods.text_computeNMChannels(src.CvPtr, out mvPtr, (int)mode);

            using (var vec = new VectorOfMat(mvPtr))
            {
                return(vec.ToArray());
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Decodes QR codes in image once it's found by the detect() method.
        /// Returns UTF8-encoded output string or empty string if the code cannot be decoded.
        /// </summary>
        /// <param name="img">grayscale or color (BGR) image containing QR code.</param>
        /// <param name="points">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 image containing rectified and binarized QR code</param>
        /// <param name="isOutputStraightQrCode"><see langword="true"/> to output <paramref name="straightQrCode"/></param>
        /// <returns></returns>
        protected bool DecodeMulti(InputArray img, IEnumerable <Point2f> points, out string?[] decodedInfo, out Mat[] straightQrCode, bool isOutputStraightQrCode)
        {
            if (img == null)
            {
                throw new ArgumentNullException(nameof(img));
            }
            if (points == null)
            {
                throw new ArgumentNullException(nameof(points));
            }

            img.ThrowIfDisposed();

            using var decodedInfoVec = new VectorOfString();
            using var pointsVec      = new VectorOfPoint2f(points);

            int ret;

            if (isOutputStraightQrCode)
            {
                NativeMethods.HandleException(
                    NativeMethods.objdetect_QRCodeDetector_decodeMulti(
                        ptr, img.CvPtr, pointsVec.CvPtr, decodedInfoVec.CvPtr, out var straightQrCodePtr, out ret));

                using var straightQrCodeVec = new VectorOfMat(straightQrCodePtr);
                straightQrCode = straightQrCodeVec.ToArray();
            }
            else
            {
                NativeMethods.HandleException(
                    NativeMethods.objdetect_QRCodeDetector_decodeMulti_NoStraightQrCode(
                        ptr, img.CvPtr, pointsVec.CvPtr, decodedInfoVec.CvPtr, out ret));
                straightQrCode = Array.Empty <Mat>();
            }

            // decode utf-8 bytes.
            decodedInfo = decodedInfoVec.ToArray();

            GC.KeepAlive(img);
            GC.KeepAlive(points);
            GC.KeepAlive(this);

            return(ret != 0);
        }
Esempio n. 14
0
        /// <summary>
        /// Both detects and decodes QR code.
        /// To simplify the usage, there is a only API: detectAndDecode
        /// </summary>
        /// <param name="inputImage">supports grayscale or color(BGR) image.</param>
        /// <param name="bbox">optional output array of vertices of the found QR code quadrangle.Will be empty if not found.</param>
        /// <param name="results">list of decoded string.</param>
        public void DetectAndDecode(InputArray inputImage, out Mat[] bbox, out string[] results)
        {
            if (inputImage == null)
            {
                throw new ArgumentNullException(nameof(inputImage));
            }
            inputImage.ThrowIfDisposed();

            using var bboxVec = new VectorOfMat();
            using var texts   = new VectorOfString();
            NativeMethods.HandleException(
                NativeMethods.wechat_qrcode_WeChatQRCode_detectAndDecode(
                    ptr, inputImage.CvPtr, bboxVec.CvPtr, texts.CvPtr));

            bbox    = bboxVec.ToArray();
            results = texts.ToArray();
            GC.KeepAlive(this);
            GC.KeepAlive(inputImage);
        }
Esempio n. 15
0
        /// <summary>
        /// Constructs a pyramid which can be used as input for calcOpticalFlowPyrLK
        /// </summary>
        /// <param name="img">8-bit input image.</param>
        /// <param name="pyramid">output pyramid.</param>
        /// <param name="winSize">window size of optical flow algorithm.
        /// Must be not less than winSize argument of calcOpticalFlowPyrLK().
        /// It is needed to calculate required padding for pyramid levels.</param>
        /// <param name="maxLevel">0-based maximal pyramid level number.</param>
        /// <param name="withDerivatives">set to precompute gradients for the every pyramid level.
        /// If pyramid is constructed without the gradients then calcOpticalFlowPyrLK() will
        /// calculate them internally.</param>
        /// <param name="pyrBorder">the border mode for pyramid layers.</param>
        /// <param name="derivBorder">the border mode for gradients.</param>
        /// <param name="tryReuseInputImage">put ROI of input image into the pyramid if possible.
        /// You can pass false to force data copying.</param>
        /// <returns>number of levels in constructed pyramid. Can be less than maxLevel.</returns>
        public static int BuildOpticalFlowPyramid(
            InputArray img, out Mat[] pyramid,
            Size winSize, int maxLevel,
            bool withDerivatives    = true,
            BorderTypes pyrBorder   = BorderTypes.Reflect101,
            BorderTypes derivBorder = BorderTypes.Constant,
            bool tryReuseInputImage = true)
        {
            if (img == null)
            {
                throw new ArgumentNullException(nameof(img));
            }
            img.ThrowIfDisposed();

            using var pyramidVec = new VectorOfMat();
            NativeMethods.HandleException(
                NativeMethods.video_buildOpticalFlowPyramid2(
                    img.CvPtr, pyramidVec.CvPtr, winSize, maxLevel, withDerivatives ? 1 : 0,
                    (int)pyrBorder, (int)derivBorder, tryReuseInputImage ? 1 : 0, out var ret));
            GC.KeepAlive(img);
            pyramid = pyramidVec.ToArray();
            return(ret);
        }