CvvImage在高级别的Opencv2.4.11下的配置以及错误解决办法。

由于高版本的OpenCV2.4.11里取消了CImage(CvvImage),在此我们可以用老的版本替代。

在需要的地方引入 #include "CvvImage.h" 就可以用了。

需要将CvvIamge.h和CvvImage.cpp重新加入进来

 1 #pragma once
 2 // CvvImage.h
 3 #ifndef CVVIMAGE_CLASS_DEF
 4 #define CVVIMAGE_CLASS_DEF
 5
 6 #include "opencv.hpp"
 7
 8 class  CvvImage{
 9 public:
10     CvvImage();
11     virtual ~CvvImage();
12
13     virtual bool  Create( int width, int height, int bits_per_pixel, int image_origin = 0 );
14
15     virtual bool  Load( const char* filename, int desired_color = 1 );
16
17     virtual bool  LoadRect( const char* filename,
18         int desired_color, CvRect r );
19
20 #if defined WIN32 || defined _WIN32
21     virtual bool  LoadRect( const char* filename,
22         int desired_color, RECT r )
23     {
24         return LoadRect( filename, desired_color,
25             cvRect( r.left, r.top, r.right - r.left, r.bottom - r.top ));
26     }
27 #endif
28
29     virtual bool  Save( const char* filename );
30
31     virtual void  CopyOf( CvvImage& image, int desired_color = -1 );
32     virtual void  CopyOf( IplImage* img, int desired_color = -1 );
33
34     IplImage* GetImage() { return m_img; };
35     virtual void  Destroy(void);
36
37     int Width() { return !m_img ? 0 : !m_img->roi ? m_img->width : m_img->roi->width; };
38     int Height() { return !m_img ? 0 : !m_img->roi ? m_img->height : m_img->roi->height;};
39     int Bpp() { return m_img ? (m_img->depth & 255)*m_img->nChannels : 0; };
40
41     virtual void  Fill( int color );
42
43     virtual void  Show( const char* window );
44
45 #if defined WIN32 || defined _WIN32
46     virtual void  Show( HDC dc, int x, int y, int width, int height, int from_x = 0, int from_y = 0 );
47     virtual void  DrawToHDC( HDC hDCDst, RECT* pDstRect );
48 #endif
49
50 protected:
51
52     IplImage*  m_img;
53 };
54
55 //typedef CvvImage CImage;
56 namespace cv
57 {
58     typedef CvvImage CImage;
59 }
60
61 #endif
  1 //CvvImage.cpp
  2
  3 #include "StdAfx.h"
  4 #include "CvvImage.h"
  5
  6 // Construction/Destruction
  7
  8 CV_INLINE RECT NormalizeRect( RECT r );
  9 CV_INLINE RECT NormalizeRect( RECT r ) {
 10     int t;
 11
 12     if( r.left > r.right ){
 13         t = r.left;
 14         r.left = r.right;
 15         r.right = t;
 16     }
 17
 18     if( r.top > r.bottom ) {
 19         t = r.top;
 20         r.top = r.bottom;
 21         r.bottom = t;
 22     }
 23
 24     return r;
 25 }
 26
 27 CV_INLINE CvRect RectToCvRect( RECT sr );
 28 CV_INLINE CvRect RectToCvRect( RECT sr ) {
 29     sr = NormalizeRect( sr );
 30     return cvRect( sr.left, sr.top, sr.right - sr.left, sr.bottom - sr.top );
 31 }
 32
 33 CV_INLINE RECT CvRectToRect( CvRect sr );
 34 CV_INLINE RECT CvRectToRect( CvRect sr ) {
 35     RECT dr;
 36     dr.left = sr.x;
 37     dr.top = sr.y;
 38     dr.right = sr.x + sr.width;
 39     dr.bottom = sr.y + sr.height;
 40
 41     return dr;
 42 }
 43
 44 CV_INLINE IplROI RectToROI( RECT r );
 45 CV_INLINE IplROI RectToROI( RECT r ) {
 46     IplROI roi;
 47     r = NormalizeRect( r );
 48     roi.xOffset = r.left;
 49     roi.yOffset = r.top;
 50     roi.width = r.right - r.left;
 51     roi.height = r.bottom - r.top;
 52     roi.coi = 0;
 53
 54     return roi;
 55 }
 56
 57 void  FillBitmapInfo( BITMAPINFO* bmi, int width, int height, int bpp, int origin ) {
 58     assert( bmi && width >= 0 && height >= 0 && (bpp == 8 || bpp == 24 || bpp == 32));
 59
 60     BITMAPINFOHEADER* bmih = &(bmi->bmiHeader);
 61
 62     memset( bmih, 0, sizeof(*bmih));
 63     bmih->biSize = sizeof(BITMAPINFOHEADER);
 64     bmih->biWidth = width;
 65     bmih->biHeight = origin ? abs(height) : -abs(height);
 66     bmih->biPlanes = 1;
 67     bmih->biBitCount = (unsigned short)bpp;
 68     bmih->biCompression = BI_RGB;
 69
 70     if( bpp == 8 ) {
 71         RGBQUAD* palette = bmi->bmiColors;
 72         int i;
 73         for( i = 0; i < 256; i++ ) {
 74             palette[i].rgbBlue = palette[i].rgbGreen = palette[i].rgbRed = (BYTE)i;
 75             palette[i].rgbReserved = 0;
 76         }
 77     }
 78 }
 79
 80 CvvImage::CvvImage() { m_img = 0; }
 81
 82 void CvvImage::Destroy() { cvReleaseImage( &m_img ); }
 83
 84 CvvImage::~CvvImage() {  Destroy(); }
 85
 86 bool  CvvImage::Create( int w, int h, int bpp, int origin ) {
 87     const unsigned max_img_size = 10000;
 88
 89     if( (bpp != 8 && bpp != 24 && bpp != 32) || (unsigned)w >=  max_img_size || (unsigned)h >= max_img_size ||
 90         (origin != IPL_ORIGIN_TL && origin != IPL_ORIGIN_BL)) {
 91             assert(0); // most probably, it is a programming error
 92             return false;
 93     }
 94
 95     if( !m_img || Bpp() != bpp || m_img->width != w || m_img->height != h ) {
 96         if( m_img && m_img->nSize == sizeof(IplImage))
 97             Destroy();
 98
 99         m_img = cvCreateImage( cvSize( w, h ), IPL_DEPTH_8U, bpp/8 );
100     }
101
102     if( m_img )
103         m_img->origin = origin == 0 ? IPL_ORIGIN_TL : IPL_ORIGIN_BL;
104
105     return m_img != 0;
106 }
107
108 void  CvvImage::CopyOf( CvvImage& image, int desired_color ) {
109     IplImage* img = image.GetImage();
110     if( img )  {
111         CopyOf( img, desired_color );
112     }
113 }
114
115 #define HG_IS_IMAGE(img)                                                  116     ((img) != 0 && ((const IplImage*)(img))->nSize == sizeof(IplImage) && 117     ((IplImage*)img)->imageData != 0)
118
119 void  CvvImage::CopyOf( IplImage* img, int desired_color ){
120     if( HG_IS_IMAGE(img) )   {
121         int color = desired_color;
122         CvSize size = cvGetSize( img );
123
124         if( color < 0 )
125             color = img->nChannels > 1;
126
127         if( Create( size.width, size.height, (!color ? 1 : img->nChannels > 1 ? img->nChannels : 3)*8,  img->origin )) {
128             cvConvertImage( img, m_img, 0 );
129         }
130     }
131 }
132
133 bool  CvvImage::Load( const char* filename, int desired_color ){
134     IplImage* img = cvLoadImage( filename, desired_color );
135     if( !img )  return false;
136
137     CopyOf( img, desired_color );
138     cvReleaseImage( &img );
139
140     return true;
141 }
142
143 bool  CvvImage::LoadRect( const char* filename, int desired_color, CvRect r ){
144     if( r.width < 0 || r.height < 0 ) return false;
145
146     IplImage* img = cvLoadImage( filename, desired_color );
147     if( !img )      return false;
148
149     if( r.width == 0 || r.height == 0 )   {
150         r.width = img->width;
151         r.height = img->height;
152         r.x = r.y = 0;
153     }
154
155     if( r.x > img->width || r.y > img->height ||  r.x + r.width < 0 || r.y + r.height < 0 )   {
156         cvReleaseImage( &img );
157         return false;
158     }
159
160     if( r.x < 0 )   {
161         r.width += r.x;
162         r.x = 0;
163     }
164     if( r.y < 0 )   {
165         r.height += r.y;
166         r.y = 0;
167     }
168
169     if( r.x + r.width > img->width )     r.width = img->width - r.x;
170
171     if( r.y + r.height > img->height )      r.height = img->height - r.y;
172
173     cvSetImageROI( img, r );
174     CopyOf( img, desired_color );
175
176     cvReleaseImage( &img );
177     return true;
178 }
179
180 bool  CvvImage::Save( const char* filename ){
181     if( !m_img )      return false;
182     cvSaveImage( filename, m_img );
183     return true;
184 }
185
186 void  CvvImage::Show( const char* window ){
187     if( m_img )      cvShowImage( window, m_img );
188 }
189
190
191 void  CvvImage::Show( HDC dc, int x, int y, int w, int h, int from_x, int from_y ){
192     if( m_img && m_img->depth == IPL_DEPTH_8U )   {
193         uchar buffer[sizeof(BITMAPINFOHEADER) + 1024];
194         BITMAPINFO* bmi = (BITMAPINFO*)buffer;
195         int bmp_w = m_img->width, bmp_h = m_img->height;
196
197         FillBitmapInfo( bmi, bmp_w, bmp_h, Bpp(), m_img->origin );
198
199         from_x = MIN( MAX( from_x, 0 ), bmp_w - 1 );
200         from_y = MIN( MAX( from_y, 0 ), bmp_h - 1 );
201
202         int sw = MAX( MIN( bmp_w - from_x, w ), 0 );
203         int sh = MAX( MIN( bmp_h - from_y, h ), 0 );
204
205         SetDIBitsToDevice(
206             dc, x, y, sw, sh, from_x, from_y, from_y, sh,
207             m_img->imageData + from_y*m_img->widthStep,
208             bmi, DIB_RGB_COLORS );
209     }
210 }
211
212 void  CvvImage::DrawToHDC( HDC hDCDst, RECT* pDstRect ){
213     if( pDstRect && m_img && m_img->depth == IPL_DEPTH_8U && m_img->imageData )   {
214         uchar buffer[sizeof(BITMAPINFOHEADER) + 1024];
215         BITMAPINFO* bmi = (BITMAPINFO*)buffer;
216         int bmp_w = m_img->width, bmp_h = m_img->height;
217
218         CvRect roi = cvGetImageROI( m_img );
219         CvRect dst = RectToCvRect( *pDstRect );
220
221         if( roi.width == dst.width && roi.height == dst.height )     {
222             Show( hDCDst, dst.x, dst.y, dst.width, dst.height, roi.x, roi.y );
223             return;
224         }
225
226         if( roi.width > dst.width )     {
227             SetStretchBltMode( hDCDst,   HALFTONE );  // handle to device context
228
229         }
230         else     {
231             SetStretchBltMode(hDCDst,  COLORONCOLOR );
232         }
233
234         FillBitmapInfo( bmi, bmp_w, bmp_h, Bpp(), m_img->origin );
235
236         ::StretchDIBits(
237             hDCDst,
238             dst.x, dst.y, dst.width, dst.height,
239             roi.x, roi.y, roi.width, roi.height,
240             m_img->imageData, bmi, DIB_RGB_COLORS, SRCCOPY );
241     }
242 }
243
244 void  CvvImage::Fill( int color ){
245     cvSet( m_img, cvScalar(color&255,(color>>8)&255,(color>>16)&255,(color>>24)&255) );
246 }
时间: 2024-07-29 23:57:35

