Issue
I installed OpenCV 4.1 following this https://www.pyimagesearch.com/2018/09/26/install-opencv-4-on-your-raspberry-pi/ on my Raspberry Pi 3B. I compiled OpenCV with these CMake flags:
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 ..
When I compile my project I get this error:
/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
the same error as this post /usr/bin/ld: cannot find -lopencv_nonfree.
I'm a beginner and don't know well what could be the problem.
I don't understand why even though I used the flag OPENCV_ENABLE_NONFREE=ON
my program can't find the opencv_nonfree
module.
Does anyone know how to do?
Edit: My 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})
Solution
opencv_nonfree
no longer exist in openCV 4.1. If you remove opencv_nonfree
from target_link_libraries
it should work.
FYI, they are now directly integrated into modules/xfeatures2d/
from opencv_contrib. With your flag OPENCV_ENABLE_NONFREE=ON
they should be available.
Answered By - xiawi Answer Checked By - Willingham (WPSolving Volunteer)