在OpenCV-DisplayImage.cpp中编译c++代码时出现问题(使用gcc和CMake)
Trouble with compiling c++ code in OpenCV - DisplayImage.cpp (using gcc and CMake)
我遵循这里给出的代码http://docs.opencv.org/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.html#linux-gcc使用这是使用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可执行文件。有人能帮我吗?提前谢谢。
对于那些面临此问题的人,请尝试添加
#include <opencv2/highgui/highgui_c.h>
到DisplayImage.cpp代码的顶部。然后编译并再次执行。希望它能起作用!我只是试着自己验证了一下。
相关文章:
- C++ 雷神库 - 使用资源加载器类时出现问题(不命名类型)
- 使用mongocxx驱动程序时包含头文件问题
- 编译要在英特尔Hyperscan中使用的.cc文件时出现问题
- 使用FFMPEG将RGB图像序列保存到.mp4时出现问题
- 如何在C++向量中奇数元素前面加上值-1,我在使用insert函数时遇到了问题
- 在c++中使用动态分配的问题
- (ODR 使用问题)在不同文件中priority_queue名称相同的结构
- SFML 纹理使用问题
- 类创建和使用问题
- C++模板使用问题指针
- 枚举使用问题
- 提升单位使用问题 - hash_value,计数乘法
- 指向成员函数声明/使用问题的可变参数模板指针
- HOGDescriptionr的使用问题
- Vec3b 使用问题以及在 Mat 对象中的某个点获取 RGB 值
- std::align的使用问题
- Z3_parse_smtlib_string使用问题
- C++中"this"关键字的使用问题
- 使用C++ - 问题的基本终端输出
- PNG到Opengl的使用问题