解决Opencv高低版本不兼容问题
目前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头文件
- #ifndef CVVIMAGE_CLASS_DEF
 - #define CVVIMAGE_CLASS_DEF
 - #ifndef RC_OPENCV_2_1_0
 - #include <opencv/cv.h>
 - #include <opencv/highgui.h>
 - /* 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& image, int desired_color = -1 );
 - 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 & 255)*m_img->nChannels : 0; };
 - 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
 - #endif
 
CvvImage源文件
- #include "stdafx.h"
 - #ifndef RC_OPENCV_2_1_0
 - #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 && width >= 0 && height >= 0 && (bpp == 8 || bpp == 24 || bpp == 32));
 - BITMAPINFOHEADER* bmih = &(bmi->bmiHeader);
 - 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 < 256; i++ )
 - {
 - palette[i].rgbBlue = palette[i].rgbGreen = palette[i].rgbRed = (BYTE)i;
 - palette[i].rgbReserved = 0;
 - }
 - }
 - }
 - CvvImage::CvvImage()
 - {
 - m_img = 0;
 - }
 - void CvvImage::Destroy()
 - {
 - cvReleaseImage( &m_img );
 - }
 - CvvImage::~CvvImage()
 - {
 - Destroy();
 - }
 - bool CvvImage::Create( int w, int h, int bpp, int origin )
 - {
 - const unsigned max_img_size = 10000;
 - if( (bpp != 8 && bpp != 24 && bpp != 32) ||
 - (unsigned)w >= max_img_size || (unsigned)h >= max_img_size ||
 - (origin != IPL_ORIGIN_TL && origin != IPL_ORIGIN_BL))
 - {
 - assert(0); // 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 && m_img->nSize == sizeof(IplImage))
 - Destroy();
 - /* 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& image, int desired_color )
 - {
 - IplImage* img = image.GetImage();
 - if( img )
 - {
 - CopyOf( img, desired_color );
 - }
 - }
 - #define HG_IS_IMAGE(img) \
 - ((img) != 0 && ((const IplImage*)(img))->nSize == sizeof(IplImage) && \
 - ((IplImage*)img)->imageData != 0)
 - void CvvImage::CopyOf( IplImage* img, int desired_color )
 - {
 - if( HG_IS_IMAGE(img) )
 - {
 - int color = desired_color;
 - CvSize size = cvGetSize( img );
 - if( color < 0 )
 - color = img->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( &img );
 - return true;
 - }
 - bool CvvImage::LoadRect( const char* filename,
 - int desired_color, CvRect r )
 - {
 - if( r.width < 0 || r.height < 0 ) return false;
 - IplImage* img = cvLoadImage( filename, desired_color );
 - if( !img )
 - return false;
 - if( r.width == 0 || r.height == 0 )
 - {
 - r.width = img->width;
 - r.height = img->height;
 - r.x = r.y = 0;
 - }
 - if( r.x > img->width || r.y > img->height ||
 - r.x + r.width < 0 || r.y + r.height < 0 )
 - {
 - cvReleaseImage( &img );
 - return false;
 - }
 - /* truncate r to source image */
 - if( r.x < 0 )
 - {
 - r.width += r.x;
 - r.x = 0;
 - }
 - if( r.y < 0 )
 - {
 - r.height += r.y;
 - r.y = 0;
 - }
 - if( 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( &img );
 - 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 && m_img->depth == IPL_DEPTH_8U )
 - {
 - uchar buffer[sizeof(BITMAPINFOHEADER) + 1024];
 - 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 && m_img && m_img->depth == IPL_DEPTH_8U && m_img->imageData )
 - {
 - uchar buffer[sizeof(BITMAPINFOHEADER) + 1024];
 - BITMAPINFO* bmi = (BITMAPINFO*)buffer;
 - int bmp_w = m_img->width, bmp_h = m_img->height;
 - CvRect roi = cvGetImageROI( m_img );
 - CvRect dst = RectToCvRect( *pDstRect );
 - if( roi.width == dst.width && roi.height == dst.height )
 - {
 - Show( hDCDst, dst.x, dst.y, dst.width, dst.height, roi.x, roi.y );
 - return;
 - }
 - if( roi.width > dst.width )
 - {
 - SetStretchBltMode(
 - hDCDst, // handle to device context
 - HALFTONE );
 - }
 - else
 - {
 - SetStretchBltMode(
 - hDCDst, // handle to device context
 - COLORONCOLOR );
 - }
 - FillBitmapInfo( bmi, bmp_w, bmp_h, Bpp(), m_img->origin );
 - ::StretchDIBits(
 - hDCDst,
 - dst.x, dst.y, dst.width, dst.height,
 - roi.x, roi.y, roi.width, roi.height,
 - m_img->imageData, bmi, DIB_RGB_COLORS, SRCCOPY );
 - }
 - }
 - void CvvImage::Fill( int color )
 - {
 - cvSet( m_img, cvScalar(color&255,(color>>8)&255,(color>>16)&255,(color>>24)&255) );
 - }
 - #endif
 
解决Opencv高低版本不兼容问题的更多相关文章
- 解决 android 高低版本 webView 里内容 自适应屏幕的终极方法
		
