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的更多相关文章

  1. OpenCV MAT基本图像容器

    参考博客: OpenCv中cv::Mat和IplImage,CvMat之间的转换 Mat - 基本图像容器 Mat类型较CvMat和IplImage有更强的矩阵运算能力,支持常见的矩阵运算(参照Mat ...

  2. opencv 61篇

    (一)--安装配置.第一个程序 标签: imagebuildincludeinputpathcmd 2011-10-21 16:16 41132人阅读 评论(50) 收藏 举报  分类: OpenCV ...

  3. 【OpenCV入门教程之三】 图像的载入,显示和输出 一站式完全解析(转)

    本系列文章由@浅墨_毛星云 出品,转载请注明出处. 文章链接:http://blog.csdn.net/poem_qianmo/article/details/20537737 作者:毛星云(浅墨)  ...

  4. OpenCV源码阅读(3)---base.hpp

    base.h处于core模块中,是OpenCV的核心类.其作用是定义了OpenCV的基本错误类型,在程序运行出现错误是抛出错误,防止数据溢出.总而言之,其功能主要是考虑程序的健壮性. 头文件 #ifn ...

  5. 图像储存容器Mat[OpenCV 笔记11]

    IplImage 与 Mat IplImage是OpenCV1中的图像存储结构体,基于C接口创建.在退出之前必须release,否则就会造成内存泄露.在一些只能使用C语言的嵌入式系统中,不得不使用. ...

  6. OpenCV中Mat的详解

    每次碰到Mat都得反复查具体的用法,网上的基础讲解不多,难得看到一篇,赶快转来收藏~ 原文地址:http://www.opencvchina.com/thread-1039-1-1.html 目标 我 ...

  7. OPENCV第一篇

    了解过之前老版本OpenCV的童鞋们都应该清楚,对于OpenCV1.0时代的基于 C 语言接口而建的图像存储格式IplImage*,如果在退出前忘记release掉的话,就会照成内存泄露.而且用起来超 ...

  8. 相机标定 matlab opencv ROS三种方法标定步骤(2)

    二  ubuntu下Opencv的相机标定 一般直接用Opencv的源码就可以进行相机的标定,但是可能只是会实现结果,却不懂实现的过程,我也是模模糊糊的看了<计算机视觉中的多视图几何>以及 ...

  9. OpenCV中的结构体、类与Emgu.CV的对应表

    OpenCv中的 C 结构 OpenCV中的 C++ 封装 Emgu.CV中的 C# 封装 OpenCV 和 Emgu.CV 中的结构罗列 谢谢阅读,有误希望指正 原文地址 Basic Structu ...

随机推荐

  1. HTML+CSS要点

    1.td占据多行 / 列时,其挤开的 td 不写(但是包裹 td 的 tr 要写) 2. display:td 的元素中的文本默认垂直不居中(table中的td中的文本是垂直居中的) 3.th虽然定义 ...

  2. Ubuntu16.04 下docker部署web项目

    概念性的请戳 第一步:更新apt-get update 第二步:安装环境 apt-get install \ apt-transport-https \ ca-certificates \ curl ...

  3. PythonCookBook笔记——数据编码和处理

    数据编码和处理 主要涉及用Python处理不同方式编码的数据,如CSV.JSON.XML和二进制包装记录. 读写CSV数据 使用csv库. import csv with open('stocks.c ...

  4. ANALYSIS AND EXPLOITATION OF A LINUX KERNEL VULNERABILITY (CVE-2016-0728)

    ANALYSIS AND EXPLOITATION OF A LINUX KERNEL VULNERABILITY (CVE-2016-0728) By Perception Point Resear ...

  5. js比较3个数字的大小

    <script> var a = [1, 5, 2, 123, 34, 43, 7]; var i = j = t = 0; //sort方法, 推荐使用 a.sort(function( ...

  6. 用Darwin开发RTSP级联服务器(拉模式转发)(附源码)

    源码下载地址:https://github.com/EasyDarwin orwww.easydarwin.org 在博客 在Darwin进行实时视频转发的两种模式 中,我们描述了流媒体服务器对源端音 ...

  7. EasyDarwin开源平台直播架构

    Created with Raphaël 2.1.0ClientClientEasyCMSEasyCMSEasyCameraEasyCameraEasyDarwinEasyDarwin请求设备列表设备 ...

  8. javaweb开发之javaBean

    一.JavaBean简介 JavaBean是使用Java语言开发的一个可重用的组件,在JSP的开发中可以使用JavaBean减少重复代码,使整个JSP代码的开发更简洁.JSP搭配JavaBean来使用 ...

  9. Collection of Boot Sector Formats for ISO 9660 Images

    http://bazaar.launchpad.net/~libburnia-team/libisofs/scdbackup/view/head:/doc/boot_sectors.txt Colle ...

  10. POJO对象建立规则

    1.所有POJO类属性必须使用包装数据类型,RPC方法的返回值和参数必须使用包装数据类型. 说明:POJO类属性没有初值是提醒使用者在使用时,必须自己显示的进行赋值,任何NPE问题,或者入库检查,都由 ...