《学习OpenCV》第二章 课后题5
2015-06-04 09:44
169 查看
题目叙述:给程序加入滚动条,使得用户可以动态调节缩放比例,缩放比例的取值为2~8之间。可以跳过写入磁盘操作,但是必须将变换结果显示在窗口中。
注:不要将滚动条放在缩放的窗口中,因为效果不好,喜欢的可以试试看!
#include "cv.h" #include "highgui.h" #include <stdio.h> int pos = 2 ; // Convert a video to grayscale // argv[1]: input video file // argv[2]: name of new output file // //#define NOWRITE 1; //Turn this on (removed the first comment out "//" if you can't write on linux void ON_Change(int n) { //printf("d%",n); pos = n; } void main( ) { cvNamedWindow( "Example2_10", CV_WINDOW_AUTOSIZE ); cvNamedWindow( "Log_Polar", CV_WINDOW_AUTOSIZE ); CvCapture* capture = cvCreateFileCapture("G:/数据/OpenCV数据/song.mp4" ); //if (!capture){ // return -1; //} cvCreateTrackbar("scale","Example2_10",&pos,8,ON_Change);//创建滚动条 IplImage* bgr_frame; double fps = cvGetCaptureProperty ( capture, CV_CAP_PROP_FPS ); printf("fps=%d\n",(int)fps); CvSize size = cvSize( (int)cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH), (int)cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT) ); printf("frame (w, h) = (%d, %d)\n",size.width,size.height); #ifndef NOWRITE CvVideoWriter* writer = cvCreateVideoWriter( "G:/数据/OpenCV数据/wind-img2.avi", CV_FOURCC('M','J','P','G'), fps, size ); #endif IplImage* logpolar_frame = cvCreateImage( size, IPL_DEPTH_8U, 3 ); IplImage* gray_frame = cvCreateImage( size, IPL_DEPTH_8U, 1 ); while( (bgr_frame=cvQueryFrame(capture)) != NULL ) { cvShowImage( "Example2_10", bgr_frame ); //We never make use of this gray image cvConvertImage( bgr_frame, gray_frame, CV_RGB2GRAY ); //This is just a fun conversion the mimic's the human visual system cvLogPolar( bgr_frame, logpolar_frame, cvPoint2D32f(bgr_frame->width/2, bgr_frame->height/2), 40, CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS ); IplImage* img2 = cvCreateImage( cvSize( logpolar_frame->width/(pos+1),logpolar_frame->height/(pos+1)), logpolar_frame->depth, logpolar_frame->nChannels); cvResize(logpolar_frame, img2, CV_INTER_LINEAR); cvShowImage( "Log_Polar", img2 ); //Sigh, on linux, depending on your ffmpeg, this often won't work ... //#ifndef NOWRITE // cvWriteToAVI( writer, img2 ); //#endif char c = cvWaitKey(10); if( c == 27 ) break; } #ifndef NOWRITE cvReleaseVideoWriter( &writer ); #endif cvReleaseImage( &gray_frame ); cvReleaseImage( &logpolar_frame ); cvReleaseCapture( &capture ); }
注:不要将滚动条放在缩放的窗口中,因为效果不好,喜欢的可以试试看!
相关文章推荐
- Hadoop的简单控制台log分析
- Hadoop杂谈
- linux下搭建svn代码库
- linix下的nginx源码安装
- 6月4日 资源网站
- use dict in bash
- I2C-pcf8563
- linux在shell中获取时间
- 在Docker中自动化部署Ruby on Rails的教程
- CentOS制作本地yum源配置说明
- (转)App工程结构搭建:几种常见Android代码架构分析
- [转载] Docker背后的容器管理——Libcontainer深度解析
- Ubuntu下VIM的安装及其配置——Linux篇
- nginx--可扩展数组和数组排序
- string中c_str()、data()、copy(p,n)函数的用法
- 安全问题-携程可能摊上大事了——崩溃原因分析
- RSYNC的介绍和配置
- Debugging Nutch With Hbase on Hadoop Fully Distributed Mode
- Linux 定时任务
- Nginx配置文件详细说明