1.1-学习Opencv与MFC混合编程之---利用画图函数,生成视频,并写入视频文件

简介: 源代码地址:http://download.csdn.net/detail/nuptboyzhb/3961674 写视频文件 Ø 新建菜单项,Learning OpenCV——> OpenCVr入门——>写视频文件 Ø 菜单项设置如下 Ø 建立类向导 Ø 编辑代码 voidCCV...

源代码地址:http://download.csdn.net/detail/nuptboyzhb/3961674

写视频文件


Ø 新建菜单项,Learning OpenCV——> OpenCVr入门——>写视频文件

Ø 菜单项设置如下


Ø 建立类向导

Ø 编辑代码

voidCCVMFCView::OnMyWriteVedio()

{

       // TODO: Add your command handler codehere

       CStringcsAVI="AVI Files(*.avi)|*.avi|";

      

    CStringcsFilter=csAVI;

      

       CStringname[]={"","avi",""};

      

       CStringstrFileName;

       CStringstrExtension;

      

       CFileDialogFileDlg(false,NULL,NULL,OFN_HIDEREADONLY,csFilter);

       //  文件存盘对话框

       if(FileDlg.DoModal()==IDOK ) {        //  选择了文件名

              strFileName= FileDlg.m_ofn.lpstrFile;

              if(FileDlg.m_ofn.nFileExtension == 0) { //  无文件后缀

                     strExtension= name[FileDlg.m_ofn.nFilterIndex];

                     strFileName= strFileName + '.' + strExtension;

                     //  加文件后缀

              }

              int width = 1000, height = 700;

              //-----------------------------------------------------

              CvVideoWriter *vw;

              vw= cvCreateVideoWriter (strFileName,-1,25, cvSize(width,height),1);  //-1可以

              //-----------------------------------------------------

              int line_type = CV_AA; // changeit to 8 to see non-antialiased graphics

              int i;

              CvPoint pt1,pt2,pt_zhb;

              double angle;

              CvSize sz;

              CvPoint  ptt[6];

              CvPoint* pt[2];

              int  arr[2];

              CvFont font;

              CvRNG rng;

              int width3 = width*3, height3 =height*3;

              CvSize text_size;

              int ymin = 0;

              // Load the source image

              IplImage* image = cvCreateImage(cvSize(width,height), 8, 3 );

              IplImage* image2;

             

              // Create a window

              cvNamedWindow(wndnamed, 1 );

              cvZero( image );

              cvShowImage(wndnamed,image);

              cvWriteFrame(vw,image); 

             

              rng = cvRNG((unsigned)-1);

              pt[0] = &(ptt[0]);

              pt[1] = &(ptt[3]);

             

              arr[0] = 3;

              arr[1] = 3;

             

              m_ImageType=-3;

              for (i = 0; i< NUMBER; i++)

              {

                     pt1.x=cvRandInt(&rng) %width3 - width;

                     pt1.y=cvRandInt(&rng) %height3 - height;

                     pt2.x=cvRandInt(&rng) %width3 - width;

                     pt2.y=cvRandInt(&rng) %height3 - height;

                    

                     cvLine( image, pt1, pt2,random_color(&rng), cvRandInt(&rng)%10, line_type, 0 );

                     cvShowImage(wndnamed,image);

                     cvWriteFrame (vw,image); 

                     cvWaitKey(DELAY);

              }

             

              for (i = 0; i< NUMBER; i++)

              {

                     pt1.x=cvRandInt(&rng) %width3 - width;

                     pt1.y=cvRandInt(&rng) %height3 - height;

                     pt2.x=cvRandInt(&rng) %width3 - width;

                     pt2.y=cvRandInt(&rng) %height3 - height;

                    

                     cvRectangle( image,pt1,pt2, random_color(&rng), cvRandInt(&rng)%10-1, line_type, 0 );

                     cvShowImage(wndnamed,image);

                     cvWriteFrame (vw,image); 

                     cvWaitKey(DELAY);

              }

             

              for (i = 0; i< NUMBER; i++)

              {

                     pt1.x=cvRandInt(&rng) %width3 - width;

                     pt1.y=cvRandInt(&rng) %height3 - height;

                     sz.width=cvRandInt(&rng)%200;

                     sz.height=cvRandInt(&rng)%200;

                     angle =(cvRandInt(&rng)%1000)*0.180;

                    

                     cvEllipse( image, pt1, sz,angle, angle - 100, angle + 200,

                            random_color(&rng),cvRandInt(&rng)%10-1, line_type, 0 );

                     cvShowImage(wndnamed,image);

                     cvWriteFrame (vw,image); 

                     cvWaitKey(DELAY);

              }

             

              for (i = 0; i< NUMBER; i++)

              {

                     pt[0][0].x=cvRandInt(&rng)% width3 - width;

                     pt[0][0].y=cvRandInt(&rng)% height3 - height;

                     pt[0][1].x=cvRandInt(&rng)% width3 - width;

                     pt[0][1].y=cvRandInt(&rng)% height3 - height;

                     pt[0][2].x=cvRandInt(&rng)% width3 - width;

                     pt[0][2].y=cvRandInt(&rng)% height3 - height;

                     pt[1][0].x=cvRandInt(&rng)% width3 - width;

                     pt[1][0].y=cvRandInt(&rng)% height3 - height;

                     pt[1][1].x=cvRandInt(&rng)% width3 - width;

                     pt[1][1].y=cvRandInt(&rng)% height3 - height;

                     pt[1][2].x=cvRandInt(&rng)% width3 - width;

                     pt[1][2].y=cvRandInt(&rng)% height3 - height;

                    

                     cvPolyLine( image, pt, arr,2, 1, random_color(&rng), cvRandInt(&rng)%10, line_type, 0 );

                     cvShowImage(wndnamed,image);

                     cvWriteFrame (vw,image); 

                     cvWaitKey(DELAY);

              }

             

              for (i = 0; i< NUMBER; i++)

              {

                     pt[0][0].x=cvRandInt(&rng)% width3 - width;

                     pt[0][0].y=cvRandInt(&rng)% height3 - height;

                     pt[0][1].x=cvRandInt(&rng)% width3 - width;

                     pt[0][1].y=cvRandInt(&rng)% height3 - height;

                     pt[0][2].x=cvRandInt(&rng)% width3 - width;

                     pt[0][2].y=cvRandInt(&rng)% height3 - height;

                     pt[1][0].x=cvRandInt(&rng)% width3 - width;

                     pt[1][0].y=cvRandInt(&rng)% height3 - height;

                     pt[1][1].x=cvRandInt(&rng)% width3 - width;

                     pt[1][1].y=cvRandInt(&rng)% height3 - height;

                     pt[1][2].x=cvRandInt(&rng)% width3 - width;

                     pt[1][2].y=cvRandInt(&rng)% height3 - height;

                    

                     cvFillPoly( image, pt, arr,2, random_color(&rng), line_type, 0 );

                     cvShowImage(wndnamed,image);

                     cvWriteFrame (vw,image); 

                     cvWaitKey(DELAY);

              }

             

              for (i = 0; i< NUMBER; i++)

              {

                     pt1.x=cvRandInt(&rng) %width3 - width;

                     pt1.y=cvRandInt(&rng) %height3 - height;

                    

                     cvCircle( image, pt1,cvRandInt(&rng)%300, random_color(&rng),

                            cvRandInt(&rng)%10-1,line_type, 0 );

                     cvShowImage(wndnamed,image);

                     cvWriteFrame (vw,image); 

                     cvWaitKey(DELAY);

              }

             

              for (i = 1; i< NUMBER; i++)

              {

                     pt1.x=cvRandInt(&rng) %width3 - width;

                     pt1.y=cvRandInt(&rng) %height3 - height;

                    

                     cvInitFont( &font,cvRandInt(&rng) % 8,

                            (cvRandInt(&rng)%100)*0.05+0.1,(cvRandInt(&rng)%100)*0.05+0.1,

                            (cvRandInt(&rng)%5)*0.1,cvRound(cvRandInt(&rng)%10), line_type );

                    

                     cvPutText( image, "Ilove zjq!", pt1, &font, random_color(&rng));

                     cvShowImage(wndnamed,image);

                     cvWriteFrame(vw,image); 

                     cvWaitKey(DELAY);

              }

             

              cvInitFont( &font, CV_FONT_HERSHEY_COMPLEX,3, 3, 0.0, 5, line_type );

             

              cvGetTextSize( "OpenCVforever!", &font, &text_size, &ymin );

             

              pt1.x = (width -text_size.width)/2-80;

              pt1.y = (height +text_size.height)/2-100;

              image2 = cvCloneImage(image);

              pt_zhb.x=pt1.x;

              pt_zhb.y=pt1.y+300;

              for( i = 0; i < 255; i++ )

              {

                     cvSubS( image2,cvScalarAll(i), image, 0 );

                     cvPutText( image,"OpenCV forever!", pt1, &font, CV_RGB(255,i,i));

                     cvPutText( image,"Made By ZhengHB!", pt_zhb, &font, CV_RGB(255,i,i));

                     cvShowImage(wndnamed,image);

                     cvWriteFrame(vw,image); 

                     cvWaitKey(DELAY);

              }

              // Wait for a key stroke; the samefunction arranges events processing

              cvReleaseVideoWriter (&vw);

              cvWaitKey(0);

              cvReleaseImage(&image);

              cvReleaseImage(&image2);

              cvDestroyWindow(wndnamed);

             

       }

      

}

 

