我正在按照此处提供的代码http://docs.opencv.org/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.html#linux-gcc-usage 这是使用GCC和CMAKE编译的。
我保存了一个带有代码的DisplayImage.cpp文件和一个带有相应代码的CMakeLists.txt文件。 lena.jpeg也保存在同一目录中。
DisplayImage.cpp的代码
#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", CV_WINDOW_AUTOSIZE );
imshow("Display Image", image);
waitKey(0);
return 0;
}
CmakeLists.txt的代码
cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
find_package( OpenCV REQUIRED )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )
然后我尝试使用生成可执行文件 cmake。 使
但我收到以下错误......
clive@clive-Aspire-4755:~/Visual_Odometry/cpp/DisplayImage$ cmake .
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/clive/Visual_Odometry/cpp/DisplayImage
clive@clive-Aspire-4755:~/Visual_Odometry/cpp/DisplayImage$ make
Scanning dependencies of target DisplayImage
[100%] Building CXX object CMakeFiles/DisplayImage.dir/DisplayImage.cpp.o
/home/clive/Visual_Odometry/cpp/DisplayImage/DisplayImage.cpp: In function ‘int main(int, char**)’:
/home/clive/Visual_Odometry/cpp/DisplayImage/DisplayImage.cpp:8:5: error: ‘arg’ was not declared in this scope
/home/clive/Visual_Odometry/cpp/DisplayImage/DisplayImage.cpp:8:5: note: suggested alternative:
/usr/include/c++/4.6/complex:619:5: note: ‘std::arg’
/home/clive/Visual_Odometry/cpp/DisplayImage/DisplayImage.cpp:25:11: error: ‘waitkey’ was not declared in this scope
make[2]: *** [CMakeFiles/DisplayImage.dir/DisplayImage.cpp.o] Error 1
make[1]: *** [CMakeFiles/DisplayImage.dir/all] Error 2
make: *** [all] Error 2
由于某些错误,无法创建DisplayImage可执行文件。有人可以帮帮我吗?提前谢谢。
答案 0 :(得分:0)
对于遇到此问题的人,请尝试添加
#include <opencv2/highgui/highgui_c.h>
到DisplayImage.cpp代码的顶部。然后再次编译并执行。 希望它有效!我现在只是自己尝试并验证了它。