ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

配置opencv环境踩过的坑

2022-09-14 19:31:59  阅读:202  来源: 互联网

标签:based sources 配置 环境 detection opencv tracker objdetect


众所周知,配环境是一个玄学问题,有问题的时候到处都是问题,在配置opencv 的时候再次感受到这感受,记录一下自己踩的坑,让大家少走些弯路(

首先给大家推荐一个教程,写得还是很清楚的,这个是网址,不过他也有一些需要注意的地方没有提到,所以这里把步骤简单列举,然后再把需要注意的地方提出来供大家参考。

不清楚版本号的具体影响,就尝试了3.9和3.12的cmake以及opencv的诸多版本,进行排列组合尝试,而且这个编译一次就要可能花费一个小时左右,并且还好多次给我卡在90%左右,弹出让人心肺骤停的进度条和报错信息···

步骤简介:

  1. 下载并安装MinGW_posix版本;
  2. 下载并安装cmake,注意要安装至C盘;
  3. 下载并安装opencv,注意不要安装至C盘;
  4. 添加上述三个文件对应的环境变量;
  5. cmake-gui程序中,配置路径并进行Configuration,然后进行Generate;
  6. 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的路径,具体操作如下:

  1. 官方网址下载2.7版本的python;
  2. 打开设置的“系统”到“系统信息”到“高级系统设置”,选择“环境变量”,在系统变量里新建一个变量名为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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有