Esempio n. 1
0
 /// <summary>
 /// Writes data to a file storage.
 /// </summary>
 /// <param name="val"></param>
 public FileStorage Add(DMatch val)
 {
     ThrowIfDisposed();
     NativeMethods.core_FileStorage_shift_DMatch(ptr, val);
     GC.KeepAlive(this);
     return(this);
 }
Esempio n. 2
0
        /// <summary>
        /// Converts std::vector to managed array
        /// </summary>
        /// <returns></returns>
        public DMatch[][] ToArray()
        {
            int size1 = Size1;

            if (size1 == 0)
            {
                return(new DMatch[0][]);
            }
            long[] size2 = Size2;

            DMatch[][] ret = new DMatch[size1][];
            for (int i = 0; i < size1; i++)
            {
                ret[i] = new DMatch[size2[i]];
            }
            using (ArrayAddress2 <DMatch> retPtr = new ArrayAddress2 <DMatch>(ret))
            {
                NativeMethods.vector_vector_DMatch_copy(ptr, retPtr);
            }
            return(ret);
        }
Esempio n. 3
0
        /// <summary>
        /// Converts std::vector to managed array
        /// </summary>
        /// <returns></returns>
        public DMatch[][] ToArray()
        {
            var size1 = Size1;

            if (size1 == 0)
            {
                return(new DMatch[0][]);
            }
            var size2 = Size2;

            var ret = new DMatch[size1][];

            for (var i = 0; i < size1; i++)
            {
                ret[i] = new DMatch[size2[i]];
            }
            using (var retPtr = new ArrayAddress2 <DMatch>(ret))
            {
                NativeMethods.vector_vector_DMatch_copy(ptr, retPtr);
                GC.KeepAlive(this);
            }
            return(ret);
        }
Esempio n. 4
0
        /// <summary>
        /// Converts std::vector to managed array
        /// </summary>
        /// <returns></returns>
        public DMatch[][] ToArray()
        {
            var size1 = GetSize1();

            if (size1 == 0)
            {
                return(Array.Empty <DMatch[]>());
            }
            var size2 = GetSize2();

            var ret = new DMatch[size1][];

            for (var i = 0; i < size1; i++)
            {
                ret[i] = new DMatch[size2[i]];
            }
            using (var retPtr = new ArrayAddress2 <DMatch>(ret))
            {
                NativeMethods.vector_vector_DMatch_copy(ptr, retPtr.GetPointer());
                GC.KeepAlive(this);
            }
            return(ret);
        }
 public static extern ExceptionStatus core_FileNode_read_DMatch(IntPtr node, out DMatch returnValue);
Esempio n. 6
0
 public static extern ExceptionStatus core_FileStorage_shift_DMatch(IntPtr fs, DMatch val);
Esempio n. 7
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="matches1to2"></param>
        /// <param name="correctMatches1to2Mask"></param>
        /// <returns>recallPrecisionCurve</returns>
        public static Point2f[] ComputeRecallPrecisionCurve(
            DMatch[][] matches1to2, byte[][] correctMatches1to2Mask)
        {
            if (matches1to2 == null)
                throw new ArgumentNullException(nameof(matches1to2));
            if (correctMatches1to2Mask == null)
                throw new ArgumentNullException(nameof(correctMatches1to2Mask));

            using (var dm = new ArrayAddress2<DMatch>(matches1to2))
            using (var cm = new ArrayAddress2<byte>(correctMatches1to2Mask))
            using (var recall = new VectorOfPoint2f())
            {
                NativeMethods.features2d_computeRecallPrecisionCurve(
                    dm.Pointer, dm.Dim1Length, dm.Dim2Lengths,
                    cm.Pointer, cm.Dim1Length, cm.Dim2Lengths,
                    recall.CvPtr);
                return recall.ToArray();
            }
        }
 public static extern void core_FileStorage_shift_DMatch(IntPtr fs, DMatch val);
 public static extern void features2d_drawMatches1(IntPtr img1, KeyPoint[] keypoints1, int keypoints1Length,
     IntPtr img2, KeyPoint[] keypoints2, int keypoints2Length,
     DMatch[] matches1to2, int matches1to2Length, IntPtr outImg,
     Scalar matchColor, Scalar singlePointColor,
     byte[] matchesMask, int matchesMaskLength, int flags);
