解决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的使用客户还是蛮多的,最近有个项目要求尽量 ...
随机推荐
- 剑指offer 面试29题
面试29题: 题目:顺时针打印矩阵(同LeetCode 螺旋矩阵打印) 题:输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下矩阵: 1 2 3 4 5 6 7 8 9 ...
- iOS应用生命周期
作为应用程序的委托对象,AppDelegate类在应用生命周期的不同阶段会回调不同的方法.首先,让我们先了解一下iOS 应用的不同状态及它们彼此间的关系,见图1 . 图1 iOS应用状态图 下面简要介 ...
- 爬虫基础库之requests模块
一.requests模块简介 使用requests可以模拟浏览器请求,比起之前用到的urllib,requests模块的api更加快捷,其实ruquests的本质就是封装urllib3这个模块. re ...
- python之数据的序列化
参考博客:http://www.cnblogs.com/yyds/p/6563608.html 数据的序列化功能表 json.dumps() 将python数据类型转换为(json)字符串 json. ...
- RocketMQ 笔记-转
Astrotrain概述 Astrotrain是基于阿里巴巴开源项目RocketMQ进行封装的分布式消息中间件系统,提供集群环境下的消息生产和消费功能. RocketMQ介绍 RocketMQ的物理部 ...
- 手机端的META差异
手机端的META你了解多少? 我们先来简单了解下meta标签:meta指元素可提供有关页面的元信息(meta-information),比如针对搜索引擎和更新频度的描述和关键词. 标签位于文档的头部, ...
- 初识python---简介,简单的for,while&if
一编程语言:编程语言是程序员与计算机沟通的介质: 编程语言的分类: 1机器语言:是用二进制代码表示的计算机能直接识别和执行的一种机器指令的集合. 优点:灵活,直接执行和速度快 ...
- 手把手教你使用eclipse+qemu+gdb来单步调试ARM内核【学习笔记】
平台信息:linux4.0 平台:qemu 作者:庄泽彬 说明:笨叔叔的Linux视频的笔记 一.编译linux源码 export CROSS_COMPILE=arm-linux-gnueabi- e ...
- POJ 1144 无向图求割点
学长写的: #include<cstdio>#include<cstdlib>#include<cmath>#include<iostream>#in ...
- juniper常用命令
Juniper防火墙基本命令 get interface ethernet0/0 查看 端口 常用查看命令 Get int 查看接口配置信息 Get int ethx/x 查看指定接口配置信息 G ...