Mat_<_Tp>::end() iterator pointer yields wrong address for subregioned matrices. (Bug #72)
Description
Hi,
I need to get a matrix header for a subregion of a matrix. I'm doing something like
Mat_<_Tp> sub = Mat_<_Tp>(roi.height, roi.width, &org_mat(roi.y, roi.x), org_mat.cols * sizeof(_Tp));
which works ok. That is... until I start to use an iterator:
Mat_<_Tp>::iterator it = sub.begin(); Mat_<_Tp>::iterator itend = sub.end(); while(it != itend) { // Do something with *it it++; }
which fails, because 'it' is never equal to 'itend'. As far as I can see, it is line 499 and 485 in cxmat.hpp that should be changed from
it.ptr = it.sliceEnd = (_Tp*)(data + step*(rows-1)) + cols;
to
it.ptr = it.sliceEnd = (_Tp*)(data + step*rows);
No, I have not tested this extensively, but my code works if I insert
itend.ptr = itend.sliceEnd = (_Tp*)(sub.data + sub.step*sub.rows);
I hope that someone with a deeper insight to OpenCV will take a look at this and check that my solution proposal will work with the rest of the library.
Ps.: For now I (and other users in the same position) can use the constellation "while(it < itend)" instead for own loops.
Related issues
duplicated by Bug #87: Wrong iterator work when iteration through non-continious... | Cancelled |
Associated revisions
Merge pull request #72 from melody-rain:2_4_knearest_neighbor
History
Updated by anonymous - about 15 years ago
thank you! The problem should have been fixed in r2613
- Status changed from Open to Done
- (deleted custom field) set to fixed