CvvImage在高级别的Opencv2.4.11下的配置以及错误解决办法。的相关文章

x64 release模式下mysql编译连接错误解决办法

系统:win8 64位 MySQL 5.7 32 原来项目是debug 32位编译的 后来改成release 64位  结果编译没错 连接时候错误  无法解决 的外部符号之类的 解决办法: 1  下载x64位的dll ,lib文件 下载链接:点击打开链接 2  将libmysql64.lib以及libmysql64.dll拷贝到数据库安装目录下面,也就是原来libmysql.lib同级目录下面 3 我的程序里面lib是这样导进去的.所以我在这里改成了libmysql64.lib #pragma

Windows 下mysqldump备份1045错误解决办法

一.我写的备份脚本如下 set d=%date:~0,4%%date:~5,2%%date:~8,2% C:\mysqldump -uroot [email protected] --all-databases > D:\backup\db_test\db_test_%d%.sql 二.报错如下 mysqldump: Got error: 1045: Access denied for user 'root'@'localhost' (using password: YES) when tryi

原创:mysql5 还原至mysql 8.0.11数据库链接配置提示错误改动备注

原创:mysql5 还原至mysql 8.0.11数据库链接配置提示错误改有三: a) mysql 连接jar包版修改 b)类路径修改 c)配置连接池地址修改 因版本升级,首先要修改 1:mysql-connector-java 架包版本修改 <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> !--原版本 5.1.6-->

