我克隆,编译并安装了OpenCV的主分支:
cmake .. -DCMAKE_INSTALL_PREFIX=/some/non-system-path \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_INSTALL_RPATH=/some/non-system-path
make
make install
通常的东西,除了我在用户路径中安装它。为了测试它,我尝试运行以下" hello world"例如:
#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char** argv )
{
if ( argc != 2 )
{
printf("usage: DisplayImage.out <Image_Path>\n");
return -1;
}
Mat image;
image = imread( argv[1], 1 );
if ( !image.data )
{
printf("No image data \n");
return -1;
}
namedWindow("Display Image", WINDOW_AUTOSIZE );
imshow("Display Image", image);
waitKey(0);
return 0;
}
使用以下CMakeLists.txt
:
cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable( DisplayImage main.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )
请注意,这是OpenCV的确切示例。它失败了以下内容:
[ 50%] Building CXX object CMakeFiles/DisplayImage.dir/main.cpp.o
make[2]: *** No rule to make target 'opencv_calib3d-NOTFOUND', needed by 'DisplayImage'. Stop.
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/DisplayImage.dir/all' failed
make[1]: *** [CMakeFiles/DisplayImage.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
查看/some/non-system-path/lib
,libopencv_calib3d.so
指向libopencv_calib3d.so.3.3.1
。
我认为这可能是link_directories
问题,但是,设置它也没有解决问题。至于${OpenCV_LIBS}
我打印了它,我得到了:
message(STATUS "OpenCV_LIBS = ${OpenCV_LIBS}")
-- OpenCV_LIBS = opencv_calib3d;opencv_core;opencv_dnn;opencv_features2d;opencv_flann;opencv_highgui;opencv_imgcodecs;opencv_imgproc;opencv_ml;opencv_objdetect;opencv_photo;opencv_shape;opencv_stitching;opencv_superres;opencv_video;opencv_videoio;opencv_videostab;opencv_viz
有什么想法吗?
答案 0 :(得分:1)