配置opencv环境踩过的坑
作者:互联网
众所周知,配环境是一个玄学问题,有问题的时候到处都是问题,在配置opencv
的时候再次感受到这感受,记录一下自己踩的坑,让大家少走些弯路(
首先给大家推荐一个教程,写得还是很清楚的,这个是网址,不过他也有一些需要注意的地方没有提到,所以这里把步骤简单列举,然后再把需要注意的地方提出来供大家参考。
不清楚版本号的具体影响,就尝试了3.9和3.12的cmake以及opencv的诸多版本,进行排列组合尝试,而且这个编译一次就要可能花费一个小时左右,并且还好多次给我卡在90%左右,弹出让人心肺骤停的进度条和报错信息···
步骤简介:
- 下载并安装
MinGW_posix
版本; - 下载并安装
cmake
,注意要安装至C盘; - 下载并安装
opencv
,注意不要安装至C盘; - 添加上述三个文件对应的环境变量;
- 在
cmake-gui
程序中,配置路径并进行Configuration,然后进行Generate; - 在
opencv
的安装路径下新建的opencv\build\x64\MinGW
文件夹下进入终端并且输入minGW32-make
进行编译,耗时约一个小时,完成后输入minGW32-make install
来装载;
以上步骤写得非常简略,开头的网址里更详细,下面主要来说下遇到的两个问题吧。
python2.7的调用问题
首先是第一步Finish之后就出现的问题
find_host_package(PythonInterp 2.7)' found wrong Python version,具体提示如下:
Found PythonInterp: C:/Users/LiuBing/AppData/Local/Programs/Python/Python38/python.exe (found suitable version "3.8.2", minimum required is "2.7")
CMake Warning at cmake/OpenCVDetectPython.cmake:81 (message):
CMake's 'find_host_package(PythonInterp 2.7)' found wrong Python version:
PYTHON_EXECUTABLE=C:/Users/LiuBing/AppData/Local/Programs/Python/Python38/python.exe
PYTHON_VERSION_STRING=3.8.2
Consider providing the 'PYTHON2_EXECUTABLE' variable via CMake command line
or environment variables
Call Stack (most recent call first):
cmake/OpenCVDetectPython.cmake:271 (find_python)
CMakeLists.txt:598 (include)
并且这个问题我之前还没注意,因为还是可以之间按照步骤操作的就没管,后来发现了就装了python2.7,甚至之后还装了python1.4,但是问题依然存在,殊不知在报错信息里就已经有了解决方法,所以说,多去阅读官方文档和第一手资料以及报错信息真的很有用,不能上来就搜索问题(虽然已经条件反射了)。
方法就是在环境变量里添加python2.7的路径,具体操作如下:
- 官方网址下载2.7版本的python;
- 打开设置的“系统”到“系统信息”到“高级系统设置”,选择“环境变量”,在系统变量里新建一个变量名为PYTHON2_EXECUTABLE,变量值为你下载的2.7版本的exe文件的位置,如
E:\Python2.7\python.exe
之后编译的时候就可以找到文件了,并且生成make文件
MinGW的版本问题
然后在运行minGW32-make
命令之后,出现这样一大堆的报错,进度卡在90%,排列组合很多次全都是一样的情况,心态很崩(
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:175:14: error: 'thread' in namespace 'std' does not name a type
std::thread second_workthread;
^~~~~~
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:175:9: note: 'std::thread' is defined in header '<thread>'; did you forget to '#include <thread>'?
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:82:1:
+#include <thread>
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:175:9:
std::thread second_workthread;
^~~
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:176:14: error: 'mutex' in namespace 'st
' does not name a type
std::mutex mtx;
^~~~~
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:176:9: note: 'std::mutex' is defined in header '<mutex>'; did you forget to '#include <mutex>'?
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:82:1:
+#include <mutex>
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:176:9:
std::mutex mtx;
^~~
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:177:14: error: 'condition_variable' in namespace 'std' does not name a type
std::condition_variable objectDetectorRun;
^~~~~~~~~~~~~~~~~~
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:177:9: note: 'std::condition_variable' is defined in header '<condition_variable>'; did you forget to '#include <condition_variable>'?
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:82:1:
+#include <condition_variable>
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:177:9:
std::condition_variable objectDetectorRun;
^~~
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:178:14: error: 'condition_variable' in namespace 'std' does not name a type
std::condition_variable objectDetectorThreadStartStop;
^~~~~~~~~~~~~~~~~~
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:178:9: note: 'std::condition_variable' is defined in header '<condition_variable>'; did you forget to '#include <condition_variable>'?
std::condition_variable objectDetectorThreadStartStop;
^~~
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp: In member function 'void cv::DetectionBasedTracker::SeparateDetectionWork::setParameters(const cv::DetectionBasedTracker::Parameters&)':
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:143:35: error: 'mutex' is not a member of 'std'
std::unique_lock<std::mutex> mtx_lock(mtx);
^~~~~
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:143:35: note: 'std::mutex' is defined in header '<mutex>'; did you forget to '#include <mutex>'?
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:143:35: error: 'mutex' is not a member of 'std'
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:143:35: note: 'std::mutex' is defined in header '<mutex>'; did you forget to '#include <mutex>'?
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:143:40: error: template argument 1 is invalid
std::unique_lock<std::mutex> mtx_lock(mtx);
^
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:143:51: error: 'mtx' was not declared in this scope
std::unique_lock<std::mutex> mtx_lock(mtx);
^~~
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:143:42: warning: unused variable 'mtx_lock' [-Wunused-variable]
std::unique_lock<std::mutex> mtx_lock(mtx);
^~~~~~~~
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp: In member function 'void cv::DetectionBasedTracker::SeparateDetectionWork::init()':
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:156:35: error: 'mutex' is not a member of 'std'
std::unique_lock<std::mutex> mtx_lock(mtx);
^~~~~
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:156:35: note: 'std::mutex' is defined in header '<mutex>'; did you forget to '#include <mutex>'?
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:156:35: error: 'mutex' is not a member of 'std'
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:156:35: note: 'std::mutex' is defined in header '<mutex>'; did you forget to '#include <mutex>'?
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:156:40: error: template argument 1 is invalid
std::unique_lock<std::mutex> mtx_lock(mtx);
^
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:156:51: error: 'mtx' was not declared in this scope
std::unique_lock<std::mutex> mtx_lock(mtx);
^~~
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:164:13: error: 'objectDetectorThreadStartStop' was not declared in this scope
objectDetectorThreadStartStop.notify_one();
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:164:13: note: suggested alternative: 'timeWhenDetectingThreadStartedWork'
objectDetectorThreadStartStop.notify_one();
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
timeWhenDetectingThreadStartedWork
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:156:42: warning: unused variable 'mtx_lock' [-Wunused-variable]
std::unique_lock<std::mutex> mtx_lock(mtx);
^~~~~~~~
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp: In destructor 'virtual cv::DetectionBasedTracker::SeparateDetectionWork::~SeparateDetectionWork()':
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:254:5: error: 'second_workthread' was not declared in this scope
second_workthread.join();
^~~~~~~~~~~~~~~~~
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp: In member function 'bool cv::DetectionBasedTracker::SeparateDetectionWork::run()':
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:261:27: error: 'mutex' is not a member of 'std'
std::unique_lock<std::mutex> mtx_lock(mtx);
^~~~~
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:261:27: note: 'std::mutex' is defined in header '<mutex>'; did you forget to '#include <mutex>'?
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:261:27: error: 'mutex' is not a member of 'std'
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:261:27: note: 'std::mutex' is defined in header '<mutex>'; did you forget to '#include <mutex>'?
E:\opencv3.4.5\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:261:32: error: template argument 1 is invalid
std::unique_lock<std::mutex> mtx_lock(mtx);
可以看到报错里有很多关于某些头文件的问题,不清楚能否之间像里面说的那样添加头文件之后就可以执行,但在查找问题的时候发现出现这样error: ‘mutex’ in namespace ‘std’ does not name a type
的类似错误可能是mingw
版本选择问题,之前装过了相关的版本,所以便没有在意这种事情,需要选择 -posix
版本的mingw
,而SJLJ
还是 SEH
的选择,似乎是说SJLJ
的兼容性会更好,但是SEH
的速度会更快,所以保险起见选择SJLJ
的版本。
不过如果你是按照开头提到的那个教程一步步来下载各个文件的话就不会踩到我这个坑了。
最后看着它终于冲破了90%的感觉就好像是获得了封号斗罗称号一样,然后install一泻千里的感觉非常爽(bushi
其实总结一下,配置环境的时候需要很注意过程当中的编译信息,然后才能排查问题精确定位,在网上搜的情况太多了,而且出问题的地方很多,不仅需要检索查找的能力,还需要有一些自主排查的能力;
还有就是在过程当中有很多重复操作,总想着有没有可能下一次会有奇迹或者不一样的事情发生,但是电脑是呆子,做一万次都是一样的结果,所以要自己做出调整之后再去尝试。
标签:based,sources,配置,环境,detection,opencv,tracker,objdetect 来源: https://www.cnblogs.com/hhr346/p/16694261.html