前几日,OpenCV 2.2.0版本出现了...但是...以前版本的CvvImage类不见了...为了能够继续使用这个类,下面把这个类的源代码贴出来,使用的时候将该代码加入到工程中便可以使用了。为了方便切换OpenCV的版本,这里用到了一些条件编译宏,来保证代码的灵活性。
不过OpenCV 2.2.0取消CvvImage这个类,一定是有它的原因的,具体可以在做实验的时候体会这些原因。
CvvImage头文件
- #ifndef CVVIMAGE_CLASS_DEF
- #define CVVIMAGE_CLASS_DEF
- #include <cv.h>
- #include <highgui.h>
- /* CvvImage class definition */
- class CvvImage
- {
- public:
- CvvImage();
- virtual ~CvvImage();
- /* 创建图像(BGR或灰度) */
- virtual bool Create( int width, int height, int bits_per_pixel, int image_origin = 0 );
- /* 从指定的文件加载图像 */
- virtual bool Load( const char* filename, int desired_color = 1 );
- /* 从文件加载矩形 */
- 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
- /* 将整个图像保存到指定的文件. */
- virtual bool Save( const char* filename );
- /* 获取输入图像ROI的副本*/
- virtual void CopyOf( CvvImage& image, int desired_color = -1 );
- virtual void CopyOf( IplImage* img, int desired_color = -1 );
- IplImage* GetImage() { return m_img; };
- virtual void Destroy(void);
- /* 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 & 255)*m_img->nChannels : 0; };
- virtual void Fill( int color );
- /* 画到高贵窗口 */
- virtual void Show( const char* window );
- #if defined WIN32 || defined _WIN32
- /* 将图像的一部分绘制到指定的DC */
- virtual void Show( HDC dc, int x, int y, int width, int height,
- int from_x = 0, int from_y = 0 );
- /* 将当前图像ROI绘制到目标DC的指定矩形 */
- virtual void DrawToHDC( HDC hDCDst, RECT* pDstRect );
- #endif
- protected:
- IplImage* m_img;
- };
- typedef CvvImage CImage;
- #endif
除特别注明外,本站所有文章均为 赢咖4注册 原创,转载请注明出处来自OpenCV 2.2.0 CvvImage的使用