from:http://blog.csdn.net/nupt123456789/article/details/7100125

目录
相关文章
|
6天前
|
机器学习/深度学习 开发框架 TensorFlow
### 如何系统化学习OpenCV4
### 如何系统化学习OpenCV4
5 0
|
6天前
|
Java 开发工具 计算机视觉
Java使用OpenCV3.2实现视频读取与播放
Java使用OpenCV3.2实现视频读取与播放
5 0
|
7天前
|
计算机视觉
OpenCV加载视频
OpenCV加载视频
|
29天前
|
存储 计算机视觉 流计算
【OpenCV】计算视频的光流并跟踪物体calcOpticalFlowPyrLK
【OpenCV】计算视频的光流并跟踪物体calcOpticalFlowPyrLK
32 0
|
29天前
|
编解码 API 计算机视觉
opencv从视频文件读取视频内容,从摄像头读取保存视频内容
opencv从视频文件读取视频内容,从摄像头读取保存视频内容
|
29天前
|
算法 C++ 计算机视觉
Opencv(C++)学习系列---Laplacian拉普拉斯边缘检测算法
Opencv(C++)学习系列---Laplacian拉普拉斯边缘检测算法
|
29天前
|
算法 计算机视觉 C++
Opencv(C++)学习系列---Sobel索贝尔算子边缘检测
Opencv(C++)学习系列---Sobel索贝尔算子边缘检测
|
6天前
|
存储 编解码 API
【图像文本化】Base64编解码OpenCV4中 Mat 对象
【图像文本化】Base64编解码OpenCV4中 Mat 对象
9 0
|
6天前
|
机器学习/深度学习 编解码 计算机视觉
【一秒梵高】基于OpenCV4实现图像九种风格迁移
【一秒梵高】基于OpenCV4实现图像九种风格迁移
11 0
|
6天前
|
计算机视觉
OpenCV中图像算术操作与逻辑操作
OpenCV中图像算术操作与逻辑操作
8 1