简体   繁体   中英

opencv: is Mat(vector<Point2f>) yelding a wrong matrix header?

i believe that header generated for Mat(vector) is wrong, it prints the matrix as a Nx2 matrix, however the col attribute is set to 2.

i didn't confirm if it is the reason for any operation that needs a copy of this new matrix or just a submatrix will fail.

a simple example would be obtain a selection over this new matrix: (Range(0,N), Range(0,1)) would select the first two columns but instead, only the first one is selected (the second member of the range operator is exclusive)

i don't see your problem, actually Mat(vector<Point2f>) is a N-row, 1-col, 2-chan matrix, and the selection over the ranges returns the N first rows :

vector<Point2f> cp; 
cp.push_back(Point2f(1,1));
cp.push_back(Point2f(2,2));
cp.push_back(Point2f(3,3));

Mat m(cp);


cerr << m.rows << " " << m.cols << " "<< m.channels() << endl;
cerr << m << endl;

int N=2;
Mat m2 = m(Range(0,N), Range(0,1));

cerr << m2.rows << " " << m2.cols << " "<< m2.channels() << endl;
cerr << m2 << endl;

3 1 2
[1, 1; 2, 2; 3, 3]
2 1 2
[1, 1; 2, 2]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM