Using openCV in MFC

Popular tutorials of using openCV to detect objects and showing recognised results are based on a black window with rapid command lines flushing up. As MFC has more powerful functions in interface design than pure interfaces provided by openCV, it is attractive to move openCV application from console to MFC. Here is an tutorial of introducing using openCV in MFC, check it out.
Step 1: Visual C++ wizard, choose MFC App.
Step 2: Visual C++, choose single document, to create main MFC app frame.
Step 3: Add openCV libs in project properties.
Step 4: Add variables in Doc class: add a variable m_image, include highgui.h head file in the first beginning, and the variable CImage m_image.
Step 5: Add two virtual functions to open and save image file, as shown below.
BOOL CSD|_OpenCVDoc::OnOpenDocument(LPCTSTR LpszPathName){
if(!CDocument::OnOpenDocument(LpszPathName)) return FALSE;
//TODO: Add your specifilised creation code here
m_image.load(LpszPathName);
return TRUE;
}
BOOL CSD|_OpenCVDoc::OnSaveDocument(LPCTSTR LpszPathName){
//TODO: Add your specialised code here and /or call the base class
m_image.Save(LpszPathName);
return CDocument::OnSaveDocument(LpszPathName);
}
Step 6: Add codes in View class to show the image
void CSDI_OpenCVView::OnDraw(CDC*pDC){
CSDI_OpenCVDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
//TODO:
CImage & img = pDoc->m_image;
CRect r;
GetClientRect(&r);
img.DrawToHDC(pDC->GetSafeHdc(),r);
}
Step 7: Compile the app, then an image can be open through open menu, here comes the beauty Lena.
—
Partly this post refers a document of ‘using openCV in MFC‘ by ollydbg23, any offend of copyrights please make me informed.9 Comments On “ Using openCV in MFC”
Hi! Great to see you posting again! You’ve got a lot of stuff in the other articles as well to keep me reading for some time 🙂
😉 take your time.
Valuable info. Lucky me I found your site by accident, I bookmarked it.
Pretty nice post. I just stumbled upon your blog and wanted to say that I have really enjoyed browsing your blog posts. In any case I’ll be subscribing to your feed and I hope you write again soon!
con you do it in visual studio 2008 or 2010?
This example was conducted under Visual Studio 2008
I am new one in this area using MFC and c++ .
I have to project on “tracing the motion detection.”
but i do’t understand how do i do it..
I tried to make a simple MFC project by working with video from camera.. you can download my project from this link: http://www.4shared.com/file/FXva0jxt/testLoadCam.html
but i do’t understand that how do i extract frames from video and do difference for moving objects./ .
Or is there any tutorail for MFC c++ work with c++ ./.
can any one help me please ,
Can any one Please update my project that should be base for my project. like load video from cam ,extract frames and difference between frames for moving objects. can any one help me please ,. Or provide me any MFC c++ book with open cv . or any project related to it. Please help me thanks
What a material of un-ambiguity and preserveness of valuable experience
about unexpected feelings.
I read a lot of interesting articles here. Probably you spend
a lot of time writing, i know how to save you a lot of time, there is an online
tool that creates high quality, SEO friendly articles in seconds, just search in google – laranitas free content source