




已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
好多 opencv 的应用程序界面中在 MFC 中显示图像,但是我发现这些显示功能大部分用到 了一个叫 CvvImage 的类,最近使用 opencv2.3.1,发现找不到这个类了。 没有具体研究过 opencv ,但是 opencv 在 MFC 中显示图像需要用的一个叫做 CvvImage 的类 的 DrawToHDC()的函数,但是我在 2.3.1 下却怎么也没有找到这个类,和这个函数。在 2.3.1 的文档下没有关于这个的任何资料,不知道是不是新版本的 opencv 去掉了这个类, 或者用其他的方式实现了。所以我需要用以前的方式实现这个类。在网上找了一些资料。 发现这个问题可以这样处理。 我们可以自己建立一个 CvvImage.h 和一个 CvvImage.cpp 的文件,添加到工程中。这样我们 在工程中包含上这个 CvvImage.h 的头文件,就可以正常的按照以前的方式使用 CvvImage 类将图像绘制到 MFC 控件中了。 一下给出这两个文件的源码。 CvvImage.h cpp view plaincopy #pragma once #ifndef CVVIMAGE_CLASS_DEF #define CVVIMAGE_CLASS_DEF #include “opencv.hpp“ /* CvvImage class definition */ class CvvImage public: CvvImage(); virtual CvvImage(); /* Create image (BGR or grayscale) */ virtual bool Create( int width, int height, int bits_per_pixel, int image_origin = 0 ); /* Load image from specified file */ virtual bool Load( const char* filename, int desired_color = 1 ); /* Load rectangle from the file */ virtual bool LoadRect( const char* filename, int desired_color, CvRect r ); #if defined WIN32 | defined _WIN32 virtual bool LoadRect( const char* filename, int desired_color, RECT r ) return LoadRect( filename, desired_color, cvRect( r.left, r.top, r.right - r.left, r.bottom - r.top ); #endif /* Save entire image to specified file. */ virtual bool Save( const char* filename ); /* Get copy of input image ROI */ virtual void CopyOf( CvvImage virtual void CopyOf( IplImage* img, int desired_color = -1 ); IplImage* GetImage() return m_img; ; virtual void Destroy(void); /* width and height of ROI */ int Width() return !m_img ? 0 : !m_img-roi ? m_img-width : m_img-roi-width; ; int Height() return !m_img ? 0 : !m_img-roi ? m_img-height : m_img-roi-height; int Bpp() return m_img ? (m_img-depth ; virtual void Fill( int color ); /* draw to highgui window */ virtual void Show( const char* window ); #if defined WIN32 | defined _WIN32 /* draw part of image to the specified DC */ virtual void Show( HDC dc, int x, int y, int width, int height, int from_x = 0, int from_y = 0 ); /* draw the current image ROI to the specified rectangle of the destination DC */ virtual void DrawToHDC( HDC hDCDst, RECT* pDstRect ); #endif protected: IplImage* m_img; ; typedef CvvImage CImage; #endif CvvImage.cpp cpp view plaincopy #include “StdAfx.h“ #include “CvvImage.h“ / / Construction/Destruction / CV_INLINE RECT NormalizeRect( RECT r ); CV_INLINE RECT NormalizeRect( RECT r ) int t; if( r.left r.right ) t = r.left; r.left = r.right; r.right = t; if( r.top r.bottom ) t = r.top; r.top = r.bottom; r.bottom = t; return r; CV_INLINE CvRect RectToCvRect( RECT sr ); CV_INLINE CvRect RectToCvRect( RECT sr ) sr = NormalizeRect( sr ); return cvRect( sr.left, sr.top, sr.right - sr.left, sr.bottom - sr.top ); CV_INLINE RECT CvRectToRect( CvRect sr ); CV_INLINE RECT CvRectToRect( CvRect sr ) RECT dr; dr.left = sr.x; dr.top = sr.y; dr.right = sr.x + sr.width; dr.bottom = sr.y + sr.height; return dr; CV_INLINE IplROI RectToROI( RECT r ); CV_INLINE IplROI RectToROI( RECT r ) IplROI roi; r = NormalizeRect( r ); roi.xOffset = r.left; roi.yOffset = r.top; roi.width = r.right - r.left; roi.height = r.bottom - r.top; roi.coi = 0; return roi; void FillBitmapInfo( BITMAPINFO* bmi, int width, int height, int bpp, int origin ) assert( bmi BITMAPINFOHEADER* bmih = memset( bmih, 0, sizeof(*bmih); bmih-biSize = sizeof(BITMAPINFOHEADER); bmih-biWidth = width; bmih-biHeight = origin ? abs(height) : -abs(height); bmih-biPlanes = 1; bmih-biBitCount = (unsigned short)bpp; bmih-biCompression = BI_RGB; if( bpp = 8 ) RGBQUAD* palette = bmi-bmiColors; int i; for( i = 0; i = max_img_size | (unsigned)h = max_img_size | (origin != IPL_ORIGIN_TL / most probably, it is a programming error return false; if( !m_img | Bpp() != bpp | m_img-width != w | m_img-height != h ) if( m_img /* prepare IPL header */ m_img = cvCreateImage( cvSize( w, h ), IPL_DEPTH_8U, bpp/8 ); if( m_img ) m_img-origin = origin = 0 ? IPL_ORIGIN_TL : IPL_ORIGIN_BL; return m_img != 0; void CvvImage:CopyOf( CvvImage if( img ) CopyOf( img, desired_color ); #define HG_IS_IMAGE(img) (img) != 0 CvSize size = cvGetSize( img ); if( color nChannels 1; if( Create( size.width, size.height, (!color ? 1 : img-nChannels 1 ? img-nChannels : 3)*8, img-origin ) cvConvertImage( img, m_img, 0 ); bool CvvImage:Load( const char* filename, int desired_color ) IplImage* img = cvLoadImage( filename, desired_color ); if( !img ) return false; CopyOf( img, desired_color ); cvReleaseImage( return true; bool CvvImage:LoadRect( const char* filename, int desired_color, CvRect r ) if( r.width width; r.height = img-height; r.x = r.y = 0; if( r.x img-width | r.y img-height | r.x + r.width img-width ) r.width = img-width - r.x; if( r.y + r.height img-height ) r.height = img-height - r.y; cvSetImageROI( img, r ); CopyOf( img, desired_color ); cvReleaseImage( return true; bool CvvImage:Save( const char* filename ) if( !m_img ) return false; cvSaveImage( filename, m_img ); return true; void CvvImage:Show( const char* window ) if( m_img ) cvShowImage( window, m_img ); void CvvImage:Show( HDC dc, int x, int y, int w, int h, int from_x, int from_y ) if( m_img BITMAPINFO* bmi = (BITMAPINFO*)buffer; int bmp_w = m_img-width, bmp_h = m_img-height; FillBitmapInfo( bmi, bmp_w, bmp_h, Bpp(), m_img-origin ); from_x = MIN( MAX( from_x, 0 ), bmp_w - 1 ); from_y = MIN( MAX( from_y, 0 ), bmp_h - 1 ); int sw = MAX( MIN( bmp_w - from_x, w ), 0 ); int sh = MAX( MIN( bmp_h - from_y, h ), 0 ); SetDIBitsToDevice( dc, x, y, sw, sh, from_x, from_y, from_y, sh, m_img-imageData + from_y*m_img-widthStep, bmi, DIB_RGB_COLORS ); void CvvImage:DrawToHDC( HDC hDCDst, RECT* pDstRect ) if( pDstRect BITMA
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 宁夏大学新华学院《即兴口语传播一》2023-2024学年第一学期期末试卷
- 武汉生物工程学院《田径运动会编排操作》2023-2024学年第一学期期末试卷
- 西京学院《全科医疗中的医患关系与沟通技巧》2023-2024学年第一学期期末试卷
- 青岛远洋船员职业学院《漫画墨线绘制》2023-2024学年第一学期期末试卷
- 2024-2025学年江苏省扬大附中东部分学校九年级化学第一学期期末监测模拟试题含解析
- 公路货运行业数字化转型2025年与物流政策法规研究报告
- 公路货运行业数字化转型与绿色物流发展报告
- 雁形板在节能建筑中的应用及安装技巧
- 美容整形手术室的感染控制体系
- 长春理工大学《应用统计学B》2023-2024学年第一学期期末试卷
- 法庭科学 伪造人像 深度伪造检验
- 海上风电场海上安全保障
- 储能系统培训课程
- 体重管理咨询表
- 绿色生态养猪场环境治理项目可行性研究报告
- 贵州省黔南州贵定县2022-2023学年六年级下学期期末质量监测语文试卷
- 高校教学质量评价体系构建与实践
- 新人教版数学五年级下册全册课本练习题精编可编辑可打印
- 小学语文命题能力培训
- 龋病的治疗及预防
- 陕西电信省市公司组织架构图
评论
0/150
提交评论