博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
OpenCV学习笔记(一)____OpenCV基本数据类型
阅读量:7011 次
发布时间:2019-06-28

本文共 2194 字,大约阅读时间需要 7 分钟。

hot3.png

Point_

typedef Point_
 Point2i;typedef Point2i Point;typedef Point_
 Point2f;typedef Point_
 Point2d;

Point3_

typedef Point3_
 Point3i;typedef Point3_
 Point3f;typedef Point3_
 Point3d;

Size_

typedef Size_
 Size2i;typedef Size2i Size;typedef Size_
 Size2f;

Rect_

typedef Rect_
 Rect;

Matx

typedef Matx
 Matx12f;typedef Matx
 Matx12d;...

Vec

typedef Vec
 Vec2b;typedef Vec
 Vec3s;typedef Vec
 Vec4i;typddef Vec
 Vec6i;...

Scalar_

typedef Scalar_
 Scalar;

Range

class Range{public:...int start, end;};

ex:取A的全部行,和 1到180列

Mat A = imread("b.jpg", CV_LOAD_IMAGE_COLOR);	Mat B = A(Range::all(), Range(1, 180));

Mat

创建复杂的矩阵

// make a 7x7 complex matrix filled with 1+3j.	Mat M(7,7,CV_32FC2,Scalar(1,3));	// and now turn M to a 100x60 15-channel 8-bit matrix.	// The old content will be deallocated	M.create(100,60,CV_8UC(15));

多维数组

// create a 100x100x100 8-bit array	int sz[] = {100, 100, 100};	Mat bigCube(3, sz, CV_8U, Scalar::all(0));

矩阵行操作

// add the 5-th row, multiplied by 3 to the 3rd row	M.row(3) = M.row(3) + M.row(5)*3;

矩阵列操作

// now copy the 7-th column to the 1-st column	// M.col(1) = M.col(7); // this will not work	Mat M1 = M.col(1);	M.col(7).copyTo(M1);

locateROI使用

Mat A = Mat::eye(10, 10, CV_32S);	// extracts A columns, 1 (inclusive) to 3 (exclusive).	Mat B = A(Range::all(), Range(1, 3));	// extracts B rows, 5 (inclusive) to 9 (exclusive).	// that is, C ~ A(Range(5, 9), Range(1, 3))	Mat C = B(Range(5, 9), Range::all());	Size size; Point ofs;	C.locateROI(size, ofs);	// size will be (width=10,height=10) and the ofs will be (x=1, y=5)

矩阵元素访问:

指针加[ ] 

int sum = 0;	Mat M = Mat::eye(20, 20, CV_8UC1);	for (int i=0; i < M.rows; i++)	{		const uchar* mi = M.ptr
(i); for (int j=0; j < M.cols; j++) { sum += mi[j]; } }

迭代

MatConstIterator_
 it = M.begin
(), it_end = M.end
(); for (; it != it_end; ++it) sum += *it;

转载于:https://my.oschina.net/baiyunpiaopiao/blog/402234

你可能感兴趣的文章