WinCv
Who needs this?
Any OpenCV user who wants to display images conviniently
in MS Windows.
Downloads
WinCv.h, WinCv.cpp.
Usage/Comment
Include these files to your project.
When you use MFC, add the following line at
the very
first line of "WinCv.cpp":
#include "stdafx.h"
Use it as instructed in "WinCv.h"
Example (MFC with document support)
===== MyExampleDoc.h =====
... #include <cv.h> #include <highgui.h> #include <WinCv.h> ... class CMyExampleDoc : public CDocument { ... public: void DisplayFrame();
protected: CvCapture *m_pCapture; WinCv m_WinCv; bool m_InitView; IplImage *m_pCurrentImage; void DisplayImage(IplImage *pImage); ... }
===== MyExampleDoc.cpp =====
#include <cv.h> #include <highgui.h> #include "WinCv.h"
...
CMyExampleDoc::CMyExampleDoc() { ... m_pCurrentImage = NULL; m_InitView = false; }
BOOL CMyExampleDoc::OnOpenDocument(LPCTSTR lpszPathName) { m_pCapture = cvCreateFileCapture(lpszPathName); if (!m_pCapture) return FALSE; IplImage *p_image = cvQueryFrame(m_pCapture); if (!p_image) return FALSE;
m_InitView = false; DisplayImage(p_image); }
// Public member. Called by View->OnDraw (see below) void CMyExampleDoc::DisplayFrame() { if (!m_InitView) { POSITION posV = GetFirstViewPosition(); CMyExampleView *view = (CMyExampleView *) GetNextView(posV); m_WinCv.InitializeWindow(view->m_hWnd, view->GetParentFrame()->m_hWnd); m_WinCv.InitializeImage(ppCurrentImage); m_InitView = true; }
m_WinCv.DisplayImage(m_pCurrentImage); }
// Private member. Call this whenever you want to update the image. void CMyExampleDoc::DisplayImage(IplImage *pImage) { if (m_pCurrentImage) cvReleaseImage(&m_pCurrentImage); m_pCurrentImage = cvCloneImage(pImage); m_WinCv.DisplayImage(m_pCurrentImage); }
===== MyExampleView.cpp =====
...
void CMyExampleView::OnDraw(CDC* pDC) { CVideoConverterDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc);
pDoc->DisplayFrame(); }
...
Q&A : How about MFC with Dialog or an
additional view?
My first recommendation is to use Highgui for an
additional view.. why not??
You can also use an inherited class of CView. The above
example should be helpful in this case...
Update History
2008-06-02: fixed a memory leak bug
2007-09-08: fixed a framewindow size bug in
the example
2007-06-20: release the very first version
Legal Comments
Sorry but I'm not responsible for any problems that may
be caused by these downloads.
My other OpenCV work
Using
QuickTime
SDK for OpenCV in Windows (to read MPEG files)
Zu
Kim, 2007.6.20.
|