perspectiveTransform error for ORB detector [closed]

asked 2016-10-28 00:42:12 -0500

ElectronicEng2015 gravatar image

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

            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)
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by berak
close date 2016-10-29 02:54:19.223579



could you check, if H is simply empty ? (can happen with findHomography !)

berak gravatar imageberak ( 2016-10-28 00:51:08 -0500 )edit

I checked H as suggested, but it is a 3x3 matrix with valid values

ElectronicEng2015 gravatar imageElectronicEng2015 ( 2016-10-28 01:53:04 -0500 )edit

I was checking in detail the performance of the homography matrix, and as you say it eventually becomes I just applied perspective transform when the matrix is not empty thank you very much

ElectronicEng2015 gravatar imageElectronicEng2015 ( 2016-10-29 02:42:31 -0500 )edit