Example #1
0
        /// <summary>
        /// Try to stitch the given images.
        /// </summary>
        /// <param name="images">Input images.</param>
        /// <param name="rois">Region of interest rectangles.</param>
        /// <param name="pano">Final pano.</param>
        /// <returns>Status code.</returns>
        public Status Stitch(IEnumerable <Mat> images, Rect[][] rois, OutputArray pano)
        {
            if (images == null)
            {
                throw new ArgumentNullException("images");
            }
            if (rois == null)
            {
                throw new ArgumentNullException("rois");
            }
            if (pano == null)
            {
                throw new ArgumentNullException("pano");
            }
            pano.ThrowIfNotReady();

            IntPtr[] imagesPtrs = EnumerableEx.SelectPtrs(images);

            using (var roisPointer = new ArrayAddress2 <Rect>(rois))
            {
                int status = NativeMethods.stitching_Stitcher_stitch2_MatArray(
                    ptr, imagesPtrs, imagesPtrs.Length,
                    roisPointer.Pointer, roisPointer.Dim1Length, roisPointer.Dim2Lengths,
                    pano.CvPtr);
                pano.Fix();
                return((Status)status);
            }
        }
Example #2
0
        /// <summary>
        /// Detect keypoints in an image set.
        /// </summary>
        /// <param name="images">Image collection.</param>
        /// <param name="masks">Masks for image set. masks[i] is a mask for images[i].</param>
        /// <returns>Collection of keypoints detected in an input images. keypoints[i] is a set of keypoints detected in an images[i].</returns>
        public KeyPoint[][] Detect(IEnumerable <Mat> images, IEnumerable <Mat> masks = null)
        {
            if (images == null)
            {
                throw new ArgumentNullException("images");
            }

            Mat[]    imagesArray = Util.ToArray(images);
            IntPtr[] imagesPtr   = new IntPtr[imagesArray.Length];
            for (int i = 0; i < imagesArray.Length; i++)
            {
                imagesPtr[i] = imagesArray[i].CvPtr;
            }

            using (var keypoints = new VectorOfVectorKeyPoint())
            {
                if (masks == null)
                {
                    NativeMethods.features2d_FeatureDetector_detect(
                        ptr, imagesPtr, imagesArray.Length, keypoints.CvPtr, null);
                }
                else
                {
                    IntPtr[] masksPtr = EnumerableEx.SelectPtrs(masks);
                    if (masksPtr.Length != imagesArray.Length)
                    {
                        throw new ArgumentException("masks.Length != images.Length");
                    }
                    NativeMethods.features2d_FeatureDetector_detect(
                        ptr, imagesPtr, imagesArray.Length, keypoints.CvPtr, masksPtr);
                }
                return(keypoints.ToArray());
            }
        }
        /// <summary>
        /// Add descriptors to train descriptor collection.
        /// </summary>
        /// <param name="descriptors">Descriptors to add. Each descriptors[i] is a descriptors set from one image.</param>
        public virtual void Add(IEnumerable <Mat> descriptors)
        {
            ThrowIfDisposed();
            if (descriptors == null)
            {
                throw new ArgumentNullException("descriptors");
            }

            IntPtr[] descriptorsPtrs = EnumerableEx.SelectPtrs(descriptors);
            NativeMethods.features2d_DescriptorMatcher_add(ptr, descriptorsPtrs, descriptorsPtrs.Length);
        }
Example #4
0
        public Status EstimateTransform(IEnumerable <Mat> images)
        {
            if (images == null)
            {
                throw new ArgumentNullException("images");
            }

            IntPtr[] imagesPtrs = EnumerableEx.SelectPtrs(images);

            int status = NativeMethods.stitching_Stitcher_estimateTransform_MatArray1(
                ptr, imagesPtrs, imagesPtrs.Length);

            return((Status)status);
        }
Example #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pyr"></param>
        /// <returns></returns>
        public Mat[] BuildDoGPyramid(IEnumerable <Mat> pyr)
        {
            ThrowIfDisposed();
            if (pyr == null)
            {
                throw new ArgumentNullException("pyr");
            }

            IntPtr[] pyrPtrs = EnumerableEx.SelectPtrs(pyr);
            using (VectorOfMat dogPyrVec = new VectorOfMat())
            {
                NativeMethods.nonfree_SIFT_buildDoGPyramid(ptr, pyrPtrs, pyrPtrs.Length, dogPyrVec.CvPtr);
                return(dogPyrVec.ToArray());
            }
        }
