opencv MatExpr MatOp
opencv提供了很多Mat的操作,其中涉及到两个重要的类:MatOp和MatExpr
- C++: MatExpr abs(const Mat& m)
- C++: void absdiff(InputArray src1, InputArray src2, OutputArray dst)
- C = abs(A-B) is equivalent to absdiff(A, B, C)
- C = abs(A) is equivalent to absdiff(A, Scalar::all(), C)
- C++: void add(InputArray src1, InputArray src2, OutputArray dst, InputArray mask=noArray(), int dtype=-)
- C++: void addWeighted(InputArray src1, double alpha, InputArray src2, double beta, double gamma, Out-
- putArray dst, int dtype=-)
- C++: void bitwise_and(InputArray src1, InputArray src2, OutputArray dst, InputArray mask=noArray())
- C++: void bitwise_not(InputArray src, OutputArray dst, InputArray mask=noArray())
- C++: void bitwise_or(InputArray src1, InputArray src2, OutputArray dst, InputArray mask=noArray())
- C++: void bitwise_xor(InputArray src1, InputArray src2, OutputArray dst, InputArray mask=noArray())
- C++: void calcCovarMatrix(const Mat* samples, int nsamples, Mat& covar, Mat& mean, int flags, int
- ctype=CV_64F)
- C++: void cartToPolar(InputArray x, InputArray y, OutputArray magnitude, OutputArray angle, bool an-
- gleInDegrees=false)
- C++: void magnitude(InputArray x, InputArray y, OutputArray magnitude)
- C++: bool checkRange(InputArray a, bool quiet=true, Point* pos=, double minVal=-DBL_MAX, double
- maxVal=DBL_MAX )
- C++: void compare(InputArray src1, InputArray src2, OutputArray dst, int cmpop)
- C++: void completeSymm(InputOutputArray mtx, bool lowerToUpper=false)
- C++: void convertScaleAbs(InputArray src, OutputArray dst, double alpha=, double beta=)
- C++: int countNonZero(InputArray src)
- C++: Mat cvarrToMat(const CvArr* arr, bool copyData=false, bool allowND=true, int coiMode= )
- C++: void dct(InputArray src, OutputArray dst, int flags=)
- C++: void idct(InputArray src, OutputArray dst, int flags=)
- C++: void dft(InputArray src, OutputArray dst, int flags=, int nonzeroRows=)
- C++: void idft(InputArray src, OutputArray dst, int flags=, int nonzeroRows=)
- C++: void divide(InputArray src1, InputArray src2, OutputArray dst, double scale=, int dtype=-)
- C++: double determinant(InputArray mtx)
- C++: bool eigen(InputArray src, OutputArray eigenvalues, int lowindex=-, int highindex=-)
- C++: void exp(InputArray src, OutputArray dst)
- C++: void extractImageCOI(const CvArr* arr, OutputArray coiimg, int coi=- )
- C++: void insertImageCOI(InputArray coiimg, CvArr* arr, int coi=- )
- C++: void flip(InputArray src, OutputArray dst, int flipCode)
- C++: void gemm(InputArray src1, InputArray src2, double alpha, InputArray src3, double gamma, OutputArray dst, int flags= )
- C++: ConvertData getConvertElem(int fromType, int toType)
- C++: int getOptimalDFTSize(int vecsize)
- C++: void inRange(InputArray src, InputArray lowerb, InputArray upperb, OutputArray dst)
- C++: double invert(InputArray src, OutputArray dst, int flags=DECOMP_LU)
- C++: void log(InputArray src, OutputArray dst)
- C++: void LUT(InputArray src, InputArray lut, OutputArray dst, int interpolation= )
- C++: double Mahalanobis(InputArray v1, InputArray v2, InputArray icovar)
- C++: void max(InputArray src1, InputArray src2, OutputArray dst)
MatOp负责MatExpr的运算操作
- class CV_EXPORTS MatOp
- {
- public:
- MatOp();
- virtual ~MatOp();
- virtual bool elementWise(const MatExpr& expr) const;
- virtual void assign(const MatExpr& expr, Mat& m, int type=-) const = ;
- virtual void roi(const MatExpr& expr, const Range& rowRange,
- const Range& colRange, MatExpr& res) const;
- virtual void diag(const MatExpr& expr, int d, MatExpr& res) const;
- virtual void augAssignAdd(const MatExpr& expr, Mat& m) const;
- virtual void augAssignSubtract(const MatExpr& expr, Mat& m) const;
- virtual void augAssignMultiply(const MatExpr& expr, Mat& m) const;
- virtual void augAssignDivide(const MatExpr& expr, Mat& m) const;
- virtual void augAssignAnd(const MatExpr& expr, Mat& m) const;
- virtual void augAssignOr(const MatExpr& expr, Mat& m) const;
- virtual void augAssignXor(const MatExpr& expr, Mat& m) const;
- virtual void add(const MatExpr& expr1, const MatExpr& expr2, MatExpr& res) const;
- virtual void add(const MatExpr& expr1, const Scalar& s, MatExpr& res) const;
- virtual void subtract(const MatExpr& expr1, const MatExpr& expr2, MatExpr& res) const;
- virtual void subtract(const Scalar& s, const MatExpr& expr, MatExpr& res) const;
- virtual void multiply(const MatExpr& expr1, const MatExpr& expr2, MatExpr& res, double scale=) const;
- virtual void multiply(const MatExpr& expr1, double s, MatExpr& res) const;
- virtual void divide(const MatExpr& expr1, const MatExpr& expr2, MatExpr& res, double scale=) const;
- virtual void divide(double s, const MatExpr& expr, MatExpr& res) const;
- virtual void abs(const MatExpr& expr, MatExpr& res) const;
- virtual void transpose(const MatExpr& expr, MatExpr& res) const;
- virtual void matmul(const MatExpr& expr1, const MatExpr& expr2, MatExpr& res) const;
- virtual void invert(const MatExpr& expr, int method, MatExpr& res) const;
- virtual Size size(const MatExpr& expr) const;
- virtual int type(const MatExpr& expr) const;
- };
- //modules/core/src/matop.cpp 定义了很多不同的操作,每种操作会重载部分函数
class MatOp_Identity : public MatOp- {
- public:
- MatOp_Identity() {}
- virtual ~MatOp_Identity() {}
- bool elementWise(const MatExpr& /*expr*/) const { return true; }
- void assign(const MatExpr& expr, Mat& m, int type=-) const;
- static void makeExpr(MatExpr& res, const Mat& m);
- };
- static MatOp_Identity g_MatOp_Identity; //一种默认的MatOp
- static inline bool isIdentity(const MatExpr& e) { return e.op == &g_MatOp_Identity; }
- class MatOp_T : public MatOp
- {
- public:
- MatOp_T() {}
- virtual ~MatOp_T() {}
- bool elementWise(const MatExpr& /*expr*/) const { return false; }
- void assign(const MatExpr& expr, Mat& m, int type=-) const;
- void multiply(const MatExpr& e1, double s, MatExpr& res) const;
- void transpose(const MatExpr& expr, MatExpr& res) const;
- static void makeExpr(MatExpr& res, const Mat& a, double alpha=);
- };
- static MatOp_T g_MatOp_T;
- static inline bool isT(const MatExpr& e) { return e.op == &g_MatOp_T; }
- //其他函数的实现举例:
- void MatOp::add(const MatExpr& e1, const MatExpr& e2, MatExpr& res) const
- {
- if( this == e2.op )
- {
- double alpha = , beta = ;
- Scalar s;
- Mat m1, m2;
- if( isAddEx(e1) && (!e1.b.data || e1.beta == ) )
- {
- m1 = e1.a;
- alpha = e1.alpha;
- s = e1.s;
- }
- else
- e1.op->assign(e1, m1);
- if( isAddEx(e2) && (!e2.b.data || e2.beta == ) )
- {
- m2 = e2.a;
- beta = e2.alpha;
- s += e2.s;
- }
- else
- e2.op->assign(e2, m2);
- MatOp_AddEx::makeExpr(res, m1, m2, alpha, beta, s);
- }
- else
- e2.op->add(e1, e2, res);
- }
- void MatOp::add(const MatExpr& expr1, const Scalar& s, MatExpr& res) const
- {
- Mat m1;
- expr1.op->assign(expr1, m1);
- MatOp_AddEx::makeExpr(res, m1, Mat(), , , s);
- }
- void MatOp::subtract(const MatExpr& e1, const MatExpr& e2, MatExpr& res) const
- {
- if( this == e2.op )
- {
- double alpha = , beta = -;
- Scalar s;
- Mat m1, m2;
- if( isAddEx(e1) && (!e1.b.data || e1.beta == ) )
- {
- m1 = e1.a;
- alpha = e1.alpha;
- s = e1.s;
- }
- else
- e1.op->assign(e1, m1);
- if( isAddEx(e2) && (!e2.b.data || e2.beta == ) )
- {
- m2 = e2.a;
- beta = -e2.alpha;
- s -= e2.s;
- }
- else
- e2.op->assign(e2, m2);
- MatOp_AddEx::makeExpr(res, m1, m2, alpha, beta, s);
- }
- else
- e2.op->subtract(e1, e2, res);
- }
- void MatOp::subtract(const Scalar& s, const MatExpr& expr, MatExpr& res) const
- {
- Mat m;
- expr.op->assign(expr, m);
- MatOp_AddEx::makeExpr(res, m, Mat(), -, , s);
- }
- //core/include/opencv2/core/mat.hpp
class CV_EXPORTS MatExpr- {
- public:
- MatExpr();
- explicit MatExpr(const Mat& m);
- MatExpr(const MatOp* _op, int _flags, const Mat& _a = Mat(), const Mat& _b = Mat(),
- const Mat& _c = Mat(), double _alpha = , double _beta = , const Scalar& _s = Scalar());
- operator Mat() const;
- template<typename _Tp> operator Mat_<_Tp>() const;
- Size size() const;
- int type() const;
- MatExpr row(int y) const;
- MatExpr col(int x) const;
- MatExpr diag(int d = ) const;
- MatExpr operator()( const Range& rowRange, const Range& colRange ) const;
- MatExpr operator()( const Rect& roi ) const;
- MatExpr t() const;
- MatExpr inv(int method = DECOMP_LU) const;
- MatExpr mul(const MatExpr& e, double scale=) const;
- MatExpr mul(const Mat& m, double scale=) const;
- Mat cross(const Mat& m) const;
- double dot(const Mat& m) const;
- const MatOp* op;
- int flags;
- Mat a, b, c;
- double alpha, beta;
- Scalar s;
- };
- CV_EXPORTS MatExpr operator + (const Mat& a, const Mat& b);
- CV_EXPORTS MatExpr operator + (const Mat& a, const Scalar& s);
- CV_EXPORTS MatExpr operator + (const Scalar& s, const Mat& a);
- CV_EXPORTS MatExpr operator + (const MatExpr& e, const Mat& m);
- CV_EXPORTS MatExpr operator + (const Mat& m, const MatExpr& e);
- CV_EXPORTS MatExpr operator + (const MatExpr& e, const Scalar& s);
- CV_EXPORTS MatExpr operator + (const Scalar& s, const MatExpr& e);
- CV_EXPORTS MatExpr operator + (const MatExpr& e1, const MatExpr& e2);
- CV_EXPORTS MatExpr operator - (const Mat& a, const Mat& b);
- CV_EXPORTS MatExpr operator - (const Mat& a, const Scalar& s);
- CV_EXPORTS MatExpr operator - (const Scalar& s, const Mat& a);
- CV_EXPORTS MatExpr operator - (const MatExpr& e, const Mat& m);
- CV_EXPORTS MatExpr operator - (const Mat& m, const MatExpr& e);
- CV_EXPORTS MatExpr operator - (const MatExpr& e, const Scalar& s);
- CV_EXPORTS MatExpr operator - (const Scalar& s, const MatExpr& e);
- CV_EXPORTS MatExpr operator - (const MatExpr& e1, const MatExpr& e2);
- CV_EXPORTS MatExpr operator - (const Mat& m);
- CV_EXPORTS MatExpr operator - (const MatExpr& e);
- CV_EXPORTS MatExpr operator * (const Mat& a, const Mat& b);
- CV_EXPORTS MatExpr operator * (const Mat& a, double s);
- CV_EXPORTS MatExpr operator * (double s, const Mat& a);
- CV_EXPORTS MatExpr operator * (const MatExpr& e, const Mat& m);
- CV_EXPORTS MatExpr operator * (const Mat& m, const MatExpr& e);
- CV_EXPORTS MatExpr operator * (const MatExpr& e, double s);
- CV_EXPORTS MatExpr operator * (double s, const MatExpr& e);
- CV_EXPORTS MatExpr operator * (const MatExpr& e1, const MatExpr& e2);
- CV_EXPORTS MatExpr operator / (const Mat& a, const Mat& b);
- CV_EXPORTS MatExpr operator / (const Mat& a, double s);
- CV_EXPORTS MatExpr operator / (double s, const Mat& a);
- CV_EXPORTS MatExpr operator / (const MatExpr& e, const Mat& m);
- CV_EXPORTS MatExpr operator / (const Mat& m, const MatExpr& e);
- CV_EXPORTS MatExpr operator / (const MatExpr& e, double s);
- CV_EXPORTS MatExpr operator / (double s, const MatExpr& e);
- CV_EXPORTS MatExpr operator / (const MatExpr& e1, const MatExpr& e2);
- CV_EXPORTS MatExpr operator < (const Mat& a, const Mat& b);
- CV_EXPORTS MatExpr operator < (const Mat& a, double s);
- CV_EXPORTS MatExpr operator < (double s, const Mat& a);
- CV_EXPORTS MatExpr operator <= (const Mat& a, const Mat& b);
- CV_EXPORTS MatExpr operator <= (const Mat& a, double s);
- CV_EXPORTS MatExpr operator <= (double s, const Mat& a);
- CV_EXPORTS MatExpr operator == (const Mat& a, const Mat& b);
- CV_EXPORTS MatExpr operator == (const Mat& a, double s);
- CV_EXPORTS MatExpr operator == (double s, const Mat& a);
- CV_EXPORTS MatExpr operator != (const Mat& a, const Mat& b);
- CV_EXPORTS MatExpr operator != (const Mat& a, double s);
- CV_EXPORTS MatExpr operator != (double s, const Mat& a);
- CV_EXPORTS MatExpr operator >= (const Mat& a, const Mat& b);
- CV_EXPORTS MatExpr operator >= (const Mat& a, double s);
- CV_EXPORTS MatExpr operator >= (double s, const Mat& a);
- CV_EXPORTS MatExpr operator > (const Mat& a, const Mat& b);
- CV_EXPORTS MatExpr operator > (const Mat& a, double s);
- CV_EXPORTS MatExpr operator > (double s, const Mat& a);
- CV_EXPORTS MatExpr operator & (const Mat& a, const Mat& b);
- CV_EXPORTS MatExpr operator & (const Mat& a, const Scalar& s);
- CV_EXPORTS MatExpr operator & (const Scalar& s, const Mat& a);
- CV_EXPORTS MatExpr operator | (const Mat& a, const Mat& b);
- CV_EXPORTS MatExpr operator | (const Mat& a, const Scalar& s);
- CV_EXPORTS MatExpr operator | (const Scalar& s, const Mat& a);
- CV_EXPORTS MatExpr operator ^ (const Mat& a, const Mat& b);
- CV_EXPORTS MatExpr operator ^ (const Mat& a, const Scalar& s);
- CV_EXPORTS MatExpr operator ^ (const Scalar& s, const Mat& a);
- CV_EXPORTS MatExpr operator ~(const Mat& m);
- CV_EXPORTS MatExpr min(const Mat& a, const Mat& b);
- CV_EXPORTS MatExpr min(const Mat& a, double s);
- CV_EXPORTS MatExpr min(double s, const Mat& a);
- CV_EXPORTS MatExpr max(const Mat& a, const Mat& b);
- CV_EXPORTS MatExpr max(const Mat& a, double s);
- CV_EXPORTS MatExpr max(double s, const Mat& a);
- CV_EXPORTS MatExpr abs(const Mat& m);
- CV_EXPORTS MatExpr abs(const MatExpr& e);
- } // cv
- MatExpr::MatExpr(const Mat& m) : op(&g_MatOp_Identity), flags(), a(m), b(Mat()), c(Mat()), alpha(), beta(), s(Scalar())
- {
//默认使用的是g_MatOp_Identity- }
- MatExpr MatExpr::diag(int d) const
- {
- MatExpr e;
- op->diag(*this, d, e);
- return e;
- }
- MatExpr MatExpr::t() const
- {
- MatExpr e;
- op->transpose(*this, e);
- return e;
- }
- MatExpr operator + (const Mat& a, const Mat& b)
- {
- MatExpr e;
- MatOp_AddEx::makeExpr(e, a, b, , );
- return e;
- }
- class MatOp_AddEx : public MatOp
- {
- public:
- MatOp_AddEx() {}
- virtual ~MatOp_AddEx() {}
- bool elementWise(const MatExpr& /*expr*/) const { return true; }
- void assign(const MatExpr& expr, Mat& m, int type=-) const;
- void add(const MatExpr& e1, const Scalar& s, MatExpr& res) const;
- void subtract(const Scalar& s, const MatExpr& expr, MatExpr& res) const;
- void multiply(const MatExpr& e1, double s, MatExpr& res) const;
- void divide(double s, const MatExpr& e, MatExpr& res) const;
- void transpose(const MatExpr& e1, MatExpr& res) const;
- void abs(const MatExpr& expr, MatExpr& res) const;
- static void makeExpr(MatExpr& res, const Mat& a, const Mat& b, double alpha, double beta, const Scalar& s=Scalar());
- };
- static MatOp_AddEx g_MatOp_AddEx;
inline void MatOp_AddEx::makeExpr(MatExpr& res, const Mat& a, const Mat& b, double alpha, double beta, const Scalar& s)
{
res = MatExpr(&g_MatOp_AddEx, 0, a, b, Mat(), alpha, beta, s);
}
opencv MatExpr MatOp的更多相关文章
- OpenCV MAT基本图像容器
参考博客: OpenCv中cv::Mat和IplImage,CvMat之间的转换 Mat - 基本图像容器 Mat类型较CvMat和IplImage有更强的矩阵运算能力,支持常见的矩阵运算(参照Mat ...
- opencv 61篇
(一)--安装配置.第一个程序 标签: imagebuildincludeinputpathcmd 2011-10-21 16:16 41132人阅读 评论(50) 收藏 举报 分类: OpenCV ...
- 【OpenCV入门教程之三】 图像的载入,显示和输出 一站式完全解析(转)
本系列文章由@浅墨_毛星云 出品,转载请注明出处. 文章链接:http://blog.csdn.net/poem_qianmo/article/details/20537737 作者:毛星云(浅墨) ...
- OpenCV源码阅读(3)---base.hpp
base.h处于core模块中,是OpenCV的核心类.其作用是定义了OpenCV的基本错误类型,在程序运行出现错误是抛出错误,防止数据溢出.总而言之,其功能主要是考虑程序的健壮性. 头文件 #ifn ...
- 图像储存容器Mat[OpenCV 笔记11]
IplImage 与 Mat IplImage是OpenCV1中的图像存储结构体,基于C接口创建.在退出之前必须release,否则就会造成内存泄露.在一些只能使用C语言的嵌入式系统中,不得不使用. ...
- OpenCV中Mat的详解
每次碰到Mat都得反复查具体的用法,网上的基础讲解不多,难得看到一篇,赶快转来收藏~ 原文地址:http://www.opencvchina.com/thread-1039-1-1.html 目标 我 ...
- OPENCV第一篇
了解过之前老版本OpenCV的童鞋们都应该清楚,对于OpenCV1.0时代的基于 C 语言接口而建的图像存储格式IplImage*,如果在退出前忘记release掉的话,就会照成内存泄露.而且用起来超 ...
- 相机标定 matlab opencv ROS三种方法标定步骤(2)
二 ubuntu下Opencv的相机标定 一般直接用Opencv的源码就可以进行相机的标定,但是可能只是会实现结果,却不懂实现的过程,我也是模模糊糊的看了<计算机视觉中的多视图几何>以及 ...
- OpenCV中的结构体、类与Emgu.CV的对应表
OpenCv中的 C 结构 OpenCV中的 C++ 封装 Emgu.CV中的 C# 封装 OpenCV 和 Emgu.CV 中的结构罗列 谢谢阅读,有误希望指正 原文地址 Basic Structu ...
随机推荐
- javascript 高级编程系列 - 继承
1. 原型链继承 (缺点:子类继承父类的引用类型的属性值会在各个实例中共享,创建子类实例时无法向父类构造函数传递参数) // 定义父类构造函数 function SuperClass(father, ...
- upstart man
man upstart nit(8) init(8) NAME init - Upstart process management daemon SYNOPSIS init [OPTION]... D ...
- .NET MVC 4 实现邮箱激活账户功能
这篇文章是<.NET MVC 4 实现用户注册功能>的后续开发,实现发送激活链接到注册用户邮箱,用户在邮箱打开链接后激活账户的功能. 首先实现发送邮件的功能,在管理用户注册的control ...
- windows常用命令(转载)
1.最基本,最常用的,测试物理网络的 ping 192.168.0.8 -t ,参数-t是等待用户去中断测试 2.查看DNS.IP.Mac等 A.Win98:winipcfg B.Win2000 ...
- VLC For Android Ubuntu14.04编译环境搭建
VLC多媒体播放器(英语:VLC media player,最初为VideoLAN Client.是VideoLAN计划的开放源码多媒体播放器.)支持众多音频与视频解码器及文件格式,并支持DVD影音光 ...
- EasyDarwin开源摄像机访问EasyCamera中海康摄像头语音对讲和云台控制转发实现
转自:http://blog.csdn.net/yanzhuomin/article/details/52887311 EasyCamera中关于摄像头SDK的调用都集中在EasyCameraSour ...
- Node.js安装及环境配置(windows)
1.Node.js简介 简单的说 Node.js 就是运行在服务端的 JavaScript.Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行环境.Node.js 使用 ...
- ABAP- INCLUDE Zxxx IF FOUND.
大顾代码: INCLUDE zinc_ca_0002 IF FOUND. - 这肯定是大顾问写出来的 - 一般都不会加东西啊 -加了 IF FOUND 不知道啥意思. 古道无仙(173120830) ...
- Mac终端操作SVN指令
1.将文件checkout到本地目录 svn checkout path(path是服务器上的目录) 例如:svn checkout svn://192.168.1.1/pro/domain ...
- CSS3学习笔记(3)—左右飞入的文字
前几天看到一个企业招聘的动画觉得很炫,里面有个企业介绍的文字是用飞入的效果做出来的,今天尝试了写了一下,感觉还不错~\(≧▽≦)/~啦啦啦 下面来看我做的动态效果: 其实上面的效果很简单的,我的截图软 ...