解决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的使用客户还是蛮多的,最近有个项目要求尽量 ...
随机推荐
- django-admin 设计User外键,设计model
设置外键 class profile_user(AbstractBaseUser, PermissionsMixin): company = models.ForeignKey(Company, de ...
- classmethod
描述 classmethod 修饰符对应的函数不需要实例化,不需要 self 参数,但第一个参数需要是表示自身类的 cls 参数,可以来调用类的属性,类的方法,实例化对象等. 语法 classmeth ...
- LeetCode:平衡二叉树【110】
LeetCode:平衡二叉树[110] 题目描述 给定一个二叉树,判断它是否是高度平衡的二叉树. 本题中,一棵高度平衡二叉树定义为: 一个二叉树每个节点 的左右两个子树的高度差的绝对值不超过1. 示例 ...
- 每天一个Linux命令(58)sudo命令
sudo命令用来以其他身份来执行命令,预设的身份为root. (1)用法: 用法: sudo [参数] [命令] (2)功能: 功能: sudo可以针对 ...
- Ubuntu中输入输出重定向及管道技术简述
输出 1.标准输出 定义:程序在默认情况下输出结果的地方(stdout). 2.输出重定向 定义:用于把数据的输出转移到另一个地方去. 3.Ubuntu中例子 $ls > ~/ls_out # ...
- 在安装mysqli的时候,出现error: ext/mysqlnd/mysql_float_to_double.h: No such file or directory
/application/php5.:: warning: /ext/mysqli/mysqli_api.c::: error: ext/mysqlnd/mysql_float_to_double.h ...
- 主攻ASP.NET MVC4.0之重生:Jquery Mobile 列表
代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title ...
- require.js和sea.js的区别
下面为大家讲解一下require.js和sea.js的区别.纯属个人意见,不喜勿喷. 首先原理上的区别 sea.js遵循CMD规范.书写方式类似node.js的书写模板代码.依赖的自动加载,配置的简洁 ...
- 用blastn比对自己建立的数据库
自己感兴趣的一些序列作为数据库,然后用blastn把测序的read比对到自己建立的数据库中. 1.用fasta文件创建blast数据库 makeblastdb -in input_file -inpu ...
- 使用easyui的form提交表单,在IE下出现类似附件下载时提示是否保存的现象
之前开发时遇到的一个问题,使用easyui的form提交表单,在Chrome下时没问题的,但是在IE下出现类似附件下载时提示是否保存的现象. 这里记录一下如何解决的.其实这个现象不光是easyui的f ...