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;
}
存在bug如下:
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
初始化从摄像头中获取视频
CvCapture* cvCreateCameraCapture( int index );
index
要使用的摄像头索引。如果只有一个摄像头或者用哪个摄像头也无所谓,那使用参数-1应该便可以。 还有见过设置为0也可以。
函数cvCreateCameraCapture给从摄像头的视频流分配和初始化CvCapture结构。目前在Windows下可使用两种接口:Video for Windows(VFW)和Matrox Imaging Library(MIL); Linux下也有两种接口:V4L和FireWire(IEEE1394)。
释放这个结构,使用函数cvReleaseCapture。
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;
}