Windows下使用采集卡directshow

Windows下使用采集卡directshow

本文提供了使用directshow代替opencv的vfw 的源代码,与转化为iplimage格式的算法. 实验中发现opencv的cvCaptureFromCAM 使用的是vfw,采用消息机制,速度较慢,测试发现fps只有 9-12左右,太慢了. 发现经过使用directshow后速度提升到60帧/s. 在opencv group上了解到这是一个普遍问题,也许有人做过转换,却没有完整的例子与代码.在此贴出.对希望提高opencv视频分析速度的有所帮助.

ARFrameGrabber 是这样封装后的一个类,用法如下: <c>static ARFrameGrabber frameGrabber; //声明对象 IplImage ds_frame; frameGrabber.Init(0, true); //设置支持directshow的设备编号,从0开始 frameGrabber.SetFlippedImage(true); //图像是否翻转 for(;;)

   {
      IplImage *frame =0;
      frameGrabber.GrabByteFrame(); //获取一帧
      BYTE *myBuffer = frameGrabber.GetByteBuffer(); //得到图像的缓冲 
      int width = frameGrabber.GetWidth();
      int height = frameGrabber.GetHeight();  
      int stride  = (width * sizeof( RGBTRIPLE ) + 3) & -4;
      cvInitImageHeader( &ds_frame, cvSize(width, height), 8, 3,IPL_ORIGIN_BL, 4 ); //创建iplimage
      ds_frame.widthStep = stride;   
      cvSetData( &ds_frame, myBuffer, stride );  //copy数据
      frame = &ds_frame;
       /* 视频分析部分 */
     
  }

</c>

以下是directshow源文件,加入工程可用。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值