招生网站制作,如何撤销网站备案,手机app定制开发,网站建设课题简介文章目录 进入正题之前版本说明Python环境搭建安装aruco算法 C 环境搭建安装 VSopencv验证 Aruco算法#xff0c;opencv4.8.0 进入正题之前
OpenCV是一个优秀的开源视觉处理软件框架#xff0c;也是计算机视觉学习道路上必须掌握的一套工具#xff0c;奈何其版本兼容性上实… 文章目录 进入正题之前版本说明Python环境搭建安装aruco算法 C 环境搭建安装 VSopencv验证 Aruco算法opencv4.8.0 进入正题之前
OpenCV是一个优秀的开源视觉处理软件框架也是计算机视觉学习道路上必须掌握的一套工具奈何其版本兼容性上实在是一言难尽。本文主要就是在说OpenCV搭建开发环境时遇到的各种奇葩问题方便帮助后面的新同学排雷。如果你也刚好遇到类似的问题并且靠着本文的处理方式解决掉你的麻烦不妨搜一搜VX公众号“24K纯学渣”可能会有更多的惊喜噢。本文将持续更新。。。
PS如果本文找不到你遇到的问题可以去官方文档搜传送门https://docs.opencv.org/
版本说明
opencv 3.4.2.17 是最后一版支持免费使用sift等模板匹配算法的版本之后的版本由于版权问题去掉了一些可能会被收费的模块。
aruco算法从4.7.0开始进入到opencv-python主库
Python环境搭建 如果只需要主要模块 pip install opencv-python 如果需要更全的模块 pip install opencv-contrib-python 如果资源较少不需要任何GUI功能 pip install opencv-python-headless 如果资源较少不需要任何GUI功能包含contrib模块 pip install opencv-contrib-python-headless 因此一般来说都会选择安装opencv-contrib-python不要同时安装opencv-python和opencv-contrib-python。 关于安装包的问题解决完以后新版本的安装包在原来的代码上会连续报如下错误对应新版本修改即可。 ———————————————— 版权声明本文为CSDN博主「童鸢」的原创文章遵循CC 4.0 BY-SA版权协议转载请附上原文出处链接及本声明。 原文链接https://blog.csdn.net/weixin_41837701/article/details/129256430 安装
# for Linux-like OS
pip3 install opencv-pythonx.x.x.x# for Windows
pip install opencv-pythonx.x.x.xaruco算法
只安装了opencv-python
import cv2 # opencv-python4.8.1.78img cv2.imread(./in_imgs/4x4_15.png, 0)
cv2.imshow(img, img)ad cv2.aruco.ArucoDetector()
corners, ids, rejected ad.detectMarkers(img)
cv2.waitKey()
cv2.destroyAllWindows()只安装 opencv-contrib-python3.4.2.17环境是CentOS 7.9 server版本
import cv2 # opencv-python3.4.2.17img cv2.imread(./in_imgs/4x4_15.jpg, cv2.IMREAD_COLOR)
img_gray cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# cv2.imshow(img, img) # 由于没有GUI无法调用imshow函数arucoDict cv2.aruco.Dictionary_get(cv2.aruco.DICT_4X4_50)
arucoParams cv2.aruco.DetectorParameters_create()
corners, ids, rejected cv2.aruco.detectMarkers(img_gray, arucoDict, parametersarucoParams)print(corners, ids, rejected)img cv2.aruco.drawDetectedMarkers(img, corners, ids, [0,255,0])
cv2.imwrite(./out_imgs/detected_aruco.jpg, img)
1AttributeError: module ‘cv2.aruco’ has no attribute ‘Dictionary_get’ cv2.aruco.Dictionary_get()函数会加载cv2.aruco.DICT_nXn_250包含250个标记的字典其中每个标记都是n×n位二进制模式。 在最新的版本中这个函数的API改为了 cv2.aruco.getPredefinedDictionary 2AttributeError: module ‘cv2.aruco’ has no attribute ‘DetectorParameters_create’ cv2.aruco.DetectorParameters_create这个函数的作用是使用默认值初始化检测器参数改为了cv2.aruco.DetectorParameters ———————————————— 版权声明本文为CSDN博主「童鸢」的原创文章遵循CC 4.0 BY-SA版权协议转载请附上原文出处链接及本声明。 原文链接https://blog.csdn.net/weixin_41837701/article/details/129256430
3centos7和ubuntu18.04分别解决cv2缺少共享库( libSM.so.6)的解决方法
yum install libSM-1.2.2-2.el7.x86_64 --setoptprotected_multilibfalse
yum install libXrender-0.9.10-1.el7.x86_64 --setoptprotected_multilibfalse
yum install libXext-1.3.3-3.el7.x86_64 --setoptprotected_multilibfalseC 环境搭建
安装 VSopencv
先安装Visual Studio如果已经安装请跳过官网下载opencv-windows.exe执行open-windows.exe记住安装的路径添加opencv的环境变量到Path中C:\your\local\env\path\for \opencv\build\x64\vc16将C:\your\local\env\path\for \opencv\build\x64\vc16\bin下的opencv_videoio_ffmpeg480_64.dll、opencv_world480.dll、opencv_world480d.dll 复制到 C:\Windows\System32\下。新建一个d_opencv_env.props 和 r_opencv_env.props文本文件分别复制下面的内容到对应的属性表文件中。注意路径
属性表(Debug) 注意 C:\your\local\env\path\for 换成你自己的安装路径。
?xml version1.0 encodingutf-8?
Project ToolsVersion4.0 xmlnshttp://schemas.microsoft.com/developer/msbuild/2003ImportGroup LabelPropertySheets /PropertyGroup LabelUserMacros /PropertyGroupIncludePathC:\your\local\env\path\for\opencv\build\include;C:\your\local\env\path\for\opencv\build\include\opencv2;$(IncludePath)/IncludePathLibraryPathC:\your\local\env\path\for\opencv\build\x64\vc16\lib;$(LibraryPath)/LibraryPath/PropertyGroupItemDefinitionGroupLinkAdditionalDependenciesC:\your\local\env\path\for\opencv\build\x64\vc16\lib\opencv_world480d.lib;%(AdditionalDependencies)/AdditionalDependencies/Link/ItemDefinitionGroupItemGroup /
/Project属性表(Release) 注意 C:\your\local\env\path\for 换成你自己的安装路径。
?xml version1.0 encodingutf-8?
Project ToolsVersion4.0 xmlnshttp://schemas.microsoft.com/developer/msbuild/2003ImportGroup LabelPropertySheets /PropertyGroup LabelUserMacros /PropertyGroupIncludePathC:\your\local\env\path\for\opencv\build\include;C:\your\local\env\path\for\opencv\build\include\opencv2;$(IncludePath)/IncludePathLibraryPathC:\your\local\env\path\for\opencv\build\x64\vc16\lib;$(LibraryPath)/LibraryPath/PropertyGroupItemDefinitionGroupLinkAdditionalDependenciesC:\your\local\env\path\for\opencv\build\x64\vc16\lib\opencv_world480.lib;%(AdditionalDependencies)/AdditionalDependencies/Link/ItemDefinitionGroupItemGroup /
/Project验证 Aruco算法opencv4.8.0
#include iostream
#include opencv2/core.hpp
#include opencv2/opencv.hpp
#include opencv2/core/core.hpp
#include opencv2/objdetect/aruco_detector.hppint main(int argc, char const *argv[])
{//std::cout 先生成一个aruco marker std::endl;//std::cout 保存生成的aruco marker std::endl;std::cout 1. 读取aruco marker std::endl;cv::Mat img_color cv::imread(./in_imgs/4x4_15.jpg, cv::IMREAD_COLOR);//cv::Mat img cv::imread(./in_imgs/4x4_15.jpg, cv::IMREAD_COLOR);cv::Mat img;cv::cvtColor(img_color, img, cv::COLOR_BGR2GRAY);//宽度std::cout 宽度 img.cols std::endl;//高度std::cout 高度 img.rows std::endl;//通道数std::cout 通道数 img.channels() std::endl;cv::imshow(aruco_15, img);auto dictionary cv::aruco::getPredefinedDictionary(cv::aruco::DICT_4X4_50);std::vectorstd::vectorcv::Point2fcorners, rejectedImgPoints;std::vectorint ids;auto parameters cv::aruco::DetectorParameters();//cv::aruco::detectMarkers(img, dictionary, corners, ids, parameters, rejectedImgPoints);cv::aruco::ArucoDetector ad cv::aruco::ArucoDetector();ad.detectMarkers(img, corners, ids);cv::aruco::drawDetectedMarkers(img_color, corners, ids, cv::Scalar(0, 255, 0));if (ids.size() 0){std::cout ids[0] std::endl;}cv::imshow(drawed, img_color);cv::waitKey();return 0;
}