[英]Issues compiling C++ Script with OpenCV and OpenCV-Contrib on MinGW g++ Windows
作为一个新项目的开始,我想在 opencv 中使用检测尺度不变图像。 首先,我尝试简单地编译并运行从opencv 文档中找到的示例脚本(尽管修改得非常轻微)
#include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/features2d.hpp>
#include <opencv2/xfeatures2d.hpp>
#include <chrono>
using namespace cv;
using namespace cv::xfeatures2d;
using namespace std;
using std::cout;
using std::endl;
int main( int argc, char* argv[] )
{
auto start = chrono::steady_clock::now();
CommandLineParser parser( argc, argv, "{@input | box.png | input image}" );
Mat src = imread( samples::findFile( parser.get<String>( "@input" ) ), IMREAD_GRAYSCALE );
if ( src.empty() )
{
cout << "Could not open or find the image!\n" << endl;
cout << "Usage: " << argv[0] << " <Input image>" << endl;
return -1;
}
//-- Step 1: Detect the keypoints using SURF Detector
int minHessian = 400;
Ptr<SURF> detector = SURF::create( minHessian );
std::vector<KeyPoint> keypoints;
detector->detect( src, keypoints );
auto end = chrono::steady_clock::now();
cout << "Elapsed time in milliseconds: "
<< chrono::duration_cast<chrono::milliseconds>(end - start).count()
<< " ms" << endl;
//-- Draw keypoints
Mat img_keypoints;
drawKeypoints( src, keypoints, img_keypoints );
//-- Show detected (drawn) keypoints
imshow("SURF Keypoints", img_keypoints );
waitKey();
return 0;
}
这在 mac 上编译并运行完美,通过自制软件安装了 opencv,并使用 -std=c++11。
然而,在 Windows(我需要它运行的操作系统)上,我遇到了多个不同的错误,我已经调查并尝试解决了这些错误,我将在下面列出,但我无法正常工作。 我并不介意解决这个问题的方法,而且我无法让任何工作,并且总体上无法让脚本运行。
使用 Cmake 创建 OpenCV4.5.5
我安装了 OpenCV4.5.5,(尝试启用和禁用“OPENCV_ENABLE_NONFREE”),将 OpenCV_contrib-4.x 模块文件夹添加到 OPENCV_EXTRA_MODULES_PATH,为 mingw 生成,运行 mingw32-make install,并使用包含、bin 和 lib 链接进行编译. 它编译得很好,虽然运行它导致
OpenCV(4.5.5) Error: The function/feature is not implemented (This algorithm is patented and is excluded in this configuration; Set OPENCV_ENABLE_NONFREE CMake option and
rebuild the library) in create, file C:\Users\playtech\Downloads\opencv_contrib-4.x\opencv_contrib-4.x\modules\xfeatures2d\src\surf.cpp, line 1029
使用 Cmake 创建 OpenCV3.4.2
在网上看到 OpenCV 的早期版本可能允许我使用 SURF,尽管在执行与上述相同但使用 OpenCV/openCV contrib 3.4.2 并运行 mingw32-make install 之后,达到 28%
[ 28%] Building CXX object modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_msmf.cpp.obj
在遇到太多不合适的错误之前。
使用其他 OpenCV
我假设 OpenCV 需要为 MinGW 而不是 Vsc 或 Mac 构建,以便能够为 MinGW g++ 进行编译,不用说,当我尝试使用相同的文件夹和相同的 Z644B1F5211D644EC527278 上的命令时
C:\Users\playtech\AppData\Local\Temp\ccaW9CKk.o:main.cpp:(.text+0x119): undefined reference to `cv::CommandLineParser::CommandLineParser(int, char const* const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
C:\Users\playtech\AppData\Local\Temp\ccaW9CKk.o:main.cpp:(.text+0x1ae): undefined reference to `cv::samples::findFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, bool)'
C:\Users\playtech\AppData\Local\Temp\ccaW9CKk.o:main.cpp:(.text+0x1c7): undefined reference to `cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
C:\Users\playtech\AppData\Local\Temp\ccaW9CKk.o:main.cpp:(.text+0x20f): undefined reference to `cv::Mat::empty() const'
C:\Users\playtech\AppData\Local\Temp\ccaW9CKk.o:main.cpp:(.text+0x2c3): undefined reference to `cv::xfeatures2d::SURF::create(double, int, int, bool, bool)'
C:\Users\playtech\AppData\Local\Temp\ccaW9CKk.o:main.cpp:(.text+0x2ed): undefined reference to `cv::noArray()'
C:\Users\playtech\AppData\Local\Temp\ccaW9CKk.o:main.cpp:(.text+0x3be): undefined reference to `cv::Mat::Mat()'
C:\Users\playtech\AppData\Local\Temp\ccaW9CKk.o:main.cpp:(.text+0x42e): undefined reference to `cv::drawKeypoints(cv::_InputArray const&, std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> > const&, cv::_InputOutputArray const&, cv::Scalar_<double> const&, cv::DrawMatchesFlags)'
C:\Users\playtech\AppData\Local\Temp\ccaW9CKk.o:main.cpp:(.text+0x4a4): undefined reference to `cv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
C:\Users\playtech\AppData\Local\Temp\ccaW9CKk.o:main.cpp:(.text+0x4db): undefined reference to `cv::waitKey(int)'
C:\Users\playtech\AppData\Local\Temp\ccaW9CKk.o:main.cpp:(.text+0x4ec): undefined reference to `cv::Mat::~Mat()'
C:\Users\playtech\AppData\Local\Temp\ccaW9CKk.o:main.cpp:(.text+0x510): undefined reference to `cv::Mat::~Mat()'
C:\Users\playtech\AppData\Local\Temp\ccaW9CKk.o:main.cpp:(.text+0x51f): undefined reference to `cv::CommandLineParser::~CommandLineParser()'
C:\Users\playtech\AppData\Local\Temp\ccaW9CKk.o:main.cpp:(.text+0x627): undefined reference to `cv::Mat::~Mat()'
C:\Users\playtech\AppData\Local\Temp\ccaW9CKk.o:main.cpp:(.text+0x655): undefined reference to `cv::Mat::~Mat()'
C:\Users\playtech\AppData\Local\Temp\ccaW9CKk.o:main.cpp:(.text+0x664): undefined reference to `cv::CommandLineParser::~CommandLineParser()'
C:\Users\playtech\AppData\Local\Temp\ccaW9CKk.o:main.cpp:(.text$_ZNK2cv17CommandLineParser3getINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEET_RKS7_b[_ZNK2cv17CommandLineParser3getINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEET_RKS7_b]+0x4b): undefined reference to `cv::CommandLineParser::getByName(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, cv::Param, void*) const'
collect2.exe: error: ld returned 1 exit status
. 我真正想要的是能够在 MinGW g++ windows 上编译,并让它运行并显示与 mac 相同的 window。 然而,这可能需要完成并不重要,只要它有效。
此外,该项目的下一步将是检测图像(尺度不变)及其坐标,而不仅仅是特征。 如果有一个替代方案可以产生比 xfeature SURF 识别更好的结果,我也想知道/可能改变它。 谢谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.