目标:学习《OpenCV3和Qt5 计算机视觉应用开发》,记录总结学习过程。
第一章 OpenCV和Qt简介
开发环境
系统版本:Ubuntu 16.04.7 LTSQt版本:Qt 5.9.5OpenCV版本:opencv-3.3.0虚拟机版本:VMware® Workstation 16 Pro(16.2.2 build-19200509)学习总结
1,安装Linux开发环境
终端运行:sudo apt-get install build-essential libgl1-mesa-dev提示:E:无法定位软件包 libg11-mesa-dev解决方法:分开安装软件包sudo apt-get install build-essential
sudo apt-get install libgl1-mesa-dev
2,安装Open CV
CMake 3.1.1:https://cmake.org/download/CMake GUI:https://cmake.org/files/v3.1/Open CV 3.3.0:https://opencv.org/releases/CMake编译OpenCV库文件,提示错误:IPPICV: Download: ippicv_2017u2_lnx_intel64_20170418.tgz解决方法:1,更改下载地址(实测依然报错)
1,找到/opencv-3.3.0/3rdparty/ippicv/ippicv.cmake
将"https://raw.githubusercontent.com/opencv/opencv_3rdparty/${IPPICV_COMMIT}/ippicv/"
改为"https://ghproxy.com/https://raw.githubusercontent.com/opencv/opencv_3rdparty/.../ippicv/"
2,重新编译
2,离线下载(实测有效)1,根据提示,下载目标版本
目标文件路径:https://github.com/opencv/opencv_3rdparty/tree/ippicv/master_20170418/ippicv
将文件下载到本地文件夹,我的文件路径:/home/bob/work/res/DownLoader/
注意:根据错误提示,下载对应版本文件,
2,修改opencv的cmake文件
找到/opencv-3.3.0/3rdparty/ippicv/ippicv.cmake,
将"https://raw.githubusercontent.com/opencv/opencv_3rdparty/${IPPICV_COMMIT}/ippicv/"
改为"file:///home/bob/work/res/DownLoader/";
3,重新编译;
注意事项ippicv.cmake文件中包含ippicv_2017u2_lnx_intel64_20170418.tgz文件的MD5校验值,如果校验值不一致,仍会报错。function(download_ippicv root_var)
set(${root_var} "" PARENT_SCOPE)
# Commit SHA in the opencv_3rdparty repo
set(IPPICV_COMMIT "a62e20676a60ee0ad6581e217fe7e4bada3b95db")
# Define actual ICV versions
if(APPLE)
set(OPENCV_ICV_PLATFORM "macosx")
set(OPENCV_ICV_PACKAGE_SUBDIR "ippicv_mac")
if(X86_64)
set(OPENCV_ICV_NAME "ippicv_2017u2_mac_intel64_20170418.tgz")
set(OPENCV_ICV_HASH "0c25953c99dbb499ff502485a9356d8d")
else()
set(OPENCV_ICV_NAME "ippicv_2017u2_mac_ia32_20170418.tgz")
set(OPENCV_ICV_HASH "5f225948f3f64067c681293c098d50d8")
endif()
elseif((UNIX AND NOT ANDROID) OR (UNIX AND ANDROID_ABI MATCHES "x86"))
set(OPENCV_ICV_PLATFORM "linux")
set(OPENCV_ICV_PACKAGE_SUBDIR "ippicv_lnx")
if(X86_64)
set(OPENCV_ICV_NAME "ippicv_2017u2_lnx_intel64_20170418.tgz") #对于X86_64系统,文件名
set(OPENCV_ICV_HASH "87cbdeb627415d8e4bc811156289fa3a") #对于X86_64系统,文件MD5校验值
else()
set(OPENCV_ICV_NAME "ippicv_2017u2_lnx_ia32_20170418.tgz")
set(OPENCV_ICV_HASH "f2cece00d802d4dea86df52ed095257e")
endif()
elseif(WIN32 AND NOT ARM)
set(OPENCV_ICV_PLATFORM "windows")
set(OPENCV_ICV_PACKAGE_SUBDIR "ippicv_win")
if(X86_64)
set(OPENCV_ICV_NAME "ippicv_2017u2_win_intel64_20170418.zip")
set(OPENCV_ICV_HASH "75060a0c662c0800f48995b7e9b085f6")
else()
set(OPENCV_ICV_NAME "ippicv_2017u2_win_ia32_20170418.zip")
set(OPENCV_ICV_HASH "60fcf3ccd9a2ebc9e432ffb5cb91638b")
endif()
else()
return()
endif()
set(THE_ROOT "${OpenCV_BINARY_DIR}/3rdparty/ippicv")
ocv_download(FILENAME ${OPENCV_ICV_NAME}
HASH ${OPENCV_ICV_HASH}
URL
"${OPENCV_IPPICV_URL}"
"$ENV{OPENCV_IPPICV_URL}"
"file:///home/bob/work/res/DownLoader/" #修改后的下载地址
DESTINATION_DIR "${THE_ROOT}"
ID IPPICV
STATUS res
UNPACK RELATIVE_URL)
if(res)
set(${root_var} "${THE_ROOT}/${OPENCV_ICV_PACKAGE_SUBDIR}" PARENT_SCOPE)
endif()
endfunction()
3,测试OpenCV安装
按照书中例程,提示错误:Error while building/deploying project opencv18:10:55: 为项目opencv执行步骤 ...
18:10:55: 配置没有改变, 跳过 qmake 步骤。
18:10:55: 正在启动 "/usr/bin/make"
g++ -Wl,-O1 -Wl,-rpath,/opt/fsl-imx-fb/Qt5.9.5/5.9.5/gcc_64/lib -o opencv main.o qrc_res.o -L/opt/fsl-imx-fb/Qt5.9.5/5.9.5/gcc_64/lib -lQt5Core -lpthread
main.o:在函数‘cvflann::anyimpl::big_any_policy<cv::String>::move(void* const*, void**)’中:
main.cpp:(.text._ZN7cvflann7anyimpl14big_any_policyIN2cv6StringEE4moveEPKPvPS5_[_ZN7cvflann7anyimpl14big_any_policyIN2cv6StringEE4moveEPKPvPS5_]+0x10):对‘cv::String::deallocate()’未定义的引用
main.cpp:(.text._ZN7cvflann7anyimpl14big_any_policyIN2cv6StringEE4moveEPKPvPS5_[_ZN7cvflann7anyimpl14big_any_policyIN2cv6StringEE4moveEPKPvPS5_]+0x24):对‘cv::String::deallocate()’未定义的引用
main.o:在函数‘cvflann::anyimpl::big_any_policy<cv::String>::static_delete(void**)’中:
main.cpp:(.text._ZN7cvflann7anyimpl14big_any_policyIN2cv6StringEE13static_deleteEPPv[_ZN7cvflann7anyimpl14big_any_policyIN2cv6StringEE13static_deleteEPPv]+0x15):对‘cv::String::deallocate()’未定义的引用
main.o:在函数‘cv::String::String(char const*)’中:
main.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x30):对‘cv::String::allocate(unsigned long)’未定义的引用
Makefile:243: recipe for target 'opencv' failed
main.o:在函数‘cv::Mat::~Mat()’中:
main.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x15):对‘cv::Mat::deallocate()’未定义的引用
main.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x71):对‘cv::fastFree(void*)’未定义的引用
main.o:在函数‘main’中:
main.cpp:(.text.startup+0x243):对‘cv::imread(cv::String const&, int)’未定义的引用
main.cpp:(.text.startup+0x250):对‘cv::String::deallocate()’未定义的引用
main.cpp:(.text.startup+0x287):对‘cv::imshow(cv::String const&, cv::_InputArray const&)’未定义的引用
main.cpp:(.text.startup+0x28f):对‘cv::String::deallocate()’未定义的引用
main.cpp:(.text.startup+0x2d9):对‘cv::String::deallocate()’未定义的引用
main.cpp:(.text.startup+0x301):对‘cv::String::deallocate()’未定义的引用
collect2: error: ld returned 1 exit status
make: *** [opencv] Error 1
18:10:55: 进程"/usr/bin/make"退出,退出代码 2 。
Error while building/deploying project opencv (kit: Desktop Qt 5.9.5 GCC 64bit)
When executing step "Make"
18:10:55: Elapsed time: 00:00.
需要在.pro文件中加上如下代码CONFIG += link_pkgconfig
PKGCONFIG += opencv
可用工程https://download.csdn.net/download/VistaTech/88947454
注意将图片的文件路径改为自己图片的路径
Mat image = imread("/home/bob/work/Qt/QtCvTest/00-opencv/test.jpg");
附件列表
标签:Qt5,OPENCV,笔记,OpenCV3,set,opencv,ippicv,main,ICV From: https://www.cnblogs.com/pudding-plus/p/18138951