目前OpenCV版本已更新到2.4...由此出现了一系列问题,解决如下:

1、cxcore.h等头文件找不到:

法一、将opencv1.0中的各种.h或者.lib文件拷到opencv2.3.1对应include/library的路径的文件夹下。

e.g.   Cannot open include file: 'cxtypes.h': No such file or directory

像这种情况,在opencv1.0中又搜索不到的,果断把#include"cxtypes.h"删掉,其他问题慢慢解决。

2、CvFilter未定义:

opencv高级版本不在含有CvFilter,那么就把类型改成int吧……

3、CvvImage类找不到定义……

高级版本中,以前版本的CvvImage类不见了...为了能够继续使用这个类,下面把这个类的源代码贴出来,使用的时候将该代码加入到工程中便可以使用了。为了方便切换OpenCV的版本,这里用到了一些条件编译宏,来保证代码的灵活性。

不过OpenCV 2.2.0取消CvvImage这个类,一定是有它的原因的,具体可以在做实验的时候体会这些原因。

========================================================================

CvvImage头文件

  1. #ifndef CVVIMAGE_CLASS_DEF
  2. #define CVVIMAGE_CLASS_DEF
  3. #ifndef RC_OPENCV_2_1_0
  4. #include <opencv/cv.h>
  5. #include <opencv/highgui.h>
  6. /* CvvImage class definition */
  7. class  CvvImage
  8. {
  9. public:
  10. CvvImage();
  11. virtual ~CvvImage();
  12. /* Create image (BGR or grayscale) */
  13. virtual bool  Create( int width, int height, int bits_per_pixel, int image_origin = 0 );
  14. /* Load image from specified file */
  15. virtual bool  Load( const char* filename, int desired_color = 1 );
  16. /* Load rectangle from the file */
  17. virtual bool  LoadRect( const char* filename,
  18. int desired_color, CvRect r );
  19. #if defined WIN32 || defined _WIN32
  20. virtual bool  LoadRect( const char* filename,
  21. int desired_color, RECT r )
  22. {
  23. return LoadRect( filename, desired_color,
  24. cvRect( r.left, r.top, r.right - r.left, r.bottom - r.top ));
  25. }
  26. #endif
  27. /* Save entire image to specified file. */
  28. virtual bool  Save( const char* filename );
  29. /* Get copy of input image ROI */
  30. virtual void  CopyOf( CvvImage& image, int desired_color = -1 );
  31. virtual void  CopyOf( IplImage* img, int desired_color = -1 );
  32. IplImage* GetImage() { return m_img; };
  33. virtual void  Destroy(void);
  34. /* width and height of ROI */
  35. int Width() { return !m_img ? 0 : !m_img->roi ? m_img->width : m_img->roi->width; };
  36. int Height() { return !m_img ? 0 : !m_img->roi ? m_img->height : m_img->roi->height;};
  37. int Bpp() { return m_img ? (m_img->depth & 255)*m_img->nChannels : 0; };
  38. virtual void  Fill( int color );
  39. /* draw to highgui window */
  40. virtual void  Show( const char* window );
  41. #if defined WIN32 || defined _WIN32
  42. /* draw part of image to the specified DC */
  43. virtual void  Show( HDC dc, int x, int y, int width, int height,
  44. int from_x = 0, int from_y = 0 );
  45. /* draw the current image ROI to the specified rectangle of the destination DC */
  46. virtual void  DrawToHDC( HDC hDCDst, RECT* pDstRect );
  47. #endif
  48. protected:
  49. IplImage*  m_img;
  50. };
  51. typedef CvvImage CImage;
  52. #endif
  53. #endif

CvvImage源文件

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

