/MycvProject/MycvProjectDoc.cpp
https://bitbucket.org/skyline75489/mycvproject · C++ · 186 lines · 120 code · 42 blank · 24 comment · 11 complexity · 3a0068caedd9582ca763cd6e9fab5625 MD5 · raw file
- // MycvProjectDoc.cpp : CMycvProjectDoc ÀàµÄʵÏÖ
- //
- #include "stdafx.h"
- // SHARED_HANDLERS ¿ÉÒÔÔÚʵÏÖÔ¤ÀÀ¡¢ËõÂÔͼºÍËÑË÷ɸѡÆ÷¾ä±úµÄ
- // ATL ÏîÄ¿ÖнøÐж¨Ò壬²¢ÔÊÐíÓë¸ÃÏîÄ¿¹²ÏíÎĵµ´úÂë¡£
- #ifndef SHARED_HANDLERS
- #include "MycvProject.h"
- #endif
- #include "MycvProjectDoc.h"
- #include <propkey.h>
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #endif
- // CMycvProjectDoc
- IMPLEMENT_DYNCREATE(CMycvProjectDoc, CDocument)
- BEGIN_MESSAGE_MAP(CMycvProjectDoc, CDocument)
- END_MESSAGE_MAP()
- // CMycvProjectDoc ¹¹Ôì/Îö¹¹
- CMycvProjectDoc::CMycvProjectDoc()
- {
- // TODO: ÔÚ´ËÌí¼ÓÒ»´ÎÐÔ¹¹Ôì´úÂë
- pImg=NULL;
- m_Display=-1;
- }
- CMycvProjectDoc::~CMycvProjectDoc()
- {
- if (pImg)
- cvReleaseImage(&pImg);
- }
- BOOL CMycvProjectDoc::OnNewDocument()
- {
- if (!CDocument::OnNewDocument())
- return FALSE;
- // TODO: ÔÚ´ËÌí¼ÓÖØÐ³õʼ»¯´úÂë
- // (SDI Îĵµ½«ÖØÓøÃÎĵµ)
- return TRUE;
- }
- // CMycvProjectDoc ÐòÁл¯
- void CMycvProjectDoc::Serialize(CArchive& ar)
- {
- if (ar.IsStoring())
- {
- // TODO: ÔÚ´ËÌí¼Ó´æ´¢´úÂë
- }
- else
- {
- // TODO: ÔÚ´ËÌí¼Ó¼ÓÔØ´úÂë
- }
- }
- #ifdef SHARED_HANDLERS
- // ËõÂÔͼµÄÖ§³Ö
- void CMycvProjectDoc::OnDrawThumbnail(CDC& dc, LPRECT lprcBounds)
- {
- // Ð޸Ĵ˴úÂëÒÔ»æÖÆÎĵµÊý¾Ý
- dc.FillSolidRect(lprcBounds, RGB(255, 255, 255));
- CString strText = _T("TODO: implement thumbnail drawing here");
- LOGFONT lf;
- CFont* pDefaultGUIFont = CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI_FONT));
- pDefaultGUIFont->GetLogFont(&lf);
- lf.lfHeight = 36;
- CFont fontDraw;
- fontDraw.CreateFontIndirect(&lf);
- CFont* pOldFont = dc.SelectObject(&fontDraw);
- dc.DrawText(strText, lprcBounds, DT_CENTER | DT_WORDBREAK);
- dc.SelectObject(pOldFont);
- }
- // ËÑË÷´¦Àí³ÌÐòµÄÖ§³Ö
- void CMycvProjectDoc::InitializeSearchContent()
- {
- CString strSearchContent;
- // ´ÓÎĵµÊý¾ÝÉèÖÃËÑË÷ÄÚÈÝ¡£
- // ÄÚÈݲ¿·ÖÓ¦ÓÉ¡°;¡±·Ö¸ô
- // ÀýÈç: strSearchContent = _T("point;rectangle;circle;ole object;")£»
- SetSearchContent(strSearchContent);
- }
- void CMycvProjectDoc::SetSearchContent(const CString& value)
- {
- if (value.IsEmpty())
- {
- RemoveChunk(PKEY_Search_Contents.fmtid, PKEY_Search_Contents.pid);
- }
- else
- {
- CMFCFilterChunkValueImpl *pChunk = NULL;
- ATLTRY(pChunk = new CMFCFilterChunkValueImpl);
- if (pChunk != NULL)
- {
- pChunk->SetTextValue(PKEY_Search_Contents, value, CHUNK_TEXT);
- SetChunkValue(pChunk);
- }
- }
- }
- #endif // SHARED_HANDLERS
- // CMycvProjectDoc Õï¶Ï
- #ifdef _DEBUG
- void CMycvProjectDoc::AssertValid() const
- {
- CDocument::AssertValid();
- }
- void CMycvProjectDoc::Dump(CDumpContext& dc) const
- {
- CDocument::Dump(dc);
- }
- #endif //_DEBUG
- // CMycvProjectDoc ÃüÁî
- BOOL CMycvProjectDoc::OnOpenDocument(LPCTSTR lpszPathName)
- {
- if (!CDocument::OnOpenDocument(lpszPathName))
- return FALSE;
-
- // TODO: Add your specialized creation code here
- BOOL boolean;
- Load(&pImg,lpszPathName);
- if (pImg!=NULL)
- boolean=true;
- else
- boolean=false;
- return(boolean);
- }
- //---------------------------------------------------------
- //---------------------------------------------------------
- // ImageIO
-
- BOOL CMycvProjectDoc::Load(IplImage** pp,LPCTSTR csFileName)
- {
- IplImage* pImg=NULL;
- pImg = cvLoadImage(csFileName,-1); // ¶ÁͼÏñÎļþ(DSCV)
- if (!pImg){
- AfxMessageBox("´ò¿ªÍ¼Ïñʧ°Ü£¬Çë¼ì²éͼÏñ¸ñʽºÍ·¾¶ÊÇ·ñÕýÈ·");
- return(false);
- }
- cvFlip(pImg); // Óë DIB ÏñËØ½á¹¹Ò»ÖÂ
- if (*pp) {
- cvReleaseImage(pp);
- }
- (*pp)=pImg;
- m_Display=0;
- return(true);
- }
- BOOL CMycvProjectDoc::Save(LPCTSTR csFileName,IplImage* pImg)
- {
- int bl;
- cvFlip(pImg); // »Ö¸´Ô OpenCV λͼ½á¹¹
- bl=cvSaveImage(csFileName,pImg); // ͼÏñ´æÅÌ
- return(bl);
- }