Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not build with OpenCV 4 #4

Open
rburkey2005 opened this issue Sep 11, 2022 · 1 comment
Open

Does not build with OpenCV 4 #4

rburkey2005 opened this issue Sep 11, 2022 · 1 comment

Comments

@rburkey2005
Copy link

The compiler reports that numerous functions are "not declared in this scope".

Most of the problems are easy to fix — or at least, the error messages from the compiler are easy to eliminate — by adding the following to main.cpp:

#include <opencv2/highgui/highgui_c.h>
#include <opencv2/videoio/videoio_c.h>

After doing that, the only remaining symbols not declared are cvLoadImage and cvSaveImage. This is apparently because they no longer exist, and instead have been replaced by cv::imread and cv::imwrite. Unfortunately, the latter two are different enough from the former two that you'd need more knowledge than I have about OpenCV (namely, zero) to fix them.

I use Linux Mint, and I would simply have worked around the problem by installing OpenCV 2, but unfortunately this seems to be a rather difficult thing to do in recent versions of Linux Mint (and I assume, Ubuntu).

@rburkey2005
Copy link
Author

Well, I looked at this a little further, and I find that if I add the following to main.cpp, then at least main.cpp compiles without error. I don't claim that it works, just that it compiles:

// 2022-09-12 RSB --------------------------------------------
#include <opencv2/highgui/highgui_c.h>
#include <opencv2/videoio/videoio_c.h>
#include <opencv2/core/types_c.h>
IplImage * cvLoadImage(const char *filename)
{
  cv::Mat img = cv::imread(filename);
  IplImage copy = cvIplImage(img);
  return (new IplImage(copy));
}
int cvSaveImage(const char *filename, const CvArr *image)
{
  cv::Mat mat = cv::cvarrToMat(image);
  return (cv::imwrite(filename, mat));
}

However, the build fails further on, at marker.cpp. If to marker.cpp I add

#include <opencv2/highgui/highgui_c.h>

then the only error remaining in marker.cpp is

.../voussoir/marker.cpp:176:5: error: ‘cvFindHomography’ was not declared in this scope

But, cvFindHomography has been discontinued in favor of cv::FindHomography. Conceptually, the basic fix for this seems to be to add

#include <opencv2/calib3d.hpp>
#define cvFindHomography(src,dst,h) h = cv::findHomography((src),(dst))

Unfortunately, the datatypes of the src and dst parameters differ, so the compilation still fails due to this incompatibility. I haven't looked into that datatype incompatibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant