5

I have been working on an image stitching project using OpenCV 3.0. I use the findHomography function like so:

findHomography(imageOnePoints, imageTwoPoints, CV_RANSAC);

but when I try to compile my code, I am returned the following error messages:

stitch.cpp:111:75: error: ‘CV_RANSAC’ was not declared in this scope
 Mat homographyMatrix = findHomography(imageOnePoints, imageTwoPoints, CV_RANSAC);

stitch.cpp:111:84: error: ‘findHomography’ was not declared in this scope
 Mat homographyMatrix = findHomography(imageOnePoints, imageTwoPoints, CV_RANSAC);

I have already declared that I am using "namespace cv" so I do not need the preceeding "cv::". I am not sure what the problem is. Any advice on these errors would be greatly appreciated. Thank you!

Jacob Waite
  • 71
  • 1
  • 4
  • Try just `RANSAC`. http://docs.opencv.org/3.0-beta/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html#findhomography. If that doesn't work for you, the value is `8`. – beaker Aug 10 '15 at 21:37
  • Using just RANSAC didn't work so I changed it to 8, yet the findHomography function still is "not declared in this scope". – Jacob Waite Aug 10 '15 at 22:03
  • 1
    Just to be sure, you did `#include "opencv2/calib3d/calib3d.hpp"`, right? – beaker Aug 10 '15 at 23:29
  • I didn't, and when I added it everything compiled flawlessly! Well that fixed it. Thank you so much! How do I declare this post answered? – Jacob Waite Aug 11 '15 at 00:49
  • I'll go ahead and type up a quick answer, and then you can accept it in a bit. – beaker Aug 11 '15 at 00:51

3 Answers3

7

It turns out the header file for findHomography was missing:

#include "opencv2/calib3d/calib3d.hpp"
beaker
  • 16,331
  • 3
  • 32
  • 49
1

Latest OpenCV version, CV_RANSAC is renamed to RANSAC.

just use H = findHomography(ref, tst, RANSAC)

This should work.

Manish S
  • 801
  • 11
  • 12
0

Q1. CV_RANSAC was not declared.

Solution: CV_RANSAC => RANSAC

Q2. findHomography was not declared.

Solution: #include <opencv2/opencv.hpp> would be enough for most cases.

For this specific question you can also use #include <opencv2/calib3d/calib3d.hpp>

ChrisZZ
  • 1,521
  • 2
  • 17
  • 24