启动网站建设的请示,企业备案网站名称要求,产品设计公司招聘,网站定位策划1 编译 opencv的编译总体来说比较简单#xff0c;但必须记住一点#xff1a;opencv的版本必须和opencv_contrib的版本保持一致。例如opencv使用4.8.0#xff0c;opencv_contrib也必须使用4.8.0。 进入opencv和opencv_contrib的github页面后#xff0c;默认看到的是git分支但必须记住一点opencv的版本必须和opencv_contrib的版本保持一致。例如opencv使用4.8.0opencv_contrib也必须使用4.8.0。 进入opencv和opencv_contrib的github页面后默认看到的是git分支如4.x。 如果想要下载具体的版本需要通过tag进行查找。 注意一定要下载具体的tag进行编译不要选择branch否则编译会报错。如opencv选择4.8.0opencv_contrib选择4.x编译会报下面的错误
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1437:1: note: candidate function template not viable: requires single argument a, but 2 arguments were provided
OPENCV_HAL_IMPL_SSE_SHIFT_OP(v_uint16x8, v_int16x8, epi16, _mm_srai_epi16)
^
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1427:16: note: expanded from macro OPENCV_HAL_IMPL_SSE_SHIFT_OP
inline _Tpuvec v_shr(const _Tpuvec a) \^
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1437:1: note: candidate function template not viable: requires single argument a, but 2 arguments were provided
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1432:16: note: expanded from macro OPENCV_HAL_IMPL_SSE_SHIFT_OP
inline _Tpsvec v_shr(const _Tpsvec a) \^
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1438:1: note: candidate function template not viable: requires single argument a, but 2 arguments were provided
OPENCV_HAL_IMPL_SSE_SHIFT_OP(v_uint32x4, v_int32x4, epi32, _mm_srai_epi32)
^
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1427:16: note: expanded from macro OPENCV_HAL_IMPL_SSE_SHIFT_OP
inline _Tpuvec v_shr(const _Tpuvec a) \^
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1438:1: note: candidate function template not viable: requires single argument a, but 2 arguments were provided
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1432:16: note: expanded from macro OPENCV_HAL_IMPL_SSE_SHIFT_OP
inline _Tpsvec v_shr(const _Tpsvec a) \^
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1439:1: note: candidate function template not viable: requires single argument a, but 2 arguments were provided
OPENCV_HAL_IMPL_SSE_SHIFT_OP(v_uint64x2, v_int64x2, epi64, v_srai_epi64)
^
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1427:16: note: expanded from macro OPENCV_HAL_IMPL_SSE_SHIFT_OP
inline _Tpuvec v_shr(const _Tpuvec a) \^
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1439:1: note: candidate function template not viable: requires single argument a, but 2 arguments were provided
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1432:16: note: expanded from macro OPENCV_HAL_IMPL_SSE_SHIFT_OP
inline _Tpsvec v_shr(const _Tpsvec a) \^
/Users/Github/opencv_contrib-4.x/modules/xphoto/src/grayworld_white_balance.cpp:290:21: error: no matching function for call to v_shrv_sR2 v_shr(v_mul_wrap(v_sR2, v_gainR), 8);^~~~~
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1437:1: note: candidate function template not viable: requires single argument a, but 2 arguments were provided
OPENCV_HAL_IMPL_SSE_SHIFT_OP(v_uint16x8, v_int16x8, epi16, _mm_srai_epi16)
^
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1427:16: note: expanded from macro OPENCV_HAL_IMPL_SSE_SHIFT_OP
inline _Tpuvec v_shr(const _Tpuvec a) \^
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1437:1: note: candidate function template not viable: requires single argument a, but 2 arguments were provided
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1432:16: note: expanded from macro OPENCV_HAL_IMPL_SSE_SHIFT_OP
inline _Tpsvec v_shr(const _Tpsvec a) \^
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1438:1: note: candidate function template not viable: requires single argument a, but 2 arguments were provided
OPENCV_HAL_IMPL_SSE_SHIFT_OP(v_uint32x4, v_int32x4, epi32, _mm_srai_epi32)
^
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1427:16: note: expanded from macro OPENCV_HAL_IMPL_SSE_SHIFT_OP
inline _Tpuvec v_shr(const _Tpuvec a) \^
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1438:1: note: candidate function template not viable: requires single argument a, but 2 arguments were provided
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1432:16: note: expanded from macro OPENCV_HAL_IMPL_SSE_SHIFT_OP
inline _Tpsvec v_shr(const _Tpsvec a) \^
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1439:1: note: candidate function template not viable: requires single argument a, but 2 arguments were provided
OPENCV_HAL_IMPL_SSE_SHIFT_OP(v_uint64x2, v_int64x2, epi64, v_srai_epi64)
^
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1427:16: note: expanded from macro OPENCV_HAL_IMPL_SSE_SHIFT_OP
inline _Tpuvec v_shr(const _Tpuvec a) \^
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1439:1: note: candidate function template not viable: requires single argument a, but 2 arguments were provided
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1432:16: note: expanded from macro OPENCV_HAL_IMPL_SSE_SHIFT_OP
inline _Tpsvec v_shr(const _Tpsvec a) \^
/Users/Github/opencv_contrib-4.x/modules/xphoto/src/grayworld_white_balance.cpp:328:21: error: no matching function for call to v_shrv_sB1 v_shr(v_mul(v_sB1, v_gainB), 16); 编译脚本如下make -j8使用并发编译编译速度会快些
make build
cd build
cmake ../ -DCMAKE_INSTALL_PREFIX/Users/opencv-4.8.0 -DBUILD_SHARED_LIBSOFF -DOPENCV_EXTRA_MODULES_PATH/Users/Github/opencv_contrib-4.8.0/modules
make -j8
make install
2 使用 编写cmake时强烈建议使用find_package引用头文件和lib库尤其是lib库千万不要手动逐个引入lib库。opencv的lib库引用关系表复杂手动引用会出现各种符号未定义。大量的符号未定义会让人忙到怀疑人生。 完整的cmake如下所示
#
#cmake for first_opencv
#
cmake_minimum_required(VERSION 3.28)
set(target first_opencv)
project(${target})
set(CMAKE_CXX_STANDARD 17)
set(project_path ${CMAKE_CURRENT_SOURCE_DIR})
file(GLOB srcs ${project_path}/src/*.cpp ${project_path}/src/*.c)
file(GLOB incs ${project_path}/src/*.hpp ${project_path}/src/*.h)
source_group(source ${srcs})
source_group(include ${incs})find_package(Iconv)
set(OpenCV_DIR /Users/libs/opencv-4.8.0/lib/cmake/opencv4)
find_package(OpenCV REQUIRED)
include_directories(${incs} ${OpenCV_INCLUDE_DIRS})add_executable(${target} ${srcs} ${incs})target_link_libraries(${target} ${OpenCV_LIBS}) 注意
set(OpenCV_DIR /Users/libs/opencv-4.8.0/lib/cmake/opencv4)中/Users/libs/opencv-4.8.0/lib/cmake/opencv4为OpenCVConfig.cmake所在的目录如果不设置OpenCV_DIR会报下面错误
CMake Error at CMakeLists.txt:16 (find_package):By not providing FindOpenCV.cmake in CMAKE_MODULE_PATH this project hasasked CMake to find a package configuration file provided by OpenCV, butCMake did not find one.Could not find a package configuration file provided by OpenCV with anyof the following names:OpenCVConfig.cmakeopencv-config.cmakeAdd the installation prefix of OpenCV to CMAKE_PREFIX_PATH or setOpenCV_DIR to a directory containing one of the above files. If OpenCVprovides a separate development package or SDK, be sure it has beeninstalled.
find_package(Iconv)必须添加否则会报下面的错误
CMake Error at /Users/libs/opencv-4.8.0/lib/cmake/opencv4/OpenCVModules.cmake:371 (set_target_properties):The link interface of target opencv_wechat_qrcode contains:Iconv::Iconvbut the target was not found. Possible reasons include:* There is a typo in the target name.* A find_package call is missing for an IMPORTED target.* An ALIAS target is missing.Call Stack (most recent call first):/Users/libs/opencv-4.8.0/lib/cmake/opencv4/OpenCVConfig.cmake:133 (include)CMakeLists.txt:16 (find_package)