我刚刚开始使用OpenCV,我有以下示例.cpp文件(来自opencv.org):
#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
int main( int argc, char** argv )
{
Mat image;
image = imread( argv[1], 1 );
if( argc != 2 || !image.data )
{
printf( "No image data \n" );
return -1;
}
namedWindow( "Display Image", CV_WINDOW_AUTOSIZE );
imshow( "Display Image", image );
waitKey(0);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我有以下CMakeList.cmake文件:
project(opencvTEST)
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
find_package(OpenCV REQUIRED)
# Project Executable
add_executable (test test.cpp)
target_link_libraries(test ${OpenCV_LIBS})
Run Code Online (Sandbox Code Playgroud)
我有一台Mac(OS 10.6.8),我已经用CMake安装了OpenCV 2.4.3,我搜索了高低,并尝试了很多不同的东西来让这个测试程序编译(我正在使用命令line - 没有IDE),但是我得到以下编译错误(显然,由于include语句不能正常工作):
test.cpp:3:30: error: opencv2/opencv.hpp: No such file or directory
test.cpp:5: error: ‘cv’ is not a namespace-name
test.cpp:5: error: expected namespace-name before ‘;’ token
test.cpp: In function ‘int main(int, char**)’:
test.cpp:9: error: ‘Mat’ was not declared in this scope
test.cpp:9: error: expected `;' before ‘image’
test.cpp:10: error: ‘image’ was not declared in this scope
test.cpp:10: error: ‘imread’ was not declared in this scope
test.cpp:18: error: ‘CV_WINDOW_AUTOSIZE’ was not declared in this scope
test.cpp:18: error: ‘namedWindow’ was not declared in this scope
test.cpp:19: error: ‘imshow’ was not declared in this scope
test.cpp:21: error: ‘waitKey’ was not declared in this scope
Run Code Online (Sandbox Code Playgroud)
我有一个文件夹opencv2,在同一目录中test.cpp,并且opencv.hpp在opencv2,所以我不明白为什么它没有找到它.有任何想法吗?
另外,一般来说,OpenCV希望您将源(.cpp等)文件放在哪里?
我有完全相同的问题.我从opencv教程运行相同的例子并得到了同样的错误
error: ‘CV_WINDOW_AUTOSIZE’ was not declared in this scope
Run Code Online (Sandbox Code Playgroud)
我通过添加标题解决了这个问题:
#include <opencv/highgui.h>
Run Code Online (Sandbox Code Playgroud)
您忘记添加 CMakeLists.txt
include_directories(${OpenCV_INCLUDE_DIRS})
Run Code Online (Sandbox Code Playgroud)
find_package 之后(需要 OpenCV)
| 归档时间: |
|
| 查看次数: |
5886 次 |
| 最近记录: |