OpenCV编程->can not open opencv/cv.h

出现错误:

1>d:\用户目录\documents\visual studio 2012\projects\test1\test1\test1.cpp(7): fatal error C1083: 无法打开包括文件:“opencv/cv.h”: No such file or directory

========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========

解决方案:

 OpenCV编程->can not open opencv/cv.h_第1张图片


OpenCV编程->can not open opencv/cv.h_第2张图片

修改如下:


编译运行后:

OpenCV编程->can not open opencv/cv.h_第3张图片

运行源码:

#include<iostream>  
#include <opencv/cv.h>    
#include <opencv2/opencv.hpp>
/*
#include <opencv2/core/core.hpp>  
#include <opencv2/highgui/highgui.hpp>  
*/
#pragma comment(lib,"opencv_core248d.lib")
#pragma comment(lib,"opencv_highgui248d.lib")
using namespace cv;  

int main()  
{  
	// 读入一张图片(游戏原画)  
	Mat img=imread("fruits.jpg");  
	// 创建一个名为 "游戏原画"窗口  
	cvNamedWindow("游戏原画");  
	// 在窗口中显示游戏原画  
	imshow("游戏原画",img);  
	// 等待6000 ms后窗口自动关闭  
	system("pause");
	waitKey(6000);  
}  
在此有两个注意的小点:

1.在链接库里添加lib有些麻烦,也可以在源码里写:

#pragma comment(lib,"opencv_core248d.lib")
#pragma comment(lib,"opencv_highgui248d.lib")
2.分析cv.h 文件

#include "opencv2/core/core_c.h"
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/video/tracking.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/flann/flann.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/legacy/compat.hpp"
在此我们可以得出,包含目录应该在opencv2目录的文件夹上一级,也就是include文件夹。






你可能感兴趣的:(OpenCV编程->can not open opencv/cv.h)