110 likes | 224 Views
This documentation explores the implementation of the CvvImage class for effective digital image processing using OpenCV in a Microsoft Foundation Class (MFC) application. It covers loading images, converting color images to grayscale, and managing multiple document interfaces. The example shows how to create and manipulate images, handle file dialogs for loading images, and perform drawing operations in a view context. Created by Kim Nam Woo at Dongseo University, this guide serves as a comprehensive reference for developers working on image processing applications.
E N D
Computer Vision Kim Nam Woo
Console OpenCV CvvImage cImage; cImage.Load("1.bmp"); IplImage* color_image=cImage.GetImage(); IplImage* gray_image=cvCreateImage(cvGetSize(color_image),IPL_DEPTH_8U,1); cvCvtColor(color_image, gray_image, CV_BGR2GRAY); cImage.CopyOf(gray_image,8); int height=cImage.Height(); int width=cImage.Width(); cImage.Show(pDC->GetSafeHdc(),0,0,width,height); cvReleaseImage(&gray_image); cImage.Destroy(); pDoc->SetTitle("CvvImage Class DefaultExam"); Digital Image Processing, Kim Nam Woo, Dongseo Univ.
Member Function in CvvImage Digital Image Processing, Kim Nam Woo, Dongseo Univ.
CvvImage in MFC • Select Multiple Documents • include in “StdAfx.h” #include <cv.h> • #include <cxcore.h> • #include <highgui.h> • #include <cvcam.h> • Add Member Variables • CvvImage m_cvvImage • char* m_szPathName Digital Image Processing, Kim Nam Woo, Dongseo Univ.
CvvImage in MFC • Add Virtual Function in Doc • Doc::OnOpenDocument(LPCTSTR lpszPathName) • { • if (!CDocument::OnOpenDocument(lpszPathName)) • return FALSE; • // TODO: Add your specialized creation code here • m_cvvImage.Load(lpszPathName); • m_szPathName=(char*)calloc(512,sizeof(char)); • strcpy(m_szPathName, (char*)lpszPathName); • return TRUE; • } Digital Image Processing, Kim Nam Woo, Dongseo Univ.
CvvImage in MFC • Add Virtual Function in Doc • Doc::DeleteContents() • { • // TODO: Add your specialized code here and/or call the base class • if(m_cvvImage.GetImage()!=NULL) • { • m_cvvImage.~CvvImage(); • } • CDocument::DeleteContents(); • } Digital Image Processing, Kim Nam Woo, Dongseo Univ.
CvvImage in MFC • Add Function in App • App::OnFileOpen() • { • // TODO: Add your command handler code here • char szFilter[]="JPEG file(*.jpeg, *.jpg, *,jpe) • | *.jpeg; *.jpg;, *.jpe|\ • Portable Network Graphics file(*.png)|*.png|\ • Windows bitmap files(*.bmp, *.dib)|*.bmp; *.dib|\ • Sun rasters(*.sr, *.ras)|*.sr; *.ras|\ • TIFF files(*.tiff, *.tif)|*.tiff; *.tif|\ • 지원하는 모든 영상 파일| • *.jpeg; *.jpg; *.jpe; *.png; *.bmp; *.dib; *.sr; *.ras;\ • *.tiff; *.tif||"; • CFileDialogfileDlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT,szFilter); • intiReturn=fileDlg.DoModal(); • if(iReturn==IDOK) • { • POSITION pos=fileDlg.GetStartPosition(); • while(pos) • { • OpenDocumentFile • (fileDlg.GetNextPathName(pos)); • } • } • } Digital Image Processing, Kim Nam Woo, Dongseo Univ.
CvvImage in MFC • Add Virtual Function in View • View::OnInitialUpdate() • { • CTestDoc* pDoc = GetDocument(); • ASSERT_VALID(pDoc); • CScrollView::OnInitialUpdate(); • CSizesizeTotal; • // TODO: calculate the total size of this view • if(pDoc->m_cvvImage.GetImage()) • { • int height=pDoc->m_cvvImage.Height(); • int width=pDoc->m_cvvImage.Width(); • sizeTotal=CSize(width, height); • } • else • { • sizeTotal.cx = sizeTotal.cy = 100; • } • SetScrollSizes(MM_TEXT, sizeTotal); • ResizeParentToFit(TRUE); • } Digital Image Processing, Kim Nam Woo, Dongseo Univ.
CvvImage in MFC • Add Virtual Function in View • View::OnDraw(CDC* pDC) • { • CTestDoc* pDoc = GetDocument(); • ASSERT_VALID(pDoc); • // TODO: add draw code for native data here • if(pDoc->m_cvvImage.GetImage()) • { • int height=pDoc->m_cvvImage.Height(); • int width=pDoc->m_cvvImage.Width(); • CRect rect=CRect(0,0,width,height); • pDoc->m_cvvImage.DrawToHDC(pDC->GetSafeHdc(),&rect); • ResizeParentToFit(FALSE); • } • } Digital Image Processing, Kim Nam Woo, Dongseo Univ.
CvvImage in MFC • Add Virtual Function in View • View::OnDraw(CDC* pDC) • { • CTestDoc* pDoc = GetDocument(); • ASSERT_VALID(pDoc); • // TODO: add draw code for native data here • if(pDoc->m_cvvImage.GetImage()) • { • int height=pDoc->m_cvvImage.Height(); • int width=pDoc->m_cvvImage.Width(); • CRect rect=CRect(0,0,width,height); • pDoc->m_cvvImage.DrawToHDC(pDC->GetSafeHdc(),&rect); • ResizeParentToFit(TRUE); • } • } Digital Image Processing, Kim Nam Woo, Dongseo Univ.
CvvImage in MFC • Add Virtual Function in ViewApp • App::InitInstance() • { • : • : • if(cmdInfo.m_nShellCommand==CCommandLineInfo::FileNew) • { • cmdInfo.m_nShellCommand=CCommandLineInfo::FileNothing; • } • : • : • } Digital Image Processing, Kim Nam Woo, Dongseo Univ.