1、opencv环境结构
推荐连结 http://www.cnblogs.com/Anykong/archive/2011/04/06/Anykong_OpenCV1.html
2、以下是基本測试,和打开摄像头程序:
我的測试是在win8 系统上。
#include <cv.h>
#include <highgui.h>
#if 0
//測试opencv环境数据
int main()
{
const char* filename = "g:\\test.jpg" ;//换成你自己的文件路径名!!请注意,双斜杠!!
const char* wndname = "http://blog.csdn.net/moc062066" ;
IplImage* pImage = cvLoadImage(filename,CV_LOAD_IMAGE_COLOR) ;
cvNamedWindow(wndname,CV_WINDOW_AUTOSIZE);
cvShowImage(wndname,pImage);
cvWaitKey(0);
cvReleaseImage(&pImage);
cvDestroyWindow(wndname);
return 0;
}
#else
//採集摄像头数据
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
int main( int argc, char** argv )
{
//声明IplImage指针
IplImage* pFrame = NULL;
//获取摄像头
CvCapture* pCapture = cvCreateCameraCapture(-1);
//创建窗体
cvNamedWindow("video", 1);
cvResizeWindow("video",300,300);
//显示视屏
while(1)
{
pFrame=cvQueryFrame( pCapture );
if(!pFrame)break;
cvShowImage("video",pFrame);
char c=cvWaitKey(33);
if(c==27)break;
}
cvReleaseCapture(&pCapture);
cvDestroyWindow("video");
}
#endif
#include <highgui.h> #if 0 //測试opencv环境数据
int main() {
const char* filename = "g:\\test.jpg" ;//换成你自己的文件路径名!!请注意,双斜杠!! const char* wndname = "http://blog.csdn.net/moc062066" ;
IplImage* pImage = cvLoadImage(filename,CV_LOAD_IMAGE_COLOR) ; cvNamedWindow(wndname,CV_WINDOW_AUTOSIZE);
cvShowImage(wndname,pImage); cvWaitKey(0); cvReleaseImage(&pImage);
cvDestroyWindow(wndname); return 0; }
#else
//採集摄像头数据 #include <cv.h>
#include <cxcore.h>
#include <highgui.h> int main( int argc, char** argv )
{
//声明IplImage指针
IplImage* pFrame = NULL; //获取摄像头
CvCapture* pCapture = cvCreateCameraCapture(-1); //创建窗体
cvNamedWindow("video", 1);
cvResizeWindow("video",300,300); //显示视屏
while(1)
{
pFrame=cvQueryFrame( pCapture );
if(!pFrame)break;
cvShowImage("video",pFrame);
char c=cvWaitKey(33);
if(c==27)break;
}
cvReleaseCapture(&pCapture);
cvDestroyWindow("video");
}
#endif
版权声明:本文博主原创文章,博客,未经同意不得转载。