(OpenCV4.1) /usr/bin/ld: 找不到 -lopencv_nonfree
(OpenCV4.1) /usr/bin/ld: cannot find -lopencv_nonfree
我在 Raspberry Pi 3B 上按照 https://www.pyimagesearch.com/2018/09/26/install-opencv-4-on-your-raspberry-pi/ 安装了 OpenCV 4.1。
我用这些 CMake 标志编译了 OpenCV:
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_opencv_java=off -D BUILD_opencv_python2=OFF -D BUILD_opencv_python3=OFF -D ENABLE_PRECOMPILED_HEADERS=OFF -D BUILD_JPEG=OFF -D ENABLE_FAST_MATH=ON -D CMAKE_SHARED_LINKER_FLAGS=-latomic -D ENABLE_NEON=ON -D ENABLE_VFPV3=ON -D OPENCV_ENABLE_NONFREE=ON -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules -D WITH_OPENCL=ON -D WITH_PTHREADS_PF=OFF -DEXTRA_C_FLAGS=-mcpu=cortex-a7 -mfpu=neon-vfpv4 -ftree-vectorize -mfloat-abi=hard -D EXTRA_CXX_FLAGS=-mcpu=cortex-a7 -mfpu=neon-vfpv4 -ftree-vectorize -mfloat-abi=hard -D BUILD_EXAMPLES=OFF -D BUILD_PERF_TESTS=OFF ..
当我编译我的项目时出现这个错误:
/usr/bin/ld: impossibile trovare -lopencv_nonfree
collect2: error: ld returned 1 exit status
CMakeFiles/river_flow_velocity_estimation.dir/build.make:271: set di istruzioni per l'obiettivo "river_flow_velocity_estimation" non riuscito
make[2]: *** [river_flow_velocity_estimation] Errore 1
CMakeFiles/Makefile2:67: set di istruzioni per l'obiettivo "CMakeFiles/river_flow_velocity_estimation.dir/all" non riuscito
make[1]: *** [CMakeFiles/river_flow_velocity_estimation.dir/all] Errore 2
Makefile:83: set di istruzioni per l'obiettivo "all" non riuscito
make: *** [all] Errore 2
与此相同的错误 post /usr/bin/ld: cannot find -lopencv_nonfree.
我是初学者,不太清楚问题出在哪里。
我不明白为什么即使我使用标志 OPENCV_ENABLE_NONFREE=ON
我的程序也找不到 opencv_nonfree
模块。
有人知道怎么做吗?
编辑:我的 CMakeLists.txt
cmake_minimum_required(VERSION 3.5.1)
set (CMAKE_BUILD_TYPE Release)
#set (CMAKE_BUILD_TYPE Debug)
SET (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
add_definitions(-std=c++0x)
project(river_flow_velocity_estimation)
set( OpenCV_DIR "/usr/share/OpenCV" )
set(OPENCV_ENABLE_NONFREE "Enable non-free algorithms" ON)
find_package( OpenCV 4.1.0 REQUIRED)
find_package( OpenMP REQUIRED)
include_directories(include ${OpenCV_LIBRARIES} ${OpenCV_INCLUDE_DIRS} } ${catkin_INCLUDE_DIRS})
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS} -mcpu=cortex-a53 -mfloat-abi=hard -funsafe-math-optimizations -mfpu=neon-fp-armv8")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS} -mcpu=cortex-a53 -mfloat-abi=hard -funsafe-math-optimizations -mfpu=neon-fp-armv8")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
file(GLOB SOURCES "src/*.cpp")
add_executable(river_flow_velocity_estimation ${SOURCES})
target_link_libraries(river_flow_velocity_estimation opencv_nonfree ${OpenCV_LIBS} ${catkin_LIBRARIES})
opencv_nonfree
在 openCV 4.1 中不再存在。如果您从 target_link_libraries
中删除 opencv_nonfree
,它应该可以工作。
仅供参考,它们现在直接从 opencv_contrib 集成到 modules/xfeatures2d/
中。有了你的标志 OPENCV_ENABLE_NONFREE=ON
,它们应该可用。
我在 Raspberry Pi 3B 上按照 https://www.pyimagesearch.com/2018/09/26/install-opencv-4-on-your-raspberry-pi/ 安装了 OpenCV 4.1。 我用这些 CMake 标志编译了 OpenCV:
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_opencv_java=off -D BUILD_opencv_python2=OFF -D BUILD_opencv_python3=OFF -D ENABLE_PRECOMPILED_HEADERS=OFF -D BUILD_JPEG=OFF -D ENABLE_FAST_MATH=ON -D CMAKE_SHARED_LINKER_FLAGS=-latomic -D ENABLE_NEON=ON -D ENABLE_VFPV3=ON -D OPENCV_ENABLE_NONFREE=ON -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules -D WITH_OPENCL=ON -D WITH_PTHREADS_PF=OFF -DEXTRA_C_FLAGS=-mcpu=cortex-a7 -mfpu=neon-vfpv4 -ftree-vectorize -mfloat-abi=hard -D EXTRA_CXX_FLAGS=-mcpu=cortex-a7 -mfpu=neon-vfpv4 -ftree-vectorize -mfloat-abi=hard -D BUILD_EXAMPLES=OFF -D BUILD_PERF_TESTS=OFF ..
当我编译我的项目时出现这个错误:
/usr/bin/ld: impossibile trovare -lopencv_nonfree
collect2: error: ld returned 1 exit status
CMakeFiles/river_flow_velocity_estimation.dir/build.make:271: set di istruzioni per l'obiettivo "river_flow_velocity_estimation" non riuscito
make[2]: *** [river_flow_velocity_estimation] Errore 1
CMakeFiles/Makefile2:67: set di istruzioni per l'obiettivo "CMakeFiles/river_flow_velocity_estimation.dir/all" non riuscito
make[1]: *** [CMakeFiles/river_flow_velocity_estimation.dir/all] Errore 2
Makefile:83: set di istruzioni per l'obiettivo "all" non riuscito
make: *** [all] Errore 2
与此相同的错误 post /usr/bin/ld: cannot find -lopencv_nonfree.
我是初学者,不太清楚问题出在哪里。
我不明白为什么即使我使用标志 OPENCV_ENABLE_NONFREE=ON
我的程序也找不到 opencv_nonfree
模块。
有人知道怎么做吗?
编辑:我的 CMakeLists.txt
cmake_minimum_required(VERSION 3.5.1)
set (CMAKE_BUILD_TYPE Release)
#set (CMAKE_BUILD_TYPE Debug)
SET (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
add_definitions(-std=c++0x)
project(river_flow_velocity_estimation)
set( OpenCV_DIR "/usr/share/OpenCV" )
set(OPENCV_ENABLE_NONFREE "Enable non-free algorithms" ON)
find_package( OpenCV 4.1.0 REQUIRED)
find_package( OpenMP REQUIRED)
include_directories(include ${OpenCV_LIBRARIES} ${OpenCV_INCLUDE_DIRS} } ${catkin_INCLUDE_DIRS})
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS} -mcpu=cortex-a53 -mfloat-abi=hard -funsafe-math-optimizations -mfpu=neon-fp-armv8")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS} -mcpu=cortex-a53 -mfloat-abi=hard -funsafe-math-optimizations -mfpu=neon-fp-armv8")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
file(GLOB SOURCES "src/*.cpp")
add_executable(river_flow_velocity_estimation ${SOURCES})
target_link_libraries(river_flow_velocity_estimation opencv_nonfree ${OpenCV_LIBS} ${catkin_LIBRARIES})
opencv_nonfree
在 openCV 4.1 中不再存在。如果您从 target_link_libraries
中删除 opencv_nonfree
,它应该可以工作。
仅供参考,它们现在直接从 opencv_contrib 集成到 modules/xfeatures2d/
中。有了你的标志 OPENCV_ENABLE_NONFREE=ON
,它们应该可用。