1.加载图像
// load image.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include "highgui.h" #include "cv.h" #include "cxcore.h" int _tmain(int argc, _TCHAR* argv[]) { IplImage* src = cvLoadImage("C:\\Users\\Authur\\Desktop\\OpenCV\\image\\bikaqiu.jpeg",1); cvNamedWindow("show_image",0); cvShowImage("show_image",src);//src是一个输入图像的地址 cvWaitKey(0); cvReleaseImage(&src); //释放句柄 cvDestroyWindow("show_image");//注销窗口 return 0; }
// load video.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include "highgui.h" int _tmain(int argc, _TCHAR* argv[]) { cvNamedWindow("avi"); CvCapture* capture = cvCreateFileCapture("C:\\Users\\Authur\\Desktop\\OpenCV\\video\\video ex1.avi"); //CvCapture用于保存图像获取所需要的信息 //两种视频读取方式,文件和摄像头 //cvCreateFileCapture 其后是视频的路径 //这个函数返回空 就是没有解码器 IplImage* frame; while(1) { frame = cvQueryFrame(capture); if(!frame) break; cvShowImage("avi",frame); char c = cvWaitKey(33); if(c==27) break; } cvReleaseCapture(&capture); cvDestroyWindow("avi"); return 0; }
3.加载摄像头
// camera.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include "highgui.h" int _tmain(int argc, _TCHAR* argv[]) { cvNamedWindow("avi"); CvCapture* capture = cvCreateCameraCapture(-1); IplImage* frame; while(1) { frame = cvQueryFrame(capture); if(!frame) break; cvShowImage("avi",frame); char c = cvWaitKey(1); if ( c== 27) break; } cvReleaseCapture(&capture); cvDestroyWindow("avi"); return 0; }cvCreateCameraCapture
4.cvSmooth平滑处理
#include "stdafx.h" #include "highgui.h" #include "cv.h"
<span style="font-family: Arial, Helvetica, sans-serif;">int _tmain(int argc, _TCHAR* argv[])</span>
{ //cvSmooth IplImage* image = cvLoadImage("C:\\Users\\Authur\\Desktop\\OpenCV\\image\\bikaqiu.jpeg"); cvNamedWindow("Example4-in"); cvNamedWindow("Example4-out"); cvShowImage("Example4-in",image); IplImage* out = cvCreateImage( cvGetSize(image), IPL_DEPTH_8U, 3 ); cvSmooth(image,out,CV_GAUSSIAN,3,3); cvShowImage("Example4-out",out); cvReleaseImage(&out); cvWaitKey(0); cvDestroyWindow("Example4-in"); cvDestroyWindow("Example4-out");
<span style="white-space:pre"> </span>return 0;
}