Error 56: The Cisco Systems, Inc. VPN Service has not been started(Cisco VPN在Vista下出现Error 56的解决办法)

Error 56: The Cisco Systems, Inc. VPN Service has not been started(Cisco VPN在Vista下出现Error 56的解决办法) 似乎,自从我的Vista自动升级安装了SP1后,我的Cisco VPN就出现问题了,根本就无法运行.总是提示Error 56: The Cisco Systems, Inc. VPN Service has not been started. Please start this service an

Linux 下WordPress FTP帐号解决办法

自己用Ubuntu搭建WordPress后在更换主题时提示需要输入FTP帐号和密码,解决办法主要是把WordPress主目录的权限所有者弄为Apache: 找到apache服务所使用的用户名和用户组 ps -aux 找到 /usr/sbin/apach 的用户名,它就是apache的所有者,我这里是 www-data sudo chown www-data:www-data -R /var/www/html/ 因为我的WordPress的主目录是 /var/www/html/ 然后刷新WordP

FreeBSD 下sac101.6a编译失败解决办法

由于FreeBSD和Linux下C的定义有些不同,可下载下面补丁修复编译问题. http://www.iris.washington.edu/pipermail/sac-help/attachments/20130910/7f30ed61/attachment.obj FreeBSD 下sac101.6a编译失败解决办法,布布扣,bubuko.com

