⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 video.cpp

📁 视频捕捉图片并进行灰度处理24真彩图像转换成8为灰度图像
💻 CPP
字号:
// Video.cpp : implementation file
//

#include "stdafx.h"
#include "Express.h"
#include "Video.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CVideo dialog


CVideo::CVideo(CWnd* pParent /*=NULL*/)
	: CDialog(CVideo::IDD, pParent)
{
	//{{AFX_DATA_INIT(CVideo)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CVideo::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CVideo)
	DDX_Control(pDX, IDC_123, m_FrameNum);
	DDX_Control(pDX, IDC_PANCEL, m_Panel);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CVideo, CDialog)
	//{{AFX_MSG_MAP(CVideo)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CVideo message handlers

BOOL CVideo::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_Captured=FALSE;
	m_hWndVideo=capCreateCaptureWindow(NULL,WS_CHILD|WS_VISIBLE,100,100,160,160,m_hWnd,0); 
	if(capDriverConnect(m_hWndVideo,0))
	{
		::SetParent(m_hWndVideo,*this);
		::SetWindowLong(m_hWndVideo,GWL_STYLE,WS_CHILD);
		CRect wndRC;
		m_Panel.GetClientRect(wndRC);
		m_Panel.MapWindowPoints(this,wndRC);
		wndRC.DeflateRect(1,1,1,1);
		::SetWindowPos(m_hWndVideo,NULL,wndRC.left,wndRC.top,wndRC.Width(),
			wndRC.Height(),SWP_NOZORDER);
		::ShowWindow(m_hWndVideo,SW_SHOW);
		CAPDRIVERCAPS caps;
		capDriverGetCaps(m_hWndVideo,sizeof(caps),&caps);
		if(caps.fHasOverlay)
		{
			capOverlay(m_hWndVideo,TRUE);
			CAPTUREPARMS params;
			capCaptureGetSetup(m_hWndVideo,&params,sizeof(params));
			params.fYield=TRUE;
			params.fAbortLeftMouse=FALSE;
			params.fAbortRightMouse=FALSE;
			params.fLimitEnabled=FALSE;
			params.vKeyAbort=FALSE;
			params.fCaptureAudio=FALSE;
			capCaptureSetSetup(m_hWndVideo,&params,sizeof(params));
			capSetCallbackOnFrame(m_hWndVideo,EncodeCallback);
			capPreviewRate(m_hWndVideo,1);
			capPreview(m_hWndVideo,TRUE);
		}
	}
	SetTimer(1,800,NULL);		
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CVideo::OnOK() 
{
	// TODO: Add extra validation here
	m_Captured=TRUE;
	capGrabFrameNoStop(m_hWndVideo);
	
	capFileSaveDIB(m_hWndVideo,"表情.bmp");
	::MessageBox(0,"图像提取完毕","提示",MB_OK);
}

void CVideo::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	CString str;
	str.Format("%i",num);
	m_FrameNum.SetWindowText(str);
	CDialog::OnTimer(nIDEvent);
}

void CVideo::OnCancel() 
{
	// TODO: Add extra cleanup here
	capSetCallbackOnFrame(m_hWndVideo,NULL);

	capDriverDisconnect(m_hWndVideo);
	CDialog::OnCancel();
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -