您的位置:首页 > 运维架构

OpenCV基本数据类型

2012-06-04 08:37 288 查看
Point_[cpp] view plaincopytypedef Point_<int> Point2i;
typedef Point2i Point;
typedef Point_<float> Point2f;
typedef Point_<double> Point2d;

Point3_[cpp] view plaincopytypedef Point3_<int> Point3i;
typedef Point3_<float> Point3f;
typedef Point3_<double> Point3d;

Size_[html] view plaincopytypedef Size_<int> Size2i;
typedef Size2i Size;
typedef Size_<float> Size2f;

Rect_[cpp] view plaincopytypedef Rect_<int> Rect;

Matx[cpp] view plaincopytypedef Matx<float,1,2> Matx12f;
typedef Matx<double,1,2> Matx12d;
...

Vec[cpp] view plaincopytypedef Vec<uchar, 2> Vec2b;
typedef Vec<short,3> Vec3s;
typedef Vec<int, 4> Vec4i;
typddef Vec<float,6> Vec6i;
...

Scalar_[cpp] view plaincopytypedef Scalar_<double> Scalar;

Range[cpp] view plaincopyclass Range
{
public:
...
int start, end;
};

ex:取A的全部行,和 1到179列[cpp] view plaincopyMat A = imread("b.jpg", CV_LOAD_IMAGE_COLOR);
Mat B = A(Range::all(), Range(1, 180));
Mat创建复杂的矩阵[cpp] view plaincopy// 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));
多维数组[cpp] view plaincopy// create a 100x100x100 8-bit array
int sz[] = {100, 100, 100};
Mat bigCube(3, sz, CV_8U, Scalar::all(0));
矩阵行操作[cpp] view plaincopy// add the 5-th row, multiplied by 3 to the 3rd row
M.row(3) = M.row(3) + M.row(5)*3;

矩阵列操作[cpp] view plaincopy// 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使用[cpp] view plaincopyMat 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)

矩阵元素访问:指针加[ ] [cpp] view plaincopyint sum = 0;
Mat M = Mat::eye(20, 20, CV_8UC1);
for (int i=0; i < M.rows; i++)
{
const uchar* mi = M.ptr<uchar>(i);
for (int j=0; j < M.cols; j++)
{
sum += mi[j];
}
}

迭代[cpp] view plaincopyMatConstIterator_<uchar> it = M.begin<uchar>(), it_end = M.end<uchar>();
for (; it != it_end; ++it)
sum += *it;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: