解决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的使用客户还是蛮多的,最近有个项目要求尽量 ...
随机推荐
- redis的安装配置(转)
一.下载windows版本的Redis 去官网找了很久,发现原来在官网上可以下载的windows版本的,现在官网以及没有下载地址,只能在github上下载,官网只提供linux版本的下载 官网下载地址 ...
- foreach使用和函数
2016-04-25 一.foreach( 对集合每个元素的引用 in 集合 ) { } int[] a = new int[5]{1,2,3,4,5}; foreach( int b in a ) ...
- Owncloud-X安装配置
系统是基于Centos7.2 1.更改yum源: mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.back ...
- UI控件之UICollectionView
UICollectionView:集合视图,是iOS6.0后出现的,与UITableView类似,优势在于可以灵活的布局cell UICollectionViewLayout:布局类,抽象类,一般定义 ...
- .ssh中的文件的分别意义
当我们在用户的主目录使用如下命令: cd (进入个人主目录,默认为/home/hadoop) ssh-keygen -t rsa -P '' (注:最后是二个单引号) 表示在用户的主目录创建ssh登陆 ...
- 版本控制系统Subversion
系统提供撤销的功能对我们实际开发中特别重要.改动后撤销几乎也是我们每个人经常做的事情.再多人进行同一个项目的开发或者测试的时候,版本的唯一性(类似于临界区资源),也就是说A 和B 两个人协同工作的时候 ...
- Linux Shell编程 sed命令
概述 sed 是一种几乎可以应用在所有 UNIX 平台(包括 Linux)上的轻量级流编辑器,体积小.所以,它可以对从如管道这样的标准输入中接收的数据进行编辑. sed 主要是用来将数据进行选取.替换 ...
- 主攻ASP.NET.4.5.1 MVC5.0之重生:在项目中使用zTree jQuery 树插件
效果图和json格式 Controllers代码 using HR.Models; using HR.Models.Repository; /***************************** ...
- Qt开发UDP
一.单播 1.声明udp对象 QUdpSocket* udpClient: 2.new出对象 udpClient = new QUdpSocket(this); 3.分配本地地址(如果不分配,使用系统 ...
- ResourceBundle和properties 读取配置文件区别
java.util.ResourceBundle 和java.util.properties 读取配置文件区别 这两个类都是读取properties格式的文件的,而Properties同时还能用来写文 ...