MFC 用对话框VMR_Capture类实现图像采集,抓拍

本文详细介绍如何通过Visual C++创建一个简易的摄像头捕获系统,包括界面布局、控件配置及关键代码实现,如枚举设备、初始化摄像头、设置分辨率、捕获图像等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.新建一个对话框取名摄像头

2.在其中加入一个picture control控件(显示摄像),一个comb控件(存储本机有的摄像头),一个button按钮(拍照)。

给picture control控件设置控制变量命名为my_device        comb控件设置控制变量命名为mylist。

3.准备好VMR_Capture.h文件和VMR_Capture.cpp文件,分别加入到头文件和源文件中

4.打开摄像头Dlg.h头文件在protected中加入变量

CVMR_Capture m_VMRCap;
	CString m_yuvFileName; 
    CFile m_pFile; 
   
	
	int m_imageWidth; 
    int m_imageHeight;


各种头文件宏定义自己补充

#include "stdafx.h"
#include "摄像头.h"
#include "摄像头Dlg.h"
#include "afxdialogex.h"
#include "VMR_Capture.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
#define CAMERA_WIDTH  640   //352 
#define CAMERA_HEIGHT 480 


5.在 摄像头Dlg.cpp 中找到BOOL C摄像头Dlg::OnInitDialog()函数添加如下代码

int m_imageWidth = CAMERA_WIDTH; 
    int  m_imageHeight= CAMERA_HEIGHT; 
	this->m_VMRCap.EnumDevices(this->mylist); 
    this->mylist.SetCurSel(0); 
    int id = this->mylist.GetCurSel(); 
    HRESULT hr = m_VMRCap.Init(id,my_device.GetSafeHwnd(),m_imageWidth,m_imageHeight); 
    if (FAILED(hr))  
        AfxMessageBox(_T("无法创建滤波器链表!")); 


6.双击拍照按钮,补充代码如下

CString sfile="C:\\Users\\Administrator\\Desktop\\sgad.jpg";
	m_VMRCap.ImageCapture(sfile);               

注意路径格式,自己修改。

7.给comb添加消息CBN_SELCHANGE

编辑代码如下

m_VMRCap.CloseInterfaces();
ong m_imageWidth = CAMERA_WIDTH; 
   long  m_imageHeight= CAMERA_HEIGHT; 
	HWND hwnd = this->my_device.GetSafeHwnd(); 
    int id = this->mylist.GetCurSel(); 
    HRESULT hr = m_VMRCap.Init(id,hwnd,m_imageWidth,m_imageHeight); 

编译运行。





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值