예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="images"></param>
        /// <param name="names"></param>
        public static void ShowImages(IEnumerable <Mat> images, IEnumerable <string> names)
        {
            if (images == null)
            {
                throw new ArgumentNullException("images");
            }
            if (names == null)
            {
                throw new ArgumentNullException("names");
            }

            Mat[]    imagesArray = EnumerableEx.ToArray(images);
            string[] namesArray  = EnumerableEx.ToArray(names);

            if (imagesArray.Length == 0)
            {
                return;
            }
            if (namesArray.Length < imagesArray.Length)
            {
                throw new ArgumentException("names.Length < images.Length");
            }

            List <Window> windows = new List <Window>();

            for (int i = 0; i < imagesArray.Length; i++)
            {
                windows.Add(new Window(namesArray[i], imagesArray[i]));
            }

            Cv.WaitKey();

            foreach (Window w in windows)
            {
                w.Close();
            }
        }
예제 #2
0
        /// <summary>
        /// Draw keypoints.
        /// </summary>
        /// <param name="image"></param>
        /// <param name="keypoints"></param>
        /// <param name="outImage"></param>
        /// <param name="color"></param>
        /// <param name="flags"></param>
        public static void DrawKeypoints(Mat image, IEnumerable <KeyPoint> keypoints, Mat outImage,
                                         Scalar?color = null, DrawMatchesFlags flags = DrawMatchesFlags.Default)
        {
            if (image == null)
            {
                throw new ArgumentNullException(nameof(image));
            }
            if (outImage == null)
            {
                throw new ArgumentNullException(nameof(outImage));
            }
            if (keypoints == null)
            {
                throw new ArgumentNullException(nameof(keypoints));
            }
            image.ThrowIfDisposed();
            outImage.ThrowIfDisposed();

            KeyPoint[] keypointsArray = EnumerableEx.ToArray(keypoints);
            Scalar     color0         = color.GetValueOrDefault(Scalar.All(-1));

            NativeMethods.features2d_drawKeypoints(image.CvPtr, keypointsArray, keypointsArray.Length,
                                                   outImage.CvPtr, color0, (int)flags);
        }
예제 #3
0
        /// <summary>
        /// N x 1 の行列(ベクトル)として初期化し、指定した配列からデータをコピーする
        /// </summary>
        /// <param name="enumerable">この行列にコピーされるデータ</param>
#else
        /// <summary>
        /// Initializes as N x 1 matrix and copys array data to this
        /// </summary>
        /// <param name="enumerable">Source array data to be copied to this</param>
#endif
        public static MatOfByte3 FromArray(IEnumerable <Vec3b> enumerable)
        {
            return(FromArray(EnumerableEx.ToArray(enumerable)));
        }
예제 #4
0
        /// <summary>
        /// N x 1 の行列(ベクトル)として初期化し、指定した配列からデータをコピーする
        /// </summary>
        /// <param name="enumerable">この行列にコピーされるデータ</param>
#else
        /// <summary>
        /// Initializes as N x 1 matrix and copys array data to this
        /// </summary>
        /// <param name="enumerable">Source array data to be copied to this</param>
#endif
        public static MatOfPoint3i FromArray(IEnumerable <Point3i> enumerable)
        {
            return(FromArray(EnumerableEx.ToArray(enumerable)));
        }
예제 #5
0
        /// <summary>
        /// N x 1 の行列(ベクトル)として初期化し、指定した配列からデータをコピーする
        /// </summary>
        /// <param name="enumerable">この行列にコピーされるデータ</param>
#else
        /// <summary>
        /// Initializes as N x 1 matrix and copys array data to this
        /// </summary>
        /// <param name="enumerable">Source array data to be copied to this</param>
#endif
        public static MatOfDouble FromArray(IEnumerable <double> enumerable)
        {
            return(FromArray(EnumerableEx.ToArray(enumerable)));
        }
예제 #6
0
        /// <summary>
        /// N x 1 の行列(ベクトル)として初期化し、指定した配列からデータをコピーする
        /// </summary>
        /// <param name="enumerable">この行列にコピーされるデータ</param>
#else
        /// <summary>
        /// Initializes as N x 1 matrix and copys array data to this
        /// </summary>
        /// <param name="enumerable">Source array data to be copied to this</param>
#endif
        public static MatOfInt FromArray(IEnumerable <int> enumerable)
        {
            return(FromArray(EnumerableEx.ToArray(enumerable)));
        }
예제 #7
0
        /// <summary>
        /// N x 1 の行列(ベクトル)として初期化し、指定した配列からデータをコピーする
        /// </summary>
        /// <param name="enumerable">この行列にコピーされるデータ</param>
#else
        /// <summary>
        /// Initializes as N x 1 matrix and copys array data to this
        /// </summary>
        /// <param name="enumerable">Source array data to be copied to this</param>
#endif
        public static MatOfShort FromArray(IEnumerable <short> enumerable)
        {
            return(FromArray(EnumerableEx.ToArray(enumerable)));
        }
예제 #8
0
        /// <summary>
        /// N x 1 の行列(ベクトル)として初期化し、指定した配列からデータをコピーする
        /// </summary>
        /// <param name="enumerable">この行列にコピーされるデータ</param>
#else
        /// <summary>
        /// Initializes as N x 1 matrix and copys array data to this
        /// </summary>
        /// <param name="enumerable">Source array data to be copied to this</param>
#endif
        public static MatOfByte FromArray(IEnumerable <byte> enumerable)
        {
            return(FromArray(EnumerableEx.ToArray(enumerable)));
        }
예제 #9
0
        /// <summary>
        /// N x 1 の行列(ベクトル)として初期化し、指定した配列からデータをコピーする
        /// </summary>
        /// <param name="enumerable">この行列にコピーされるデータ</param>
#else
        /// <summary>
        /// Initializes as N x 1 matrix and copys array data to this
        /// </summary>
        /// <param name="enumerable">Source array data to be copied to this</param>
#endif
        public static MatOfDMatch FromArray(IEnumerable <DMatch> enumerable)
        {
            return(FromArray(EnumerableEx.ToArray(enumerable)));
        }
예제 #10
0
        /// <summary>
        /// N x 1 の行列(ベクトル)として初期化し、指定した配列からデータをコピーする
        /// </summary>
        /// <param name="enumerable">この行列にコピーされるデータ</param>
#else
        /// <summary>
        /// Initializes as N x 1 matrix and copys array data to this
        /// </summary>
        /// <param name="enumerable">Source array data to be copied to this</param>
#endif
        public static MatOfFloat4 FromArray(IEnumerable <Vec4f> enumerable)
        {
            return(FromArray(EnumerableEx.ToArray(enumerable)));
        }
예제 #11
0
        /// <summary>
        /// Draws matches of keypints from two images on output image.
        /// </summary>
        /// <param name="img1"></param>
        /// <param name="keypoints1"></param>
        /// <param name="img2"></param>
        /// <param name="keypoints2"></param>
        /// <param name="matches1To2"></param>
        /// <param name="outImg"></param>
        /// <param name="matchColor"></param>
        /// <param name="singlePointColor"></param>
        /// <param name="matchesMask"></param>
        /// <param name="flags"></param>
        public static void DrawMatches(Mat img1, IEnumerable <KeyPoint> keypoints1,
                                       Mat img2, IEnumerable <KeyPoint> keypoints2,
                                       IEnumerable <IEnumerable <DMatch> > matches1To2, Mat outImg,
                                       Scalar?matchColor = null, Scalar?singlePointColor = null,
                                       IEnumerable <IEnumerable <byte> > matchesMask = null,
                                       DrawMatchesFlags flags = DrawMatchesFlags.Default)
        {
            if (img1 == null)
            {
                throw new ArgumentNullException(nameof(img1));
            }
            if (img2 == null)
            {
                throw new ArgumentNullException(nameof(img2));
            }
            if (outImg == null)
            {
                throw new ArgumentNullException(nameof(outImg));
            }
            if (keypoints1 == null)
            {
                throw new ArgumentNullException(nameof(keypoints1));
            }
            if (keypoints2 == null)
            {
                throw new ArgumentNullException(nameof(keypoints2));
            }
            if (matches1To2 == null)
            {
                throw new ArgumentNullException(nameof(matches1To2));
            }
            img1.ThrowIfDisposed();
            img2.ThrowIfDisposed();
            outImg.ThrowIfDisposed();

            KeyPoint[] keypoints1Array  = EnumerableEx.ToArray(keypoints1);
            KeyPoint[] keypoints2Array  = EnumerableEx.ToArray(keypoints2);
            DMatch[][] matches1To2Array = EnumerableEx.SelectToArray(matches1To2, EnumerableEx.ToArray);
            int        matches1To2Size1 = matches1To2Array.Length;

            int[]  matches1To2Size2  = EnumerableEx.SelectToArray(matches1To2Array, dm => dm.Length);
            Scalar matchColor0       = matchColor.GetValueOrDefault(Scalar.All(-1));
            Scalar singlePointColor0 = singlePointColor.GetValueOrDefault(Scalar.All(-1));

            using (var matches1To2Ptr = new ArrayAddress2 <DMatch>(matches1To2Array))
            {
                if (matchesMask == null)
                {
                    NativeMethods.features2d_drawMatches2(img1.CvPtr, keypoints1Array, keypoints1Array.Length,
                                                          img2.CvPtr, keypoints2Array, keypoints2Array.Length,
                                                          matches1To2Ptr, matches1To2Size1, matches1To2Size2,
                                                          outImg.CvPtr, matchColor0, singlePointColor0,
                                                          null, 0, null, (int)flags);
                }
                else
                {
                    byte[][] matchesMaskArray = EnumerableEx.SelectToArray(matchesMask, EnumerableEx.ToArray);
                    int      matchesMaskSize1 = matches1To2Array.Length;
                    int[]    matchesMaskSize2 = EnumerableEx.SelectToArray(matchesMaskArray, dm => dm.Length);
                    using (var matchesMaskPtr = new ArrayAddress2 <byte>(matchesMaskArray))
                    {
                        NativeMethods.features2d_drawMatches2(img1.CvPtr, keypoints1Array, keypoints1Array.Length,
                                                              img2.CvPtr, keypoints2Array, keypoints2Array.Length,
                                                              matches1To2Ptr.Pointer, matches1To2Size1, matches1To2Size2,
                                                              outImg.CvPtr, matchColor0, singlePointColor0,
                                                              matchesMaskPtr, matchesMaskSize1, matchesMaskSize2, (int)flags);
                    }
                }
            }
        }