// GetTheAVI.cpp : implementation file
//
#include "stdafx.h"
#include "GetTheAVI.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CGetTheAVI
CGetTheAVI::CGetTheAVI()
{
lpstrCapWndName = new char[128];
char ch[] = "MYAVI";
strcpy(lpstrCapWndName,ch);
SetTheCapWndRect(CRect(0,0,320,240));
hCapWnd = NULL;
m_iDriverNumber= 0;
memset(m_DriverDescript,-1,sizeof(m_DriverDescript));
m_iTheCurrentSelectDriver = 0;
}
CGetTheAVI::~CGetTheAVI()
{
if (lpstrCapWndName)
delete lpstrCapWndName;
//capCapture
//cap
capCaptureStop(hCapWnd);
//capDriverDisconnect(hCapWnd);
//CloseHandle(hCapWnd);
//hCapWnd->unused =TRUE;
}
BEGIN_MESSAGE_MAP(CGetTheAVI, CStatic)
//{{AFX_MSG_MAP(CGetTheAVI)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGetTheAVI message handlers
BOOL CGetTheAVI::InitDevice(HWND hparent)
{
BOOL bret =CreateTheCapWND(hparent);
if (!bret) return FALSE;
bret = FALSE;
char szDeviceName[80];
char szDeviceVersion[80];
for (int wIndex = 0; wIndex < 10; wIndex++)
{
if (capGetDriverDescription (wIndex, szDeviceName,
sizeof (szDeviceName), szDeviceVersion,
sizeof (szDeviceVersion)) )
{
// Append name to list of installed capture drivers
// and then let the user select a driver to use.
m_DriverDescript[m_iDriverNumber].SaveTheDeviceInfomation(szDeviceName,szDeviceVersion,wIndex);
//m_DriverDescript[m_iDriverNumber].index = wIndex;
m_iDriverNumber++;
}
}
if (m_iDriverNumber<=0)
{
MessageBox("没找到摄像头");
return FALSE;
}
return TRUE;
}
BOOL CGetTheAVI::CreateTheCapWND(HWND hparent)
{
HWND hwnd = capCreateCaptureWindow(lpstrCapWndName,WS_CHILD|WS_VISIBLE,
m_RectCapWnd.left,m_RectCapWnd.top,
m_RectCapWnd.right-m_RectCapWnd.left,
m_RectCapWnd.bottom-m_RectCapWnd.top,
hparent,1);
if (!hwnd){
MessageBox("创建捕获窗口失败!");
return FALSE;
}
hCapWnd = hwnd;
capSetCallbackOnError(hCapWnd,(FARPROC)ErrorCallbackProc);
capSetCallbackOnStatus(hCapWnd,(FARPROC)StatusCallbackProc);
capSetCallbackOnFrame(hCapWnd,(FARPROC)FrameCallbackProc);
return TRUE;
}
void CGetTheAVI::SetTheCapWndRect(CRect &r)
{
if (r!=m_RectCapWnd)
{
m_RectCapWnd = r;
}
}
BOOL CGetTheAVI::SelectTheDeviceAndConnect(UINT index)
{
if(!capDriverConnect(hCapWnd,index))
return FALSE;
m_iTheCurrentSelectDriver = index;
return TRUE;
}
BOOL CGetTheAVI::StopTheConnection(UINT index)
{
if(!capDriverDisconnect (hCapWnd))
return FALSE;
capCaptureStop(hCapWnd);
return TRUE;
}
BOOL CGetTheAVI::StartPreview()
{
capGetStatus(hCapWnd, &m_capStatus, sizeof (CAPSTATUS));
::SetWindowPos(hCapWnd, NULL, 0, 0, m_capStatus.uiImageWidth,
m_capStatus.uiImageHeight, SWP_NOZORDER | SWP_NOMOVE);
//capCaptureSequenceNoFile(hCapWnd);
//capDriverGetCaps(ghWndCap,&gCapDriverCaps,sizeof(CAPDRIVERCAPS));
if(m_capDrive.fHasDlgVideoSource)capDlgVideoSource(hCapWnd); //Video source 对话框
if(m_capDrive.fHasDlgVideoFormat)capDlgVideoFormat(hCapWnd); // Video format 对话框
if(m_capDrive.fHasDlgVideoDisplay)capDlgVideoDisplay(hCapWnd); // Video display 对话框
capPreviewRate(hCapWnd, 66); // 设置Preview模式的显示速率
capPreview(hCapWnd, TRUE);
return TRUE;
}
BOOL CGetTheAVI::ENDPrivew()
{
if(capPreview(hCapWnd, false))return TRUE;
else return FALSE;
}
LRESULT CGetTheAVI::StatusCallbackProc(HWND hWnd, int nID, LPSTR lpStatusText)
{
if (!hWnd)
return FALSE;
// if (nID == 0) { // Clear old status messages.
// ::SetWindowText(hWnd, (LPSTR) lpstrCapWndName);
// return (LRESULT) TRUE;
// }
// Show the status ID and status text...
char gachBuffer[128];
wsprintf(gachBuffer, "Status# %d: %s", nID, lpStatusText);
::SetWindowText(hWnd, (LPSTR)gachBuffer);
return (LRESULT) TRUE;
}
LRESULT CGetTheAVI::ErrorCallbackProc(HWND hWnd, int nErrID,LPSTR lpErrorText)
{
if (!hWnd)
return FALSE;
if (nErrID == 0) // Starting a new major function.
return TRUE; // Clear out old errors.
// Show the error identifier and text.
char gachBuffer[128];
wsprintf(gachBuffer, "Error# %d", nErrID);
AfxMessageBox(gachBuffer);
return (LRESULT) TRUE;
}
LRESULT CGetTheAVI::FrameCallbackProc(HWND hWnd, LPVIDEOHDR lpVHdr)
{
if (!hWnd)
return FALSE;
char gachBuffer[128];
wsprintf(gachBuffer, "Preview frame# %ld "/*, gdwFrameNum++*/);
::SetWindowText(hWnd, (LPSTR)gachBuffer);
return (LRESULT) TRUE ;
}
BOOL CGetTheAVI::SaveTheAVI(CString &szCaptureFile)
{
capFileSetCaptureFile( hCapWnd, szCaptureFile.GetBuffer(30)); //指定捕获文件名
szCaptureFile.ReleaseBuffer();
capFileAlloc(hCapWnd, (1024L * 1024L * 10)); //为捕获文件分配存储空间
capCaptureSequence(hCapWnd); //开始捕获视频序列
capGrabFrame(hCapWnd); //捕获单帧图像
return TRUE;
}
没有合适的资源?快使用搜索试试~ 我知道了~
USB_Video.rar_USB摄像头枚举_枚举usb摄像头_枚举摄像头
共17个文件
h:6个
cpp:5个
dsw:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 58 浏览量
2022-09-19
13:42:17
上传
评论
收藏 14KB RAR 举报
温馨提示
一段简单的通过枚举搜索出机子上所有的摄像头获取摄像头视频的代码
资源详情
资源评论
资源推荐
收起资源包目录
USB_Video.rar (17个子文件)
www.pudn.com.txt 218B
USBAVI2
DriverDescript.h 702B
USBAVI2.dsp 4KB
res
USBAVI2.rc2 399B
USBAVI2.ico 1KB
USBAVI2.rc 5KB
GetTheAVI.cpp 5KB
DriverDescript.cpp 937B
USBAVI2.dsw 537B
GetTheAVI.h 2KB
USBAVI2Dlg.cpp 5KB
StdAfx.cpp 209B
resource.h 777B
StdAfx.h 1KB
USBAVI2.cpp 2KB
USBAVI2Dlg.h 1KB
USBAVI2.h 1KB
共 17 条
- 1
钱亚锋
- 粉丝: 86
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0