OpenCV 3.2.0 cannnot access to SURF/SIFT in xfeatures2d
I am using Qt creator in Ubuntu 16.04 to build a non-Qt project. I need to use SIFT to detect features. I know that SIFT and SURF are in OpenCV_contrib so I add the extra module when using CMake-gui to configure OpenCV.
Then I can find libopencv_xfeatures2d.so/.so.3.2/.so.3.2.0 and also libopencv_features2d.so/.so.3.2/.so.3.2.0 in /usr/local/lib When I am using the code from OpenCV official website: test code to test SIFT, I still get the error
/home/ronjane92/Documents/Qt/OpenCV/build/lib/libslam_essentials.so:-1: error: undefined reference to `cv::xfeatures2d::SIFT::create(int, int, double, double, double)'
:-1: error: collect2: error: ld returned 1 exit status
My CMakeLists.txt has the following things:
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(opencv_test)
include( CheckCXXCompilerFlag )
SET(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
FIND_PACKAGE( PCL 1.7 REQUIRED COMPONENTS common io visualization)
ADD_DEFINITIONS( ${PCL_DEFINITIONS} )
INCLUDE_DIRECTORIES( ${PCL_INCLUDE_DIRS} )
LINK_DIRECTORIES( ${PCL_LIBRARY_DIRS} )
ADD_SUBDIRECTORY(lib)
INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/lib )
LINK_DIRECTORIES( ${PROJECT_BINARY_DIR}/lib )
FIND_PACKAGE( OpenCV 3.1.0 REQUIRED )
INCLUDE_DIRECTORIES( ${OpenCV_INCLUDE_DIRS} )
ADD_EXECUTABLE(${PROJECT_NAME} "main.cpp")
TARGET_LINK_LIBRARIES(opencv_test ${OpenCV_LIBRARIES}
${PCL_LIBRARIES}
realsense
slam_essentials
)
The results from Cmake-gui are
Detected version of GNU GCC: 54 (504)
FP16: Feature disabled
Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found suitable version "1.2.8", minimum required is "1.2.3")
Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.8")
Found OpenEXR: /usr/lib/x86_64-linux-gnu/libIlmImf.so
Checking for module 'gstreamer-base-1.0'
No package 'gstreamer-base-1.0' found
Checking for module 'gstreamer-video-1.0'
No package 'gstreamer-video-1.0' found
Checking for module 'gstreamer-app-1.0'
No package 'gstreamer-app-1.0' found
Checking for module 'gstreamer-riff-1.0'
No package 'gstreamer-riff-1.0' found
Checking for module 'gstreamer-pbutils-1.0'
No package 'gstreamer-pbutils-1.0' found
Checking for module 'gstreamer-base-0.10'
No package 'gstreamer-base-0.10' found
Checking for module 'gstreamer-video-0.10'
No package 'gstreamer-video-0.10' found
Checking for module 'gstreamer-app-0.10'
No package 'gstreamer-app-0.10' found
Checking for module 'gstreamer-riff-0.10'
No package 'gstreamer-riff-0.10' found
Checking for module 'gstreamer-pbutils-0.10'
No package 'gstreamer-pbutils-0.10' found
Looking for linux/videodev.h
Looking for linux/videodev.h - not found
Looking for linux/videodev2.h
Looking for linux/videodev2.h - found
Looking for sys/videoio.h
Looking for sys/videoio.h - not found
WARNING, PrimeSensor Module binaries directory (set by OPENNI_PRIME_SENSOR_MODULE_BIN_DIR variable) is not found or does not have PrimeSensor Module binaries.
Checking for module 'libavresample'
No package 'libavresample' found
Checking for module 'libgphoto2'
No package 'libgphoto2' found
Found TBB: /usr/lib/x86_64-linux-gnu/libtbb.so
found IPP (ICV version): 9.0.1 [9.0.1]
at: /home/ronjane92/Programs/opencv/opencv-3.2.0-build/3rdparty/ippicv/ippicv_lnx
Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off
Could NOT find Atlas (missing: Atlas_CLAPACK_INCLUDE_DIR)
Could NOT find JNI (missing: JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH)
Could NOT find Matlab (missing: MATLAB_MEX_SCRIPT MATLAB_INCLUDE_DIRS MATLAB_ROOT_DIR MATLAB_LIBRARIES MATLAB_LIBRARY_DIRS MATLAB_MEXEXT MATLAB_ARCH MATLAB_BIN)
The imported target "vtkRenderingPythonTkWidgets" references the file
"/usr/lib/x86_64-linux-gnu/libvtkRenderingPythonTkWidgets.so"
but this file does not exist. Possible reasons include:
* The file was deleted, renamed, or moved to ...
well, your cmake output clearly shows, that the opencv_xfeatures2d module was build (but again, please check !)
problem now seems to be, why the cmake file to build your program does not pick it up, right ?
btw: "I am using Qt creator in Ubuntu 16.04 to build a non-Qt project." -- totally irrelevant, and more an obstacle. keep it plain and simple.
Thanks for your reply.
Can the libopencv_xfeatures2d.so file in /usr/local/lib be an evidence that the opencv_xfeatures2d module was already built? If yes, then I can say it was already built. I do not know what is another way to prove that it was built.
Yes, I think the problem is why my CMake cannot detect the libs.
"Can the libopencv_xfeatures2d.so file in /usr/local/lib be an evidence that the opencv_xfeatures2d module was already built" -- yes. (well, unless you have to fear confusion with a previously build opencv version)
again, i'd say, something in the cmake file to build your program is wrong.
Can I just delete all the OpenCV-related lib files in /usr/local/lib and rebuild the whole OpenCV packages again? I am just worried that if I could delete them thoroughly? Actually, I just rebuild them all a few hours ago but I did not do the deletion step.
imho, you need not fear, the current version should just overwrite the previous.
(and i may be wrong, but i think, you're working on the wrong problem. if it was build originally, it's ok.)
can you ditch cmake for your own project ( yea, it looks complicated, pcl and all), and try to write a simple (hahaha) makefile on your own ?
Thanks for the advice. Let me simplify it.
Thanks guy! Acutally, I met this problem a year ago but then I had to do something else. I almost forgot this problem until last night when I started to do the same thing as the last year. Fortunately, you helped me out. New user can only answer 2 days later... I'll do that afterwards.