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 <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