如何在vc中调用摄像头并把捕获的图像保存为bmp图片?

dong048 2006-07-09 10:53:16
我想做一个用摄像头拍照的程序,如何在vc中调用摄像头并把捕获的图像保存为bmp图片?哪位大虾可以贴个代码上来吗?
...全文
2694 12 打赏 收藏 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
lid0770 2006-11-06
  • 打赏
  • 举报
回复
用DirectShow吧
wxshzf 2006-11-02
  • 打赏
  • 举报
回复
mark
taianmonkey 2006-07-27
  • 打赏
  • 举报
回复
找找有个叫陆其明的人的网站,他写过这方面的东西!
sxslyy 2006-07-24
  • 打赏
  • 举报
回复
太长了不让发!去google搜"利用VFW进行视频捕捉"吧!有代码!
sxslyy 2006-07-24
  • 打赏
  • 举报
回复
// VFWImageProcessor.h: interface for the CVFWImageProcessor class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_VFWIMAGEPROCESSOR_H__635099B7_63C1_11D4_9EF0_000083A26E84__INCLUDED_)
#define AFX_VFWIMAGEPROCESSOR_H__635099B7_63C1_11D4_9EF0_000083A26E84__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


#include <afxmt.h>
#include <vfw.h>
#include <afxole.h>

#define MAX_VFW_DEVICES 10

//class AFX_EXT_CLASS CVFWImageProcessor
class CVFWImageProcessor
{
public:
CVFWImageProcessor();
virtual ~CVFWImageProcessor();
CVFWImageProcessor(const CVFWImageProcessor ©From);
CVFWImageProcessor &operator =(const CVFWImageProcessor ©From);

BOOL Initialize(SHORT DriverIndex = 0);
VOID Destroy();

BOOL SetDriver(SHORT DriverIndex);

HWND GetCapWindow();

BOOL CaptureDIB(PBITMAPINFO *Bitmap, ULONG BitmapLength, ULONG *RetBitmapLength);
BOOL CaptureAVI(LPCTSTR Filename, FLOAT FramesPerSec, ULONG Duration, UINT Quality);
BOOL EnablePreviewVideo(HWND Parent, INT x, INT y, INT PreviewRate = 30);
BOOL EnablePreviewVideo(HWND Parent, INT x, INT y, INT Width, INT Height, INT PreviewRate = 30);
BOOL DisablePreviewVideo();
BOOL DriverGetCaps(CAPDRIVERCAPS *Caps);
BOOL DlgVideoSource();
BOOL DlgVideoFormat();
BOOL DlgVideoDisplay();
VOID CancelCapture();
BOOL AllocDIBImage(PBITMAPINFO *ppImageData, ULONG *AllocatedSize);

BITMAPINFOHEADER GetBitmapInfoHeader();

VOID GetPreviousError(INT *ErrorID, CString *ErrorString, BOOL ResetError = FALSE);

static ULONG CalcBitmapSize(const BITMAPINFOHEADER &bmiHeader);
static ULONG CalcBitmapInfoSize(const BITMAPINFOHEADER &bmiHeader);

friend LRESULT CALLBACK ErrorCallbackProc(HWND hWnd, int nErrID, LPSTR lpErrorText);
friend LRESULT CALLBACK ControlCallbackProc(HWND hWnd, int nState);
friend LRESULT CALLBACK StatusCallbackProc(HWND hWnd, int nID, LPCSTR lpsz);
friend LRESULT CALLBACK FrameCallbackProc(HWND hWnd, LPVIDEOHDR lpVHdr);
friend LRESULT CALLBACK StreamCallbackProc(HWND hWnd, LPVIDEOHDR lpVHdr);

friend UINT CaptureThreadFunc(VOID *pCVFWImageProcessor);

private: // Data
HWND m_hWndVideo;
CMutex m_ImageProtect;
CEvent m_ImageReady;
CEvent m_CancelCapture;
CEvent m_CaptureEnded;

BITMAPINFOHEADER m_BitmapInfoHeader; // Used to store image dimensions.

PBITMAPINFO m_TransferBitmapInfo;
ULONG m_TransferBitmapInfoSize;

CWinThread *m_CaptureThread;
INT m_DriverIndex;

INT m_ErrorID;
CString m_ErrorText;

static UINT m_ValidDriverIndex[MAX_VFW_DEVICES];
static USHORT m_TotalVideoDrivers;

private: // Functions
CVFWImageProcessor ©(const CVFWImageProcessor ©From);
};