Ubuntu下su:authentication failure的解决办法

$ su - rootPassword: su: Authentication failureSorry. 这时候输入 $ sudo passwd rootEnter new UNIX password: Retype new UNIX password: passwd: password updated successfully 这时候就可以进入根目录了. Ubuntu下su:authentication failure的解决办法,布布扣,bubuko.com

linux下遇见mysql启动报2002错误解决办法

前言:目前问题解决了,但是仍不知道是什么原因造成的,在出现问题前安装uWSGI后,mysql就出现这个问题的,哪位大侠说说这是怎么回事? 正文:Linux 下 Mysql error 2002 错误解决 先查看 /etc/rc.d/init.d/mysqld status 查看mysql是否已经启动. 若mysql未启动,etc/init.d/mysqld start启动mysql 启动失败,八成是/etc/my.comf文件配置问题,然后mv /etc/my.cnf /tmp/my.cnf,再

Vmware虚拟机下不能访问网络的解决办法之一

Vmware虚拟机下不能访问网络的解决办法之一 1.这个是默认的网络设置 2.如果不能访问网络,看下VMware相关的服务有没有打开,win+R 3.找到VMware的相关选项,全部启用(当然网络可能只是依赖NAT Service或其他的服务) 4.打开虚拟机,看是否能够联网.