建立工程见
http://www.opencv.org.cn/index.php/MFC%E4%B8%AD%E5%BF%AB%E9%80%9F%E5%BA%94%E7%94%A8OpenCV
在Doc类中添加变量
不要建立CImage m_image,改为
public:
IplImage *m_image;
加头文件:
#include "highgui.h"
初始化 m_image
CMFC_testDoc::CMFC_testDoc()
{
// TODO: add one-time construction code here
m_image = NULL;
}
在工程中加入以下两个文件
http://opencv-extension-library.googlec ... CvxWin32.h
http://opencv-extension-library.googlec ... xWin32.cpp
在stdafx.h中,加入#include "CvxWin32.h"
在CvxWin32.cpp中加入 #include "stdafx.h"
BOOL CMFC_testDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
if (!CDocument::OnOpenDocument(lpszPathName))
return FALSE;
// TODO: Add your specialized creation code here
m_image = cvLoadImage(lpszPathName);
return TRUE;
}
BOOL CMFC_testDoc::OnSaveDocument(LPCTSTR lpszPathName)
{
// TODO: Add your specialized code here and/or call the base class
cvSaveImage(lpszPathName,m_image);
return TRUE;//CDocument::OnSaveDocument(lpszPathName);
}
在View类中添加显示图像代码
void CMFC_testView::OnDraw(CDC* pDC)
{
CMFC_testDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CvxWin32::DrawToHDC(pDoc->m_image,pDC->GetSafeHdc(),NULL);
}
如果需要实现canny
BOOL CMFC_testDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
if (!CDocument::OnOpenDocument(lpszPathName))
return FALSE;
// TODO: Add your specialized creation code here
m_image = cvLoadImage(lpszPathName,0);
return TRUE;
}
void CMFC_testDoc::OnCanny()
{
// TODO: Add your command handler code here
cvCanny(m_image,m_image,50,150,3);
UpdateAllViews(NULL);
}
没有评论:
发表评论