mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 15:23:05 +04:00
Fix signed integer overflow in connected components
This commit is contained in:
@@ -145,14 +145,21 @@ namespace cv{
|
||||
void finish(){
|
||||
for (int l = 0; l < statsv.rows; ++l){
|
||||
int *row =& statsv.at<int>(l, 0);
|
||||
row[CC_STAT_WIDTH] = row[CC_STAT_WIDTH] - row[CC_STAT_LEFT] + 1;
|
||||
row[CC_STAT_HEIGHT] = row[CC_STAT_HEIGHT] - row[CC_STAT_TOP] + 1;
|
||||
|
||||
Point2ui64& integral = integrals[l];
|
||||
double *centroid = ¢roidsv.at<double>(l, 0);
|
||||
double area = ((unsigned*)row)[CC_STAT_AREA];
|
||||
centroid[0] = double(integral.x) / area;
|
||||
centroid[1] = double(integral.y) / area;
|
||||
double *centroid = ¢roidsv.at<double>(l, 0);
|
||||
if (area > 0){
|
||||
row[CC_STAT_WIDTH] = row[CC_STAT_WIDTH] - row[CC_STAT_LEFT] + 1;
|
||||
row[CC_STAT_HEIGHT] = row[CC_STAT_HEIGHT] - row[CC_STAT_TOP] + 1;
|
||||
Point2ui64& integral = integrals[l];
|
||||
centroid[0] = double(integral.x) / area;
|
||||
centroid[1] = double(integral.y) / area;
|
||||
} else {
|
||||
row[CC_STAT_WIDTH] = 0;
|
||||
row[CC_STAT_HEIGHT] = 0;
|
||||
row[CC_STAT_LEFT] = -1;
|
||||
centroid[0] = std::numeric_limits<double>::quiet_NaN();
|
||||
centroid[1] = std::numeric_limits<double>::quiet_NaN();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user