免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1514 | 回复: 0
打印 上一主题 下一主题

转-在QT实现摄像头图像采集 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-11-04 08:50 |只看该作者 |倒序浏览

                               
在QT实现摄像头图像采集
      
        
tingxx
发表于 2008-04-05 21:16:37
      
      
之前已经写了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之后,就调动里面的[color="#0000ff"]capCreateCaptureWindowA()函数,然后是一系列的SendMessage
运行效果图如下


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

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/69947/showart_1358844.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP