end() iterator wrong with ROI matrix header (Bug #885)
Description
1. Create a matrix header B as a subregion of the original matrix A.
2. Let the subregion B have less columns than A.
3. Iterate through B with MatIterator.
4. B.end() is 1 pixel off. Last pixel in B is not traversed.
Sample code:
#include <cv.h>
#include <highgui.h>
using namespace cv;
int main(int arg, char** argv)
{
Mat1b data(23, 42);
data.setTo(0);
Rect roi(0, 0, data.cols - 1, data.rows);
Mat1b data_roi(data, roi);
MatIterator_<uchar> it;
for (it = data_roi.begin(); it != data_roi.end(); ++it)
*it = 255;
imshow("data", data);
waitKey();
return 0;
}
You can observe that the pixel in the down-right corner stays black. Same effect with other ROIs, e.g.
Rect roi(2, 2, data.cols - 4, data.rows - 4);
This is a major bummer, you can never trust your iterators if you don't know the origin of your matrix header.
Related issues
duplicated by Bug #1128: Mat[Const]Iterator skips the last element when iterating ... | Cancelled |
Associated revisions
Merge pull request #885 from pengx17:2.4_bfmatcher_ocl
History
Updated by Vadim Pisarevsky about 14 years ago
in the current SVN version the sample works as expected: data_roi.at<uchar>(data_roi.rows-1, data_roi.cols-1) == 255.
- Status changed from Open to Done
- (deleted custom field) set to worksforme