end() iterator wrong with ROI matrix header (Bug #885)


Added by Johannes Jordan about 14 years ago. Updated about 14 years ago.


Status:Done Start date:
Priority:Blocker Due date:
Assignee:Vadim Pisarevsky % Done:

0%

Category:core
Target version:-
Affected version: Operating System:
Difficulty: HW Platform:
Pull request:

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_&lt;uchar&gt; 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.


opencvtest.cpp - example code (359 Bytes) Johannes Jordan, 2011-02-14 01:37 pm


Related issues

duplicated by Bug #1128: Mat[Const]Iterator skips the last element when iterating ... Cancelled

Associated revisions

Revision 7d904146
Added by Vadim Pisarevsky almost 12 years ago

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

Also available in: Atom PDF