运行环境vc6.0 OpenCV1.0 OS:win7
//用户可以通过滚动条动态调节缩放比例,缩放比例的取值为2—8之间
#include "cv.h"
#include "highgui.h"
#include <iostream.h>
int g_slider_position = 0;
int flag = 0;
int pp = 0;
IplImage* doPyrDown(IplImage* in)
{
IplImage* out = cvCreateImage(
cvSize( in->width/2, in->height/2 ),
in->depth,
in->nChannels
);
cvPyrDown( in, out, CV_GAUSSIAN_5x5);
return( out );
};
void onTrackbarSlide(int pos)
{
flag = 1;
pp = pos;
switch(pos){
case 0:
cout << "Exercise3_1中视频画面保持原始大小——1*1" << endl;
flag = 0;
break;
case 1:
cout << "Exercise3_1中视频画面缩小一半——0.5*0.5" << endl;
break;
case 2:
cout << "Exercise3_1中视频画面缩小两半——0.25*0.25" << endl;
break;
case 3:
cout << "Exercise3_1中视频画面缩小三半——0.125*0.125" << endl;
break;
}
};
main() {
CvCapture* capture = cvCreateCameraCapture(-1);
cvNamedWindow( "Exercise3", CV_WINDOW_AUTOSIZE );
cvNamedWindow( "Exercise3_1", CV_WINDOW_AUTOSIZE );
cvCreateTrackbar(
"Position",
"Exercise3",
&g_slider_position,
3,
onTrackbarSlide
);
IplImage* frame;
IplImage* frame1 = NULL;
cout << "程序启动,Exercise3_1中视频画面为原始大小!" << endl;
while(1) {
frame = cvQueryFrame( capture );
if( !frame ) break;
if(flag==0)
frame1 = frame;
else
{
frame1 = frame;
int i = pp;
while(i!=0){
frame1 = doPyrDown(frame1);
i--;
}
cvFlip( frame1, NULL, 0);
}
cvShowImage( "Exercise3", frame );
cvShowImage( "Exercise3_1", frame1 );
char c = cvWaitKey(10);
if( c == 27 ) break;
}
cvReleaseImage( &frame1 );
cvReleaseCapture( &capture );
cvDestroyWindow( "Exercise3_1" );
cvDestroyWindow( "Exercise3" );
return(0);
}
这篇博客详细介绍了在Windows 7操作系统中,如何利用Visual C++ 6.0和OpenCV 1.0进行编程,解答了第二章的习题5。内容涉及环境配置和问题解决方法。

1306

被折叠的 条评论
为什么被折叠?