转载请声明出处(http://www.cnblogs.com/linguanh/) 一,先说下我的情况,大家可以对号入座(嫌无聊请跳过) 我的项目要求是这样的,先从数据库里面拿出来html标签,因为加 ...
 - 【我的Android进阶之旅】解决 Error:CreateProcess error=216, 该版本的 %1 与您运行的 Windows 版本不兼容。请查看计算机的系统信息,了解是否需要 x86
		
一.错误描述 刚刚打开Android Studio新建一个项目,然后就编译不了,报了如下所示的错误: 错误描述为: Error:CreateProcess error=216, 该版本的 %1 与您运 ...
 - 解决Mybatis-plus高版本不向后兼容的问题
		
mybatis-plus插件后面的版本没有兼容低版本.即:不存在低版本中EntityWrapper这个类了.而该类采用数据库表真实字段名作查询条件,这样硬编码形式确实不友好,比如如果后面数据库表中字段 ...
 - 解决selenium和FireFox版本不兼容问题
		
相信很多同学刚接触selenium时,在Eclipse中打开fireFox浏览器时会报错:org.openqa.selenium.firefox.NotConnectedException: Unab ...
 - OpenCV各版本差异与演化,从1.x到4.0
		
博客:blog.shinelee.me | 博客园 | CSDN 写在前面 最近因项目需要,得把OpenCV捡起来,登录OpenCV官网,竟然发现release了4.0.0-beata版本,所以借此机 ...
 - 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 ...
 - 怎么用一行代码解决CSS各种IE各种兼容问题
		
用一行代码来解决CSS在,IE6,IE7,IE8,IE9,IE10 中的各种兼容性问题. 在网站前端写代码的过程中,很多时间IE各个版本的兼容问题很难整.现在百度与谷歌都有了一行解决这种兼容性的代码了 ...
 - ubuntu下python安装pandas和numpy等依赖库版本不兼容的问题RuntimeWarning: numpy.dtype size changed
		
习惯了linux下用pip install numpy及pip install pandas命令了.折腾了好久了. 上来先在python3中pip3 install numpy装了numpy,然后再p ...
 - angularjs1+requirejs+ bootstrap+ jQuery低版本配合兼容ie8+浏览器
		
angularjs兼容低版本IE浏览器(IE8)angularjs在1.3之后的版本都是选择放弃对IE8及更低IE版本的支持,但是就目前的开发形式来看,IE8的使用客户还是蛮多的,最近有个项目要求尽量 ...
 
随机推荐
- 算法题 19 二叉平衡树检查 牛客网 CC150
			
算法题 19 二叉平衡树检查 牛客网 CC150 实现一个函数,检查二叉树是否平衡,平衡的定义如下,对于树中的任意一个结点,其两颗子树的高度差不超过1. 给定指向树根结点的指针TreeNode* ro ...
 - Excel 查找某一列中包含指定字符的单元格
			
网上查找相关内容,个人感觉是另一种形式的过滤喽.有的说用FIND,有的用高级筛选.我查找时如下: 1.新拉一列,标注公式“=ISNUMBER(FIND("宣",B2))”,然后拉至 ...
 - notepad++运行python代码
			
notepad++运行代码 在菜单栏中点击运行或按F5,在弹出的对话框中输入下面命令 cmd /k E:\py3.6\python.exe "$(FULL_CURRENT_PATH)&quo ...
 - IDEA中文出现乱码解决
			
转自:http://lcl088005.iteye.com/blog/2284696 我是个idea的忠实用户,新公司的项目都是用eclipse做的,通过svn拉下代码后发现,注释的内容里,中文内容都 ...
 - FarBox的使用经历
			
新年伊始,一个崭新的开始,我的博客也有个新的起点.怎么会有这个想法呢?个人觉得这是程序员那颗不安分的心开始躁动了(其实就是开始作了~~哈哈,开个玩笑). 更佳界面.更流畅的操作.更方便的查看.更炫酷动 ...
 - $Java正则表达式基础整理
			
(一)正则表达式及语法简介 String类使用正则表达式的几个方法: 正则表达式支持的合法字符: 特殊字符: 预定义字符: 方括号表达式: 圆括号表达式:用于将多个表达式组成一个子表达式,可以使用或运 ...
 - INSPIRED启示录 读书笔记 - 第28章 创业型公司的产品管理
			
产品设计方式 第一步:创业初期只设三个职位,产品经理.交互设计师和原型开发人员(职位可以兼任) 第二步:快速展开产品设计(高保真原型),邀请真实的目标用户验证产品原型,迭代修改 第三步:随着迭代的深入 ...
 - 如何判断Linux服务器是否被入侵?
			
被入侵服务器的症状 当服务器被没有经验攻击者或者自动攻击程序入侵了的话,他们往往会消耗 100% 的资源.他们可能消耗 CPU 资源来进行数字货币的采矿或者发送垃圾邮件,也可能消耗带宽来发动 DoS ...
 - Linux学习笔记001——win下安装Linux虚拟机
			
我研二之前算是一个纯粹的计算机小白,因为某些原因开始接触了计算机方面的知识. Linux系统也就是前几个月才听说,因某些需求需要在Linux环境下运行.纯的Linux系统不太现实, 所以在他人帮助和自 ...
 - MapReduce-join连接
			
join连接 MapReduce能够执行大型数据集间的连接(join)操作.连接操作的具体实现技术取决于数据集的规模及分区方式连接操作如果由mapper执行,则称为“map端连接”:如果由reduce ...