OpenCV - match SURF points runtime error

asked 2015-01-14 09:36:30 -0500

colin747 gravatar image

updated 2015-01-15 07:49:40 -0500

I have a program which matches feature points found in a template image to those shown in the video feed. When I run the program I am getting the following error:

OpenCV Error: Assertion failed (i1 >= 0 && i1 < static_cast<int>(keypoints1.size())) in drawMatches, file bin/opencv-2.4.7/modules/features2d/src/draw.cpp, line 207
terminate called after throwing an instance of 'cv::Exception'
  what():  bin/opencv-2.4.7/modules/features2d/src/draw.cpp:207: error: (-215) i1 >= 0 && i1 < static_cast<int>(keypoints1.size()) in function drawMatches

Aborted

This is the function drawMatches that is mentioned above:

drawMatches(img_1, templateKeypoints, frames, keypoints_1, good_matches, img_matches, cv::Scalar::all(-1), cv::Scalar::all(-1), std::vector<char>(), cv::DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);

From what I've read I believe the problem is to do with if the feature points found in the video do not match the feature points in the template image then the program is aborting.

min_dist = 100;      
for(int i = 0; i < img_descriptors_1.rows; i++) {
        if(matches[i].distance <= 3 * min_dist) {
          good_matches.push_back(matches[i]);
        }
      }

I am looking for the video feed to run constantly even if no matches are present.

EDIT: I've noticed if I repeatedly try to run the program I sometimes get an alternative error message:

OpenCV Error: Assertion failed (npoints >= 0 && points2.checkVector(2) == npoints && points1.type() == points2.type()) in findHomography, file /home/colin/bin/opencv-2.4.7/modules/calib3d/src/fundam.cpp, line 1074
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/colin/bin/opencv-2.4.7/modules/calib3d/src/fundam.cpp:1074: error: (-215) npoints >= 0 && points2.checkVector(2) == npoints && points1.type() == points2.type() in function findHomography

Aborted
edit retag flag offensive close merge delete

Comments

Your error message appears to indicate you are using OpenCV 2.4.7 which is not the most recent, have you tried the latest 2.4 branch version? Maybe your bug is already fixed there

codingTornado gravatar imagecodingTornado ( 2015-01-15 08:35:45 -0500 )edit

I wrote the code using the OpenCV doc example, when I try it on a separate program with just still images it works fine so I'm assuming there is a problem in my code somewhere.

colin747 gravatar imagecolin747 ( 2015-01-16 03:26:34 -0500 )edit