Example #6
0
 /// <summary>
 /// Trains a FaceRecognizer.
 /// </summary>
 /// <param name="src"></param>
 /// <param name="labels"></param>
 public virtual void Train(IEnumerable <Mat> src, IEnumerable <int> labels)
 {
     if (src == null)
     {
         throw new ArgumentNullException(nameof(src));
     }
     if (labels == null)
     {
         throw new ArgumentNullException(nameof(labels));
     }
     IntPtr[] srcArray    = EnumerableEx.SelectPtrs(src);
     int[]    labelsArray = EnumerableEx.ToArray(labels);
     NativeMethods.contrib_FaceRecognizer_train(
         ptr, srcArray, srcArray.Length, labelsArray, labelsArray.Length);
 }
Example #7
0
 /// <summary>
 /// Updates a FaceRecognizer.
 /// </summary>
 /// <param name="src"></param>
 /// <param name="labels"></param>
 public void Update(IEnumerable <Mat> src, IEnumerable <int> labels)
 {
     if (src == null)
     {
         throw new ArgumentNullException("src");
     }
     if (labels == null)
     {
         throw new ArgumentNullException("labels");
     }
     IntPtr[] srcArray    = EnumerableEx.SelectPtrs(src);
     int[]    labelsArray = EnumerableEx.ToArray(labels);
     NativeMethods.contrib_FaceRecognizer_update(
         ptr, srcArray, srcArray.Length, labelsArray, labelsArray.Length);
 }
Example #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="mats"></param>
        public VectorOfMat(IEnumerable <Mat> mats)
        {
            if (mats == null)
            {
                throw new ArgumentNullException(nameof(mats));
            }

            var matPointers = EnumerableEx.SelectPtrs(mats);

            using (var matPointersPointer = new ArrayAddress1 <IntPtr>(matPointers))
            {
                ptr = NativeMethods.vector_Mat_new3(
                    matPointersPointer.Pointer,
                    new IntPtr(matPointers.Length));
            }
        }
        /// <summary>
        /// Add descriptors to train descriptor collection.
        /// </summary>
        /// <param name="descriptors">Descriptors to add. Each descriptors[i] is a descriptors set from one image.</param>
        public virtual void Add(IEnumerable <Mat> descriptors)
        {
            ThrowIfDisposed();
            if (descriptors == null)
            {
                throw new ArgumentNullException(nameof(descriptors));
            }

            Mat[] descriptorsArray = EnumerableEx.ToArray(descriptors);
            if (descriptorsArray.Length == 0)
            {
                return;
            }

            IntPtr[] descriptorsPtrs = EnumerableEx.SelectPtrs(descriptorsArray);
            NativeMethods.features2d_DescriptorMatcher_add(ptr, descriptorsPtrs, descriptorsPtrs.Length);
        }
Example #10
0
        public Status ComposePanorama(IEnumerable <Mat> images, OutputArray pano)
        {
            if (images == null)
            {
                throw new ArgumentNullException("images");
            }
            if (pano == null)
            {
                throw new ArgumentNullException("pano");
            }
            pano.ThrowIfNotReady();

            IntPtr[] imagesPtrs = EnumerableEx.SelectPtrs(images);
            int      status     = NativeMethods.stitching_Stitcher_composePanorama2_MatArray(
                ptr, imagesPtrs, imagesPtrs.Length, pano.CvPtr);

            pano.Fix();
            return((Status)status);
        }
Example #11
0
        /// <summary>
        /// select the 512 "best description pairs"
        /// </summary>
        /// <param name="images">grayscale images set</param>
        /// <param name="keypoints">set of detected keypoints</param>
        /// <param name="corrThresh">correlation threshold</param>
        /// <param name="verbose">print construction information</param>
        /// <returns>list of best pair indexes</returns>
        public int[] SelectPairs(IEnumerable <Mat> images, out KeyPoint[][] keypoints,
                                 double corrThresh = 0.7, bool verbose = true)
        {
            if (images == null)
            {
                throw new ArgumentNullException(nameof(images));
            }

            IntPtr[] imagesPtrs = EnumerableEx.SelectPtrs(images);

            using (var outVec = new VectorOfInt32())
                using (var keypointsVec = new VectorOfVectorKeyPoint())
                {
                    NativeMethods.features2d_FREAK_selectPairs(ptr, imagesPtrs, imagesPtrs.Length,
                                                               keypointsVec.CvPtr, corrThresh, verbose ? 1 : 0, outVec.CvPtr);
                    keypoints = keypointsVec.ToArray();
                    return(outVec.ToArray());
                }
        }
