Search code examples
c#opencvemgucv

Exception Unhandled : Emgu.CV.Util.CvException: 'OpenCV: '


I'm trying to find matched keypoints between two frame that in live video stream. But I encounter the "Exception Unhandled" error. Here are the details of error:Error Details

And here is my class in question:

       public static VectorOfKeyPoint[] Matches(List<Mat> imList)
        {
            int k = 2;
            double uniquenessT = 0.8;
            Mat homography = new Mat();
            Mat mask = new Mat();
            VectorOfKeyPoint modelKeyPoints = new VectorOfKeyPoint();
            VectorOfKeyPoint observedKeyPoints = new VectorOfKeyPoint();
            VectorOfVectorOfDMatch matches = new VectorOfVectorOfDMatch();
            using (UMat uModelImage = imList[0].GetUMat(Emgu.CV.CvEnum.AccessType.Read))
            using (UMat uObservedImage = imList[1].GetUMat(Emgu.CV.CvEnum.AccessType.Read))
            {
                FastFeatureDetector fastCPU = new FastFeatureDetector(10, true);
                UMat modelDescriptors = new UMat();
                fastCPU.DetectAndCompute(uModelImage, null, modelKeyPoints, modelDescriptors, false);

                UMat observedDescriptors = new UMat();
                fastCPU.DetectAndCompute(uObservedImage, null, observedKeyPoints, observedDescriptors, false);

                BFMatcher matcher = new BFMatcher(DistanceType.L2);
                matcher.Add(modelDescriptors);
                matcher.KnnMatch(observedDescriptors, matches, k, null);
                mask = new Mat(matches.Size, 1, Emgu.CV.CvEnum.DepthType.Cv8U, 1);
                mask.SetTo(new MCvScalar(255));
                Features2DToolbox.VoteForUniqueness(matches, uniquenessT, mask);
                int nonZeroCount = CvInvoke.CountNonZero(mask);
                if (nonZeroCount >= 4)
                {
                    nonZeroCount = Features2DToolbox.VoteForSizeAndOrientation(modelKeyPoints, observedKeyPoints,
                       matches, mask, 1.5, 20);
                    if (nonZeroCount >= 4)
                        homography = Features2DToolbox.GetHomographyMatrixFromMatchedFeatures(modelKeyPoints,
                           observedKeyPoints, matches, mask, 2);
                }

                VectorOfKeyPoint[] result = null;

                if (homography != null)
                {
                    result[0] = modelKeyPoints;
                    result[1] = observedKeyPoints;
                }
                return result;
            }
        }

´´´

Thanks for your helps.


Solution

  • Thanks to everyone who let me solve the issue myself. There are the changes on the code.

    using(ORBDetector detector = new ORBDetector())
    {
    detector.DetectAndCompute(uModelImage, null, modelKeyPoints, modelDescriptors, false);
    detector.DetectAndCompute(uObservedImage, null, observedKeyPoints, 
    observedDescriptors, false);