#include <cv.h>
#include <cvcam.h>
#include <cxcore.h>
#include <highgui.h>
#pragma comment(lib,"cv.lib")
#pragma comment(lib,"cvcam.lib")
#pragma comment(lib,"cxcore.lib")
#pragma comment(lib,"highgui.lib")
void main()
{
CvCapture *capture=cvCreateFileCapture("my.avi"); //创建capture对象
assert(capture!=NULL);
IplImage *image=cvQueryFrame(capture); //获取一个图像
assert(image!=NULL);
IplImage *grary_image=cvCreateImage(cvGetSize(image),image->depth,1); //创建单通道的gray_image
assert(grary_image!=NULL);
IplImage *canny_image=cvCreateImage(cvGetSize(image),image->depth,1); //创建单通道的gray_image
assert(canny_image!=NULL);
IplImage *merge_image=cvCreateImage(cvSize(image->width*3,image->height),image->depth,3);
assert(merge_image); //创建三通道的merge_image
IplImage *three_channel_gray_image=cvCreateImage(cvGetSize(image),image->depth,image->nChannels);
assert(three_channel_gray_image!=NULL); //创建一个三通道的three_channel_gray_image
IplImage *three_channel_canny_image=cvCreateImage(cvGetSize(image),image->depth,image->nChannels);
assert(three_channel_canny_image!=NULL); //创建一个三通道的three_channel_canny_image
IplImage *sub_image1=cvCreateImage(cvGetSize(image),image->depth,image->nChannels); //创建一个sub_image1用来指向merge_image的开始处
sub_image1->origin=merge_image->origin;
sub_image1->widthStep=merge_image->widthStep;
IplImage *sub_image2=cvCreateImage(cvGetSize(image),image->depth,image->nChannels); //创建一个sub_image1用来指向merge_image的1/3处
sub_image2->origin=merge_image->origin;
sub_image2->widthStep=merge_image->widthStep;
IplImage *sub_image3=cvCreateImage(cvGetSize(image),image->depth,image->nChannels); //创建一个sub_image1用来指向merge_image的2/3处
sub_image3->origin=merge_image->origin;
sub_image3->widthStep=merge_image->widthStep;
cvNamedWindow("Show_Orginal"); //创建窗口
cvNamedWindow("Show_Gray");
cvNamedWindow("Show_Canny");
cvNamedWindow("Show_Merge");
while ((image=cvQueryFrame(capture))!=NULL)
{
cvConvertImage(image,grary_image,CV_CVTIMG_FLIP); //将image转换为灰度图
cvCanny(grary_image,canny_image,150,50); //将gray_image做canny处理
cvConvertImage(grary_image,three_channel_gray_image); //将gray_image转换为三通道
cvConvertImage(canny_image,three_channel_canny_image); //将canny_image转换为三通道
sub_image1->imageData=merge_image->imageData; //确定三个指针的指向
sub_image2->imageData=merge_image->imageData+merge_image->widthStep/3;
sub_image3->imageData=merge_image->imageData+merge_image->widthStep/3*2;
cvCopyImage(image,sub_image1); //将要拷贝的图像拷贝到相应的位置
cvConvertImage(sub_image1,sub_image1,CV_CVTIMG_FLIP);
cvCopyImage(three_channel_gray_image,sub_image2);
cvCopyImage(three_channel_canny_image,sub_image3);
cvShowImage("Show_Orginal",image);
cvShowImage("Show_Gray",three_channel_gray_image); //显示图像
cvShowImage("Show_Canny",three_channel_canny_image);
cvShowImage("Show_Merge",merge_image);
if (27==cvWaitKey(30))
{
break;
}
}
cvDestroyAllWindows(); //释放所有资源
cvReleaseCapture(&capture);
cvReleaseImage(&grary_image);
cvReleaseImage(&canny_image);
cvReleaseImage(&sub_image1);
cvReleaseImage(&sub_image2);
cvReleaseImage(&sub_image3);
}