Example #12
0
        /// <summary>
        /// Modification of fastNlMeansDenoisingMulti function for colored images sequences
        /// </summary>
        /// <param name="srcImgs">Input 8-bit 3-channel images sequence. All images should have the same type and size.</param>
        /// <param name="dst">Output image with the same size and type as srcImgs images.</param>
        /// <param name="imgToDenoiseIndex">Target image to denoise index in srcImgs sequence</param>
        /// <param name="temporalWindowSize">Number of surrounding images to use for target image denoising. Should be odd.
        /// Images from imgToDenoiseIndex - temporalWindowSize / 2 to imgToDenoiseIndex - temporalWindowSize / 2 from srcImgs
        /// will be used to denoise srcImgs[imgToDenoiseIndex] image.</param>
        /// <param name="h">Parameter regulating filter strength for luminance component. Bigger h value perfectly removes noise
        /// but also removes image details, smaller h value preserves details but also preserves some noise.</param>
        /// <param name="hColor"> The same as h but for color components.</param>
        /// <param name="templateWindowSize">Size in pixels of the template patch that is used to compute weights. Should be odd. Recommended value 7 pixels</param>
        /// <param name="searchWindowSize">Size in pixels of the window that is used to compute weighted average for given pixel.
        /// Should be odd. Affect performance linearly: greater searchWindowsSize - greater denoising time. Recommended value 21 pixels</param>
        public static void FastNlMeansDenoisingColoredMulti(IEnumerable <InputArray> srcImgs, OutputArray dst,
                                                            int imgToDenoiseIndex, int temporalWindowSize, float h = 3, float hColor = 3,
                                                            int templateWindowSize = 7, int searchWindowSize = 21)
        {
            if (srcImgs == null)
            {
                throw new ArgumentNullException("srcImgs");
            }
            if (dst == null)
            {
                throw new ArgumentNullException("dst");
            }
            dst.ThrowIfNotReady();
            IntPtr[] srcImgPtrs = EnumerableEx.SelectPtrs(srcImgs);

            NativeMethods.photo_fastNlMeansDenoisingColoredMulti(srcImgPtrs, srcImgPtrs.Length, dst.CvPtr, imgToDenoiseIndex,
                                                                 templateWindowSize, h, hColor, templateWindowSize, searchWindowSize);
            dst.Fix();
        }
Example #13
0
        /// <summary>
        /// Try to stitch the given images.
        /// </summary>
        /// <param name="images">Input images.</param>
        /// <param name="pano">Final pano.</param>
        /// <returns>Status code.</returns>
        public Status Stitch(IEnumerable <Mat> images, OutputArray pano)
        {
            if (images == null)
            {
                throw new ArgumentNullException(nameof(images));
            }
            if (pano == null)
            {
                throw new ArgumentNullException(nameof(pano));
            }
            pano.ThrowIfNotReady();

            IntPtr[] imagesPtrs = EnumerableEx.SelectPtrs(images);

            Status status = (Status)NativeMethods.stitching_Stitcher_stitch1_MatArray(
                ptr, imagesPtrs, imagesPtrs.Length, pano.CvPtr);

            pano.Fix();

            return(status);
        }
Example #14
0
        public Status EstimateTransform(IEnumerable <Mat> images, Rect[][] rois)
        {
            if (images == null)
            {
                throw new ArgumentNullException("images");
            }
            if (rois == null)
            {
                throw new ArgumentNullException("rois");
            }

            IntPtr[] imagesPtrs = EnumerableEx.SelectPtrs(images);

            using (var roisPointer = new ArrayAddress2 <Rect>(rois))
            {
                int status = NativeMethods.stitching_Stitcher_estimateTransform_MatArray2(
                    ptr, imagesPtrs, imagesPtrs.Length,
                    roisPointer.Pointer, roisPointer.Dim1Length, roisPointer.Dim2Lengths);
                return((Status)status);
            }
        }
