当前位置: 首页 > 工具软件 > VideoCapture > 使用案例 >

undefined reference to `cv::VideoCapture::VideoCapture()‘

孙成益
2023-12-01

ubuntu opencv两个版本都有,2.4.9和3.0

编译报异常:

/lbg/pTrack/dsst/tqone/main/image_acquisition.cpp:36: error: undefined reference to `cv::VideoCapture::VideoCapture()'

/lbg/pTrack/dsst/tqone/main/image_acquisition.cpp:81: error: undefined reference to `cv::VideoCapture::open(int)'

/lbg/pTrack/dsst/tqone/main/image_acquisition.cpp:87: error: undefined reference to `cv::VideoCapture::open(cv::String const&)'
/lbg/pTrack/dsst/tqone/main/image_acquisition.cpp:45: error: undefined reference to `cv::VideoCapture::operator>>(cv::Mat&)'

/lbg/pTrack/dsst/tqone/main/image_acquisition.cpp:61: error: undefined reference to `cv::VideoCapture::isOpened() const'

/lbg/pTrack/dsst/tqone/main/image_acquisition.cpp:67: error: undefined reference to `cv::VideoCapture::set(int, double)'
 

原因:添加了opencv的头文件,没有加库路径,

解决方式, 加上opencv的库就ok了:

/usr/local/lib/libopencv_shape.so \

/usr/local/lib/libopencv_videoio.so \

/usr/local/lib/libopencv_core.so.3.0 \

最简单的写法:


cmake_minimum_required(VERSION 3.5)
project( OpenCamera )
find_package( OpenCV REQUIRED )
add_executable( OpenCamera OpenCamera.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )

这种写法也可以:

project(imageprocess)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)


add_executable(${PROJECT_NAME} test.cpp)
target_link_libraries(${PROJECT_NAME} -I/usr/include/opencv /usr/lib/x86_64-linux-gnu/libopencv_calib3d.so -lopencv_calib3d /usr/lib/x86_64-linux-gnu/libopencv_contrib.so -lopencv_contrib /usr/lib/x86_64-linux-gnu/libopencv_core.so -lopencv_core /usr/lib/x86_64-linux-gnu/libopencv_features2d.so -lopencv_features2d /usr/lib/x86_64-linux-gnu/libopencv_flann.so -lopencv_flann /usr/lib/x86_64-linux-gnu/libopencv_gpu.so -lopencv_gpu /usr/lib/x86_64-linux-gnu/libopencv_highgui.so -lopencv_highgui /usr/lib/x86_64-linux-gnu/libopencv_imgproc.so -lopencv_imgproc /usr/lib/x86_64-linux-gnu/libopencv_legacy.so -lopencv_legacy /usr/lib/x86_64-linux-gnu/libopencv_ml.so -lopencv_ml /usr/lib/x86_64-linux-gnu/libopencv_objdetect.so -lopencv_objdetect /usr/lib/x86_64-linux-gnu/libopencv_ocl.so -lopencv_ocl /usr/lib/x86_64-linux-gnu/libopencv_photo.so -lopencv_photo /usr/lib/x86_64-linux-gnu/libopencv_stitching.so -lopencv_stitching /usr/lib/x86_64-linux-gnu/libopencv_superres.so -lopencv_superres /usr/lib/x86_64-linux-gnu/libopencv_ts.so -lopencv_ts /usr/lib/x86_64-linux-gnu/libopencv_video.so -lopencv_video /usr/lib/x86_64-linux-gnu/libopencv_videostab.so -lopencv_videostab)

android ndk添加方式:

CMakeLists.txt中:

if(BUILD_ANDROID)
  include_directories(${android_opencv}/sdk/native/jni/include)
  include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../rknn_api/include)
  link_directories(${android_opencv}/sdk/native/libs/${ANDROID_ABI})

endif()


add_executable(demo_exe ${SRC_CODES})

target_link_libraries(demo_exe 
                      ${android_opencv}/sdk/native/libs/${ANDROID_ABI}/libopencv_java3.so
                      -llog
					  -lz
                      -ljnigraphics
					  )

 类似资料: