CvMat and cv::Mat
CvMat:
typedef struct CvMat
{
int type;
int step; /* for internal use only */
int* refcount;
int hdr_refcount; union
{
uchar* ptr;
short* s;
int* i;
float* fl;
double* db;
} data; #ifdef __cplusplus
union
{
int rows;
int height;
}; union
{
int cols;
int width;
};
#else
int rows;
int cols;
#endif }
CvMat;
cv::Mat
class CV_EXPORTS Mat
{
public:
// constructors
Mat();
// constructs matrix of the specified size and type
// (_type is CV_8UC1, CV_64FC3, CV_32SC(12) etc.)
Mat(int _rows, int _cols, int _type);
Mat(Size _size, int _type);
// constucts matrix and fills it with the specified value _s.
Mat(int _rows, int _cols, int _type, const Scalar& _s);
Mat(Size _size, int _type, const Scalar& _s);
// copy constructor
Mat(const Mat& m);
// constructor for matrix headers pointing to user-allocated data
Mat(int _rows, int _cols, int _type, void* _data, size_t _step=AUTO_STEP);
Mat(Size _size, int _type, void* _data, size_t _step=AUTO_STEP);
// creates a matrix header for a part of the bigger matrix
Mat(const Mat& m, const Range& rowRange, const Range& colRange);
Mat(const Mat& m, const Rect& roi);
// converts old-style CvMat to the new matrix; the data is not copied by default
Mat(const CvMat* m, bool copyData=false);
// converts old-style IplImage to the new matrix; the data is not copied by default
Mat(const IplImage* img, bool copyData=false);
// builds matrix from std::vector with or without copying the data
template<typename _Tp> explicit Mat(const vector<_Tp>& vec, bool copyData=false);
// helper constructor to compile matrix expressions
Mat(const MatExpr_Base& expr);
// destructor - calls release()
~Mat();
// assignment operators
Mat& operator = (const Mat& m);
Mat& operator = (const MatExpr_Base& expr); operator MatExpr_<Mat, Mat>() const; // returns a new matrix header for the specified row
Mat row(int y) const;
// returns a new matrix header for the specified column
Mat col(int x) const;
// ... for the specified row span
Mat rowRange(int startrow, int endrow) const;
Mat rowRange(const Range& r) const;
// ... for the specified column span
Mat colRange(int startcol, int endcol) const;
Mat colRange(const Range& r) const;
// ... for the specified diagonal
// (d=0 - the main diagonal,
// >0 - a diagonal from the lower half,
// <0 - a diagonal from the upper half)
Mat diag(int d=) const;
// constructs a square diagonal matrix which main diagonal is vector "d"
static Mat diag(const Mat& d); // returns deep copy of the matrix, i.e. the data is copied
Mat clone() const;
// copies the matrix content to "m".
// It calls m.create(this->size(), this->type()).
void copyTo( Mat& m ) const;
// copies those matrix elements to "m" that are marked with non-zero mask elements.
void copyTo( Mat& m, const Mat& mask ) const;
// converts matrix to another datatype with optional scalng. See cvConvertScale.
void convertTo( Mat& m, int rtype, double alpha=, double beta= ) const; void assignTo( Mat& m, int type=- ) const; // sets every matrix element to s
Mat& operator = (const Scalar& s);
// sets some of the matrix elements to s, according to the mask
Mat& setTo(const Scalar& s, const Mat& mask=Mat());
// creates alternative matrix header for the same data, with different
// number of channels and/or different number of rows. see cvReshape.
Mat reshape(int _cn, int _rows=) const; // matrix transposition by means of matrix expressions
MatExpr_<MatExpr_Op2_<Mat, double, Mat, MatOp_T_<Mat> >, Mat>
t() const;
// matrix inversion by means of matrix expressions
MatExpr_<MatExpr_Op2_<Mat, int, Mat, MatOp_Inv_<Mat> >, Mat>
inv(int method=DECOMP_LU) const;
MatExpr_<MatExpr_Op4_<Mat, Mat, double, char, Mat, MatOp_MulDiv_<Mat> >, Mat>
// per-element matrix multiplication by means of matrix expressions
mul(const Mat& m, double scale=) const;
MatExpr_<MatExpr_Op4_<Mat, Mat, double, char, Mat, MatOp_MulDiv_<Mat> >, Mat>
mul(const MatExpr_<MatExpr_Op2_<Mat, double, Mat, MatOp_Scale_<Mat> >, Mat>& m, double scale=) const;
MatExpr_<MatExpr_Op4_<Mat, Mat, double, char, Mat, MatOp_MulDiv_<Mat> >, Mat>
mul(const MatExpr_<MatExpr_Op2_<Mat, double, Mat, MatOp_DivRS_<Mat> >, Mat>& m, double scale=) const; // computes cross-product of 2 3D vectors
Mat cross(const Mat& m) const;
// computes dot-product
double dot(const Mat& m) const; // Matlab-style matrix initialization
static MatExpr_Initializer zeros(int rows, int cols, int type);
static MatExpr_Initializer zeros(Size size, int type);
static MatExpr_Initializer ones(int rows, int cols, int type);
static MatExpr_Initializer ones(Size size, int type);
static MatExpr_Initializer eye(int rows, int cols, int type);
static MatExpr_Initializer eye(Size size, int type); // allocates new matrix data unless the matrix already has specified size and type.
// previous data is unreferenced if needed.
void create(int _rows, int _cols, int _type);
void create(Size _size, int _type);
// increases the reference counter; use with care to avoid memleaks
void addref();
// decreases reference counter;
// deallocate the data when reference counter reaches 0.
void release(); // locates matrix header within a parent matrix. See below
void locateROI( Size& wholeSize, Point& ofs ) const;
// moves/resizes the current matrix ROI inside the parent matrix.
Mat& adjustROI( int dtop, int dbottom, int dleft, int dright );
// extracts a rectangular sub-matrix
// (this is a generalized form of row, rowRange etc.)
Mat operator()( Range rowRange, Range colRange ) const;
Mat operator()( const Rect& roi ) const; // converts header to CvMat; no data is copied
operator CvMat() const;
// converts header to IplImage; no data is copied
operator IplImage() const; // returns true iff the matrix data is continuous
// (i.e. when there are no gaps between successive rows).
// similar to CV_IS_MAT_CONT(cvmat->type)
bool isContinuous() const;
// returns element size in bytes,
// similar to CV_ELEM_SIZE(cvmat->type)
size_t elemSize() const;
// returns the size of element channel in bytes.
size_t elemSize1() const;
// returns element type, similar to CV_MAT_TYPE(cvmat->type)
int type() const;
// returns element type, similar to CV_MAT_DEPTH(cvmat->type)
int depth() const;
// returns element type, similar to CV_MAT_CN(cvmat->type)
int channels() const;
// returns step/elemSize1()
size_t step1() const;
// returns matrix size:
// width == number of columns, height == number of rows
Size size() const;
// returns true if matrix data is NULL
bool empty() const; // returns pointer to y-th row
uchar* ptr(int y=);
const uchar* ptr(int y=) const; // template version of the above method
template<typename _Tp> _Tp* ptr(int y=);
template<typename _Tp> const _Tp* ptr(int y=) const; // template methods for read-write or read-only element access.
// note that _Tp must match the actual matrix type -
// the functions do not do any on-fly type conversion
template<typename _Tp> _Tp& at(int y, int x);
template<typename _Tp> _Tp& at(Point pt);
template<typename _Tp> const _Tp& at(int y, int x) const;
template<typename _Tp> const _Tp& at(Point pt) const; // template methods for iteration over matrix elements.
// the iterators take care of skipping gaps in the end of rows (if any)
template<typename _Tp> MatIterator_<_Tp> begin();
template<typename _Tp> MatIterator_<_Tp> end();
template<typename _Tp> MatConstIterator_<_Tp> begin() const;
template<typename _Tp> MatConstIterator_<_Tp> end() const; enum { MAGIC_VAL=0x42FF0000, AUTO_STEP=, CONTINUOUS_FLAG=CV_MAT_CONT_FLAG }; // includes several bit-fields:
// * the magic signature
// * continuity flag
// * depth
// * number of channels
int flags;
// the number of rows and columns
int rows, cols;
// a distance between successive rows in bytes; includes the gap if any
size_t step;
// pointer to the data
uchar* data; // pointer to the reference counter;
// when matrix points to user-allocated data, the pointer is NULL
int* refcount; // helper fields used in locateROI and adjustROI
uchar* datastart;
uchar* dataend;
};
CvMat and cv::Mat的更多相关文章
- OpenCV 3.0 CvMat and cv::Mat Conversion
After OpenCV 3.0, CvMat cannot be directly converted to cv::Mat, we need to use function cvarrToMat( ...
- Write cv::Mat to a file
如果我们想把OpenCV中的矩阵数据类型cv::Mat保存在一个文件中,可以使用如下的代码: void writeMatToFile(cv::Mat& m, const char* filen ...
- QImage 与 cv::Mat 之间的相互转换
近期做图像处理方面的项目比較多,非常多算法自己从头写的话太浪费时间,并且自己写的也不一定完好,早就听说OpenCV在图像处理算法方面功能非常强大,一直没时间学习,这次正好项目用到了.暂时抱佛脚学习些O ...
- CvArr* to cv::Mat 转换
OpenCV中的CvArr*的定义的一个空类型的指针,可以转换为其派生类CvMat和IplImage,那么如何将其转化为cv::Mat呢,其实很简单,只需要一行代码即可: // CvArr *_img ...
- openc下cv::Mat和IplImage的相互转换
opencv2.0的类CV::Mat和opencv1.0的IplImage之间烦人转换: cv::Mat matimg = cv::imread ("girl.jpg"); Ipl ...
- 访问cv::Mat中的数据时遇到的指针类型问题
在用Opencv的时候由于下图原本的图像尺寸是1111*1111,要进行resize,代码如下: cv::Mat img = cv::imread("//Users//apple//td3/ ...
- Convert between cv::Mat and QImage 两种图片类转换
在使用Qt和OpenCV混合编程时,我们有时需要在两种图片类cv::Mat和QImage之间进行转换,下面的代码参考了网上这个帖子: //##### cv::Mat ---> QImage ## ...
- cv::mat转换成QImage的问题
在进行cv::mat转换为QImage过程中,经常出现问题: cv::Mat image; ...QImage img=QImage((const unsigned char*)(image.data ...
- OpenCV图片类cv::Mat和QImage之间进行转换(好多相关文章)
在使用Qt和OpenCV混合编程时,我们有时需要在两种图片类cv::Mat和QImage之间进行转换,下面的代码参考了网上这个帖子: //##### cv::Mat ---> QImage ## ...
随机推荐
- 【转】 Mybatis/Ibatis,数据库操作的返回值
该问题,我百度了下,根本没发现什么有价值的文章:还是看源代码(详见最后附录)中的注释,最有效了!insert,返回值是:新插入行的主键(primary key):需要包含<selectKey&g ...
- cas单点注销失败Error Sending message to url endpoint
最近在做cas单点登录时,由于是单点登录.必然会涉及到单点注销,然而在做单点注销时由于对cas注销机制不了解加之测试条件所致,所有测试都是在本机下完成(机器性能较低,没用虚拟机):导致折腾了很久.网上 ...
- iOS 利用constraint实现2个控件上下的空白是相等的
说的有点乱,先看个图把 其实这个constrant的目的就是控制两个方形的控件上方和下方的空白大小. 对于每一个方块来说,他们上方和下方的空白是相同的.这种“居中”的设计到处可见.一个控件想实现这种居 ...
- centos 单独安装PHP的mysql和mysqli扩展
2013年11月22日 11:25:41 Linux centos 6.3 最小化安装 mysql 5.5 php 5.4 安装PHP时只是 ./configure --prefix=/**** 并没 ...
- java获取本机IP地址
转载自:http://blog.csdn.net/thunder09/article/details/5360251 在网上找了几个用java获取本机IP地址的代码,发现都少都有些不完美,自己整理了一 ...
- C语言字符串处理
一. C语言中,为什么字符串可以赋值给字符指针变量 char *p,a='5';p=&a; //显然是正确的,p="abcd"; ...
- CUDA学习笔记(二)——CUDA线程模型
转自:http://blog.sina.com.cn/s/blog_48b9e1f90100fm5b.html 一个grid中的所有线程执行相同的内核函数,通过坐标进行区分.这些线程有两级的坐标,bl ...
- 使用webstorm调试node程序
前言 相信大家接触过不少node代码了,如果你应用的比较初级或者针对你的项目不需要接触过深的node代码,也许你仅仅需要简单的console.log('your variable')就完全满足你的需要 ...
- zabbix_agent key 传递参数
root@(none):/etc/zabbix/zabbix_agentd.conf.d# pwd /etc/zabbix/zabbix_agentd.conf.d root@(none):/etc/ ...
- navicat使用跳板机连接数据库-ssh
1. 目标数据库的域名/IP,端口,用户名,密码:如图1 2. 这时候不要点OK!选择SSH这个tab 3. 选中User SSH Tunnel:填写跳板机域名/IP,用户名,密码(注意:端口22不要 ...