VS2008编写MFC程序--使用opencv2.4()

开始记录VS2008环境下学习OPENCV2.4

头文件:

 #pragma once
#include "CvvImage.h"
#include "opencv/cv.h"
#include "opencv/highgui.h"

定义全局变量:

在*dlg.cpp

 CvCapture* capture;
CRect rect;
CDC *pDC;
HDC hDC;
CWnd *pwnd;

CPP文件:

 void Cvedio_mfcDlg::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here
if(!capture)
{
capture = cvCaptureFromCAM();
//AfxMessageBox("OK");
} if (!capture)
{
AfxMessageBox("无法打开摄像头");
return;
} // 测试
IplImage* m_Frame;
m_Frame=cvQueryFrame(capture);
CvvImage m_CvvImage;
m_CvvImage.CopyOf(m_Frame,);
if (true)
{
m_CvvImage.DrawToHDC(hDC, &rect);
//cvWaitKey(10);
} // 设置计时器,每10ms触发一次事件
SetTimer(,,NULL);
} void Cvedio_mfcDlg::OnTimer(UINT_PTR nIDEvent)
{
// TODO: Add your message handler code here and/or call default
/************************************************************************/
/* 显示摄像头 */
/************************************************************************/
IplImage* m_Frame;
m_Frame=cvQueryFrame(capture);
CvvImage m_CvvImage;
m_CvvImage.CopyOf(m_Frame,);
if (true)
{
m_CvvImage.DrawToHDC(hDC, &rect);
//cvWaitKey(10);
} CDialog::OnTimer(nIDEvent);
} void Cvedio_mfcDlg::OnBnClickedButton2()
{
// TODO: Add your control notification handler code here
cvReleaseCapture(&capture);
CDC MemDC;
CBitmap m_Bitmap1;
m_Bitmap1.LoadBitmap(IDB_BITMAP1);
MemDC.CreateCompatibleDC(NULL);
MemDC.SelectObject(&m_Bitmap1);
pDC->StretchBlt(rect.left,rect.top,rect.Width(),rect.Height(),&MemDC,,,,,SRCCOPY);
}

托管在github上的源代码:

https://github.com/yuliyang-bupt/simple_camera_mfc

效果:

VS2008编写MFC程序--使用opencv2.4()

上一篇:Java图片缩略图裁剪水印缩放旋转压缩转格式-Thumbnailator图像处理


下一篇:ASP.NET中常用的字符串分割函数