读取摄像头数据(学习openCV课后题 2.4)

// 第二章 课后练习题
// 题号:2.4
// 功能:读取摄像头的数据,将是视频文件的尺寸缩小一倍
// 将实时的图像显示出来。

#include "cv.h"
#include "highgui.h"

/*******************************************************************/
/* 函数名 : doPyrDown() 执行图形的向下图像金字塔
/*   参数 : input       输入图像
/*          filter      cvPyrDown()的默认参数
/*   功能 : 将输入图像input缩小一倍,并返回指向经过缩小处理图像的指针
/*******************************************************************/
 
IplImage *doPyrDown(IplImage *input,int filter=CV_GAUSSIAN_5x5)
{
 //Make sure the width and the height of the image are divisable
 assert(input->width%2==0 && input->height%2==0);

 IplImage *output=cvCreateImage(cvSize(input->width/2,input->height/2),
         input->depth,
         input->nChannels);

 assert(output!=NULL);

 cvPyrDown(input,output,CV_GAUSSIAN_5x5);

 return(output);

}

/**************************主函数**************************/

void main()
{
 //create capture object
 CvCapture *capture=cvCreateCameraCapture(0);

 if (NULL==capture)
 {
  return ;
 }
 
 //create a window to show the image
 cvNamedWindow("Show1");
 cvNamedWindow("Show2");
 
 //create a IplImage* object to receive image from capture
 IplImage *image =cvQueryFrame(capture);

 //To receive the image being pyrDowned
 IplImage *change_iamge=cvCreateImage(cvSize(image->width/2,image->height/2),
            image->depth,
            image->nChannels);

 while (NULL!=(image=cvQueryFrame(capture)))
 {
  change_iamge=doPyrDown(image);
  cvConvertImage(change_iamge,change_iamge,CV_CVTIMG_FLIP);

  //show the images in windows
  cvShowImage("Show1",image);
  cvShowImage("Show2",change_iamge);

  //if press ESC break
  char c=cvWaitKey(23);
  if (27==c)
  {
   break;
  }
 }
 
 //release the resourse
 cvReleaseCapture(&capture);
 cvDestroyWindow("Show1");
 cvDestroyWindow("Show2");
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值