学习opencv 第二章 习题5答案

这篇博客详细介绍了在Windows 7操作系统中,如何利用Visual C++ 6.0和OpenCV 1.0进行编程,解答了第二章的习题5。内容涉及环境配置和问题解决方法。

运行环境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);
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值