解决Opencv高低版本不兼容问题的更多相关文章

  1. 解决 android 高低版本 webView 里内容 自适应屏幕的终极方法

    转载请声明出处(http://www.cnblogs.com/linguanh/) 一,先说下我的情况,大家可以对号入座(嫌无聊请跳过) 我的项目要求是这样的,先从数据库里面拿出来html标签,因为加 ...

  2. 【我的Android进阶之旅】解决 Error:CreateProcess error=216, 该版本的 %1 与您运行的 Windows 版本不兼容。请查看计算机的系统信息,了解是否需要 x86

    一.错误描述 刚刚打开Android Studio新建一个项目,然后就编译不了,报了如下所示的错误: 错误描述为: Error:CreateProcess error=216, 该版本的 %1 与您运 ...

  3. 解决Mybatis-plus高版本不向后兼容的问题

    mybatis-plus插件后面的版本没有兼容低版本.即:不存在低版本中EntityWrapper这个类了.而该类采用数据库表真实字段名作查询条件,这样硬编码形式确实不友好,比如如果后面数据库表中字段 ...

  4. 解决selenium和FireFox版本不兼容问题

    相信很多同学刚接触selenium时,在Eclipse中打开fireFox浏览器时会报错:org.openqa.selenium.firefox.NotConnectedException: Unab ...

  5. OpenCV各版本差异与演化,从1.x到4.0

    博客:blog.shinelee.me | 博客园 | CSDN 写在前面 最近因项目需要,得把OpenCV捡起来,登录OpenCV官网,竟然发现release了4.0.0-beata版本,所以借此机 ...

  6. Selenium2学习-007-WebUI自动化实战实例-005-解决 Firefox 版本不兼容:org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary

    此文主要讲述 Java 运行 Selenium 脚本时,因 Friefox 浏览器版本与 selenium-server-standalone-x.xx.x.jar 不兼容引起的 org.openqa ...

  7. 怎么用一行代码解决CSS各种IE各种兼容问题

    用一行代码来解决CSS在,IE6,IE7,IE8,IE9,IE10 中的各种兼容性问题. 在网站前端写代码的过程中,很多时间IE各个版本的兼容问题很难整.现在百度与谷歌都有了一行解决这种兼容性的代码了 ...

  8. ubuntu下python安装pandas和numpy等依赖库版本不兼容的问题RuntimeWarning: numpy.dtype size changed

    习惯了linux下用pip install numpy及pip install pandas命令了.折腾了好久了. 上来先在python3中pip3 install numpy装了numpy,然后再p ...

  9. angularjs1+requirejs+ bootstrap+ jQuery低版本配合兼容ie8+浏览器

    angularjs兼容低版本IE浏览器(IE8)angularjs在1.3之后的版本都是选择放弃对IE8及更低IE版本的支持,但是就目前的开发形式来看,IE8的使用客户还是蛮多的,最近有个项目要求尽量 ...

随机推荐

  1. 玩转NumPy数组

    一.Numpy 数值类型 1.前言:Python 本身支持的数值类型有 int(整型, long 长整型).float(浮点型).bool(布尔型) 和 complex(复数型).而 Numpy 支持 ...

  2. springMVC中使用 RequestBody 及 Ajax POST请求 415 (Unsupported Media Type)

    使用POST请求的时候一直报错: Ajax 未设置 contentType 时会报 415 . 后台 RequestBody  承接前台参数,故对参数data的要求为“必传”“JSON”,否则会报40 ...

  3. vue框架(一)

    一.介绍 1.Vue是什么? Vue.js (读音 /vjuː/,类似于 view) 是一套构建用户界面的渐进式框架.与其他重量级框架不同的是,Vue 采用自底向上增量开发的设计.Vue 的核心库只关 ...

  4. 导入Frameworks 死活引用不Liao头文件

    向工程中拖入或add file时可能会出现Frameworks导入,但是在添加该Frameworks后却引用不到相应的头文件 打开工程文件目录发现frameworks所在的路径并不存在,而是直接在工程 ...

  5. 'substring(from:)' is deprecated: Please use String slicing subscript with a 'partial range from' operator.

    let newStr = String(str[..<index]) // = str.substring(to: index) In Swift 3 let newStr = String(s ...

  6. uCOS-II的学习笔记(共九期)和例子(共六个)

    源:uCOS-II的学习笔记(共九期)和例子(共六个) 第一篇 :学习UCOS前的准备工作http://blog.sina.com.cn/s/blog_98ee3a930100w0eu.html 第二 ...

  7. Django框架之HTTP本质

    1.Http请求本质 浏览器(socket客户端): socket.connect(ip,端口) socket.send("http://www.xiaohuar.com/index.htm ...

  8. @MarkFan 口语练习录音 20140401

    Hi,everybody 对于未来,我只梦想最好的情况, 并定下最踏实的计划,而绝不花时间在无谓的担心上, 因为我知道,只要把我对自己的承诺付诸实践, 我的未来将不会只是一个梦…… 这是引用考拉小巫的 ...

  9. 20165101 实验一 Java开发环境的熟悉

    #20165103 实验一 Java开发环境的熟悉 实验报告 封面 实验要求 第一部分 1.建立"自己学号exp1"的目录 2.在"自己学号exp1"目录下建立 ...

  10. Python的return self和return一个新的对象区别

    目的:设计一个有理数相加.如3/5 + 7/15 = 80/75 return self 输入: class Rational0: def __init__(self, num, den=1): se ...