Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

perspectiveTransform error for ORB detector

Hello everyone, I have been trying to draw a bounding area for an object from its corresponding features in a video scene, but when it comes to run the perspectiveTransform function, it launches the following error: OpenCV ERROR: Assertion Failed (scn+1==m.cols) in cv::perspectiveTransform

I ran a similar program with the SURF and SIFT detectors and they did not show that error.

I present to you the programming code as follows:

            BFMatcher matcher(NORM_HAMMING, false);                        
            vector< DMatch > matches; // Descriptor matches
            std::vector< DMatch > good_matches;
            matcher.match(descriptor, descriptor_f, matches);

            double minDist;
            double maxDist;

            filterResultsByDistance( &matches, &good_matches, 2, &minDist, &maxDist);
            drawMatches(picture, keypoints, frame, keypoints_f, good_matches, img_matches, Scalar::all(-1), Scalar::all(-1), std::vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);

            /* Localize the object*/

            std::vector<Point2f> obj;
            std::vector<Point2f> scene; 

            for (size_t i = 0; i < good_matches.size(); i++)
            {
                //-- Get the keypoints from the good matches
                obj.push_back(keypoints[good_matches[i].queryIdx].pt);
                scene.push_back(keypoints_f[good_matches[i].trainIdx].pt);
            }

            Mat H = findHomography(obj, scene, RANSAC);

            //-- Get the corners from the image_1 ( the object to be "detected" )
            std::vector<Point2f> obj_corners(4);
            obj_corners[0] = cvPoint(0, 0); 
            obj_corners[1] = cvPoint(picture.cols, 0);
            obj_corners[2] = cvPoint(picture.cols, picture.rows); 
            obj_corners[3] = cvPoint(0, picture.rows);

            std::vector<Point2f> scene_corners(4);

            perspectiveTransform(obj_corners, scene_corners, H); // Error Assertion Failed (scn+1 == m.cols)