Esempio n. 10
0
 private static void VoteForUniqueness(DMatch[][] matches, Mat mask, float uniqnessThreshold = 0.80f)
 {
     byte[] maskData = new byte[matches.Length];
     GCHandle maskHandle = GCHandle.Alloc(maskData, GCHandleType.Pinned);
     using (Mat m = new Mat(matches.Length, 1, MatType.CV_8U, maskHandle.AddrOfPinnedObject()))
     {
         mask.CopyTo(m);
         for (int i = 0; i < matches.Length; i++)
         {
             //This is also known as NNDR Nearest Neighbor Distance Ratio
             if ((matches[i][0].Distance / matches[i][1].Distance) <= uniqnessThreshold)
                 maskData[i] = 255;
             else
                 maskData[i] = 0;
         }
         m.CopyTo(mask);
     }
     maskHandle.Free();
 }
Esempio n. 11
0
        static int VoteForSizeAndOrientation(KeyPoint[] modelKeyPoints, KeyPoint[] observedKeyPoints, DMatch[][] matches, Mat mask, float scaleIncrement, int rotationBins)
        {
            int idx = 0;
            int nonZeroCount = 0;
            byte[] maskMat = new byte[mask.Rows];
            GCHandle maskHandle = GCHandle.Alloc(maskMat, GCHandleType.Pinned);
            using (Mat m = new Mat(mask.Rows, 1, MatType.CV_8U, maskHandle.AddrOfPinnedObject()))
            {
                mask.CopyTo(m);
                List<float> logScale = new List<float>();
                List<float> rotations = new List<float>();
                double s, maxS, minS, r;
                maxS = -1.0e-10f; minS = 1.0e10f;

                //if you get an exception here, it's because you're passing in the model and observed keypoints backwards.  Just switch the order.
                for (int i = 0; i < maskMat.Length; i++)
                {
                    if (maskMat[i] > 0)
                    {
                        KeyPoint observedKeyPoint = observedKeyPoints[i];
                        KeyPoint modelKeyPoint = modelKeyPoints[matches[i][0].TrainIdx];
                        s = Math.Log10(observedKeyPoint.Size / modelKeyPoint.Size);
                        logScale.Add((float)s);
                        maxS = s > maxS ? s : maxS;
                        minS = s < minS ? s : minS;

                        r = observedKeyPoint.Angle - modelKeyPoint.Angle;
                        r = r < 0.0f ? r + 360.0f : r;
                        rotations.Add((float)r);
                    }
                }

                int scaleBinSize = (int)Math.Ceiling((maxS - minS) / Math.Log10(scaleIncrement));
                if (scaleBinSize < 2)
                    scaleBinSize = 2;
                float[] scaleRanges = { (float)minS, (float)(minS + scaleBinSize + Math.Log10(scaleIncrement)) };

                using (MatOfFloat scalesMat = new MatOfFloat(rows: logScale.Count, cols: 1, data: logScale.ToArray()))
                using (MatOfFloat rotationsMat = new MatOfFloat(rows: rotations.Count, cols: 1, data: rotations.ToArray()))
                using (MatOfFloat flagsMat = new MatOfFloat(logScale.Count, 1))
                using (Mat hist = new Mat())
                {
                    flagsMat.SetTo(new Scalar(0.0f));
                    float[] flagsMatFloat1 = flagsMat.ToArray();

                    int[] histSize = { scaleBinSize, rotationBins };
                    float[] rotationRanges = { 0.0f, 360.0f };
                    int[] channels = { 0, 1 };
                    Rangef[] ranges = { new Rangef(scaleRanges[0], scaleRanges[1]), new Rangef(rotations.Min(), rotations.Max()) };
                    double minVal, maxVal;

                    Mat[] arrs = { scalesMat, rotationsMat };
                    Cv2.CalcHist(arrs, channels, null, hist, 2, histSize, ranges);
                    Cv2.MinMaxLoc(hist, out minVal, out maxVal);

                    Cv2.Threshold(hist, hist, maxVal * 0.5, 0, ThresholdTypes.Tozero);
                    Cv2.CalcBackProject(arrs, channels, hist, flagsMat, ranges);

                    MatIndexer<float> flagsMatIndexer = flagsMat.GetIndexer();

                    for (int i = 0; i < maskMat.Length; i++)
                    {
                        if (maskMat[i] > 0)
                        {
                            if (flagsMatIndexer[idx++] != 0.0f)
                            {
                                nonZeroCount++;
                            }
                            else
                                maskMat[i] = 0;
                        }
                    }
                    m.CopyTo(mask);
                }
            }
            maskHandle.Free();

            return nonZeroCount;
        }
Esempio n. 12
0
 /// <summary>
 /// Compares by distance (less is better)
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public int CompareTo(DMatch other) => Distance.CompareTo(other.Distance);