1 | initial version |
I think problem is here :
int nmask = connectedComponentsWithStats(mask, labels, stats, centroids, 4, CV_16U);
stats.convertTo(stats, CV_8U);
when you convert in uchar some values are saturate because leftmost (or topmost) coordinate can be greater than 255 :
CC_STAT_LEFT
The leftmost (x) coordinate which is the inclusive start of the bounding box in the horizontal direction.
CC_STAT_TOP
The topmost (y) coordinate which is the inclusive start of the bounding box in the vertical direction.
CC_STAT_WIDTH
The horizontal size of the bounding box.
CC_STAT_HEIGHT
The vertical size of the bounding box.
CC_STAT_AREA
The total area (in pixels) of the connected component.
Don't convert in CV_8U : int* data = stats.ptr<int>(i);
2 | No.2 Revision |
I think problem is here :
int nmask = connectedComponentsWithStats(mask, labels, stats, centroids, 4, CV_16U);
stats.convertTo(stats, CV_8U);
when you convert in uchar some values are saturate because leftmost (or topmost) coordinate can be greater than 255 :
CC_STAT_LEFT
The leftmost (x) coordinate which is the inclusive start of the bounding box in the horizontal direction.
CC_STAT_TOP
The topmost (y) coordinate which is the inclusive start of the bounding box in the vertical direction.
CC_STAT_WIDTH
The horizontal size of the bounding box.
CC_STAT_HEIGHT
The vertical size of the bounding box.
CC_STAT_AREA
The total area (in pixels) of the connected component.
Don't convert in CV_8U :
:
int* data = stats.ptr<int>(i);stats.ptr<int>(i);