Example #15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="gaussPyr"></param>
        /// <param name="dogPyr"></param>
        /// <returns></returns>
        public KeyPoint[] FindScaleSpaceExtrema(IEnumerable <Mat> gaussPyr, IEnumerable <Mat> dogPyr)
        {
            ThrowIfDisposed();
            if (gaussPyr == null)
            {
                throw new ArgumentNullException("gaussPyr");
            }
            if (dogPyr == null)
            {
                throw new ArgumentNullException("dogPyr");
            }

            IntPtr[] gaussPyrPtrs = EnumerableEx.SelectPtrs(gaussPyr);
            IntPtr[] dogPyrPtrs   = EnumerableEx.SelectPtrs(dogPyr);

            using (VectorOfKeyPoint keyPointsVec = new VectorOfKeyPoint())
            {
                NativeMethods.nonfree_SIFT_findScaleSpaceExtrema(ptr, gaussPyrPtrs, gaussPyrPtrs.Length,
                                                                 dogPyrPtrs, dogPyrPtrs.Length, keyPointsVec.CvPtr);
                return(keyPointsVec.ToArray());
            }
        }
        /// <summary>
        /// Find one best match for each query descriptor (if mask is empty).
        /// </summary>
        /// <param name="queryDescriptors"></param>
        /// <param name="masks"></param>
        /// <returns></returns>
        public DMatch[] Match(Mat queryDescriptors, Mat[] masks = null)
        {
            ThrowIfDisposed();
            if (queryDescriptors == null)
            {
                throw new ArgumentNullException(nameof(queryDescriptors));
            }

            var masksPtrs = new IntPtr[0];

            if (masks != null)
            {
                masksPtrs = EnumerableEx.SelectPtrs(masks);
            }

            using (var matchesVec = new VectorOfDMatch())
            {
                NativeMethods.features2d_DescriptorMatcher_match2(
                    ptr, queryDescriptors.CvPtr, matchesVec.CvPtr, masksPtrs, masksPtrs.Length);
                return(matchesVec.ToArray());
            }
        }
Example #17
0
        /// <summary>
        /// Compute the descriptors for a keypoints collection detected in image collection.
        /// </summary>
        /// <param name="images">Image collection.</param>
        /// <param name="keypoints">Input keypoints collection. keypoints[i] is keypoints detected in images[i].
        /// Keypoints for which a descriptor cannot be computed are removed.</param>
        /// <param name="descriptors">Descriptor collection. descriptors[i] are descriptors computed for set keypoints[i].</param>
        public virtual void Compute(IEnumerable <Mat> images, ref KeyPoint[][] keypoints, IEnumerable <Mat> descriptors)
        {
            if (images == null)
            {
                throw new ArgumentNullException("images");
            }
            if (descriptors == null)
            {
                throw new ArgumentNullException("descriptors");
            }

            IntPtr[] imagesPtrs      = EnumerableEx.SelectPtrs(images);
            IntPtr[] descriptorsPtrs = EnumerableEx.SelectPtrs(descriptors);

            using (var keypointsVec = new VectorOfVectorKeyPoint(keypoints))
            {
                NativeMethods.features2d_DescriptorExtractor_compute2(
                    ptr, imagesPtrs, imagesPtrs.Length, keypointsVec.CvPtr,
                    descriptorsPtrs, descriptorsPtrs.Length);

                keypoints = keypointsVec.ToArray();
            }
        }
        /// <summary>
        /// Find best matches for each query descriptor which have distance less than
        /// maxDistance (in increasing order of distances).
        /// </summary>
        /// <param name="queryDescriptors"></param>
        /// <param name="maxDistance"></param>
        /// <param name="masks"></param>
        /// <param name="compactResult"></param>
        /// <returns></returns>
        public DMatch[][] RadiusMatch(Mat queryDescriptors, float maxDistance, Mat[] masks = null, bool compactResult = false)
        {
            ThrowIfDisposed();
            if (queryDescriptors == null)
            {
                throw new ArgumentNullException(nameof(queryDescriptors));
            }

            var masksPtrs = new IntPtr[0];

            if (masks != null)
            {
                masksPtrs = EnumerableEx.SelectPtrs(masks);
            }

            using (var matchesVec = new VectorOfVectorDMatch())
            {
                NativeMethods.features2d_DescriptorMatcher_radiusMatch2(
                    ptr, queryDescriptors.CvPtr, matchesVec.CvPtr, maxDistance,
                    masksPtrs, masksPtrs.Length, compactResult ? 1 : 0);
                return(matchesVec.ToArray());
            }
        }