以上是参考链接
系统:win10
配置:VS2008+OpenCV 2.3.1
- File|New|Project|MFC Application|Name(MFCtest)
MFC Application Wizard
Application type :Single document
Use of MFC: static library
Use Unicode libraries:No
ActiveX controls:No
-Project|porperties|Linker|Input
Configuration:Active(Debug) and Release
Additional Dependencies:
opencv_calib3d231d.lib
opencv_contrib231d.lib
opencv_core231d.lib
opencv_features2d231d.lib
opencv_flann231d.lib
opencv_gpu231d.lib
opencv_highgui231d.lib
opencv_imgproc231d.lib
opencv_legacy231d.lib
opencv_ml231d.lib
opencv_objdetect231d.lib
opencv_ts231d.lib
opencv_video231d.libSolution|MFCtestDoc.h|添加 include”CvvImage.h”|public in class CMFCtestDoc 添加 CvvImage m_image
在链接中,使用的是OpenCV2.0.0 而我们使用的是OpenCV 2.3.1 这个版本中取消了CImage这个类型,所以这里我们可以通过添加原版本的CvvImage类型来实现,添加两个文件CvvImage.h 和CvvImage.c 到工程中。Class View|CMFCtestDoc|Add Function
添加两个函数
OnOpenDocument 和 OnSaveDocument:
Return type:BOOL(bool编译可能会出错)
Function name:OnOpenDocument
Parameter type:LPCTSTR
Parameter name: lpszPathName
Choose Virtual
Return type:BOOL(bool编译可能会出错)
Function name:OnSaveDocument
Parameter type:LPCTSTR
Parameter name: lpszPathName
Choose Virtual
BOOL CMFCtestDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
if(!CDocument::OnOpenDocument(lpszPathName))
return false;
m_image.Load(lpszPathName);
return true;
}
BOOL CMFCtestDoc::OnSaveDocument(LPCTSTR lpszPathName)
{
m_image.Save(lpszPathName);
return true;
}
- CMFCtestView.c|OnDraw
void CMFCtestView::OnDraw(CDC* pDC)
{
CMFCtestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
CvvImage & img = pDoc ->m_image;
CRect r;
GetClientRect (&r);
img.DrawToHDC(pDC->GetSafeHdc() ,r);
}
运行可以实现MFC中快速应用OpenCV
下面是CvvImage.c 和 CvvImage.h 的内容
CvvImage.h
#pragma once
#ifndef CVVIMAGE_CLASS_DEF
#define CVVIMAGE_CLASS_DEF
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/imgproc/imgproc_c.h"
class CvvImage
{
public:
CvvImage();
virtual ~CvvImage();
virtual bool Create( int width,