I've met a couple of times before. Due to a row and column error causing the pointer to go out of bounds, here are some of the things I've summarized:
Condition one (definition iplimage*):
IPLIMAGE*DST = NULL;
DST =cvcreateimage (cvsize), ipl_depth_8u, 3);
The DST created here is 480 rows and 600 columns, preceded by a row.
Situation two (definition mat):
Mat DST;
DST =mat (CV_8UC3);
The DST created here is also 480 rows and 600 columns, but the first column.
Situation three (defining areas of interest):
Rectroi_rect;
roi_rect.x=10;
roi_rect.y=20;
This represents the coordinate (x,y) of the upper-left pixel of the defined area of interest (rectangle) (10,20), which is in row 20th, column 10th.
These details are important, and when you traverse a picture using nested for loops, there is a good chance that if you don't pay attention to the details of the rows and columns, there is a high likelihood of errors in the pointer crossing.
--------------------------------------------------------------------------------------------------------------- --------------------
2016.11.03 Supplements
--------------------------------------------------------------------------------------------------------------- --------------------
Yesterday, the lab students found the following situation:
Use
Mat img = Mat (cv::size (), CV_8UC3);
The img defined is 600 rows, 480 columns.
And the situation I mentioned above two is defined by 480 lines, 600 columns ... Note the use of cv::size.
Special attention should be paid here.