在QT实现摄像头图像采集

之前已经写了minGW环境中DL的创建与调动,也实验了在QT下如何用QLibrary来调动外部的DLL.于是更进一步,要用QT实现摄像头图像的采集.原理就是基于win32下的capavi32.dll的调动,参考了网上的一些DELPHI程序
由于只是为了实现功能,所以界面上没有任何的button之类,所有的代码都完成在构造函数中.
#include
#include
#include
const static int WM_CAP_START=WM_USER;
const static int WM_CAP_STOP = WM_CAP_START + 68;
const static int WM_CAP_DRIVER_CONNECT=WM_CAP_START+10;
const static int WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11;
const static int WM_CAP_SAVEDIB = WM_CAP_START + 25;
const static int WM_CAP_GRAB_FRAME = WM_CAP_START + 60;
const static int WM_CAP_SEQUENCE = WM_CAP_START + 62;
const static int WM_CAP_FILE_SET_CAPTURE_FILEA = WM_CAP_START + 20;
const static int WM_CAP_SEQUENCE_NOFILE =WM_CAP_START+ 63;
const static int WM_CAP_SET_OVERLAY =WM_CAP_START+ 51 ;
const static int WM_CAP_SET_PREVIEW =WM_CAP_START+ 50  ;
const static int WM_CAP_SET_CALLBACK_VIDEOSTREAM = WM_CAP_START +6;
const static int WM_CAP_SET_CALLBACK_ERROR=WM_CAP_START +2;
const static int WM_CAP_SET_CALLBACK_STATUSA= WM_CAP_START +3;
const static int WM_CAP_SET_CALLBACK_FRAME= WM_CAP_START +5;
const static int WM_CAP_SET_SCALE=WM_CAP_START+ 53;
const static int WM_CAP_SET_PREVIEWRATE=WM_CAP_START+ 52;
CamViewer::CamViewer(QWidget *parent)
    : QWidget(parent)
{
    resize(400,300);
    QLibrary mylib("avicap32");
    if(mylib.load()){
//        QMessageBox::information(this,tr("info"),tr("load dll OK!"));
        typedef HWND(* capCreateFunc)(char *lpszWindowName,long int swStyle,
                int x,int y,int nWidth,int nHeight,HWND parentWin,int nID);
        capCreateFunc capCreate=(capCreateFunc)mylib.resolve("capCreateCaptureWindowA");
        if(capCreate){
            HWND h=capCreate("my own capture window",WS_CHILD|WS_VISIBLE,0,0,width(),height(),winId(),0);
            if(h){
                SendMessage(h,WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0);
                SendMessage(h,WM_CAP_SET_CALLBACK_ERROR,0,0);
                SendMessage(h,WM_CAP_SET_CALLBACK_STATUSA,0,0);
                SendMessage(h,WM_CAP_DRIVER_CONNECT,0,0);
                SendMessage(h,WM_CAP_SET_SCALE,1,0);
                SendMessage(h,WM_CAP_SET_PREVIEWRATE,66,0);
                SendMessage(h,WM_CAP_SET_OVERLAY,1,0);
                SendMessage(h,WM_CAP_SET_PREVIEW,1,0);
            }
               
        }
    }
}
说起来也是很简单,载入avicap.dll之后,就调动里面的 capCreateCaptureWindowA()函数,然后是一系列的SendMessage
运行效果图如下


其它的功能比如截图或是保存到avi文件之类的,也就是再多加几个SendMessage而已,或是再设计一个漂亮的UI
加上PushButton,没有想再继续写下去,我的目的已经达到了
[url=/post.2028303.html]...[/url]
-->
      
      
        关键词(Tag):
        
eclipse
        
qt
        
mingw
http://www.yculblog.com/tags/qt
      
               
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值