#endif // !defined(AFX_VFWIMAGEPROCESSOR_H__635099B7_63C1_11D4_9EF0_000083A26E84__INCLUDED_)
caferd 2006-07-19
  • 打赏
  • 举报
回复
hwndc = capCreateCaptureWindow ( "my own capture window",
WS_CHILD | WS_VISIBLE , 11 , 11,rectCapsWindow.Width(), rectCapsWindow.Height() ,this->m_hWnd,10001);
//::MoveWindow(hwndc,rectCapsWindow.left,rectCapsWindow.top,rectCapsWindow.Width(),rectCapsWindow.Height(),TRUE);

CAPDRIVERCAPS CapDrvCaps;

::SendMessage ( hwndc, WM_CAP_DRIVER_CONNECT, 0 /* windex */, 0l);

::SendMessage( hwndc, WM_CAP_DRIVER_GET_CAPS,
sizeof(CAPDRIVERCAPS), (LONG) (LPVOID) &CapDrvCaps);

// set preview rate to 66 miliseconds
capPreviewRate( hwndc, 1 );
// start preview video
capPreview( hwndc, TRUE ); //开始预览
capDlgVideoFormat(hwndc); //改变摄像头分辨率,及大小


capFileSaveDIB(hwndc,"C:\\1.bmp");
zhaogaojian 2006-07-17
  • 打赏
  • 举报
回复
http://www.vckbase.com/document/viewdoc/?id=1130
xzj159 2006-07-15
  • 打赏
  • 举报
回复
void CRobotDlg::OnBufsave()
{
// TODO: Add your control notification handler code here
char* FileName;
FileName="E:\\tuxiang.bmp";
bufSave(m_hbuf,FileName);

}
你试着模仿这段代码!
图像存取应该是比较简单的~
dong048 2006-07-11
  • 打赏
  • 举报
回复
没有人能帮帮我吗?
VirtualDesktop 2006-07-11
  • 打赏
  • 举报
回复
用VFW啊,很简单的~~你Google一下C++,Video Capture着关键词
milkzhang 2006-07-10
  • 打赏
  • 举报
回复
这个有意思,关注下
EddieCai 2006-07-10
  • 打赏
  • 举报
回复
摄像头驱动支持TWAIN接口么?
很多怀旧爱好者、民俗查阅人群在查阅传统黄历时一直被纸质挂历的短板困扰,每年都需要购置新日历,存放占用空间,翻阅查找指定日期费时费力,普通电子日历大多样式单调,缺少传统黄历完整民俗信息。**电子手撕老黄历**就是针对这类需求打造的桌面万年历查阅工具,依托仿真纸质交互设计,完整复刻传统老黄历全套内容,无需年年更换,帮助用户沉浸式查阅历法民俗资料,兼顾情怀质感与查阅效率,零学习门槛,适配电脑桌面长期使用。 它的核心能力集中在**仿真纸张交互**与**万年历法检索**两大模块,搭配高清文档导出功能,每一项功能都围绕查阅留存需求设计。仿真纸张交互可以模拟真实挂历翻页、卷纸与手撕页面效果,纸张带有透视阴影,撕纸碎片动态飞出,还原手撕老黄历的怀旧手感。万年历法检索覆盖超大时间跨度,公历农历对照展示,完整收纳节气、宜忌、时辰吉凶、九星五行、冲煞方位等全套黄历信息;高清导出支持 300DPI 图片与多页 PDF 生成,方便资料保存与打印排版。 这款软件可以适配多种个人查阅与素材制作场景。民俗文化爱好者可以随时查询任意年代的历法信息,快速查看每日宜忌、胎神方位、潮汐时间与当日主题对联,用于传统文化内容研读。内容创作者可以借助导出功能,将黄历页面生成为高清图片或 PDF 文档,直接用于图文素材制作。日常居家用户放置在电脑桌面,随时查看节气节日,周末自动切换红色主题,工作日使用青绿纸本样式,区分阅读视觉,满足日常日期查看、民俗参考的轻量需求。

2,644

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 硬件/系统
社区管理员
  • 硬件/系统社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