Skip to content

Commit e9e5070

Browse files
authored
Merge pull request #2937 from scloke:patch-1
* Divide by zero error in SEEDS Superpixels #2935 When processing a large number of images, a program crash can occur with a divide by zero error in the above function. Changing the order of multiplication / division avoids a division by zero. * Update seeds.cpp Minor corrections
1 parent 76dde8f commit e9e5070

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

modules/ximgproc/src/seeds.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ class SuperpixelSEEDSImpl : public SuperpixelSEEDS
136136
//compute initial label for sublevels: level <= seeds_top_level
137137
//this is an equally sized grid with size nr_h[level]*nr_w[level]
138138
int computeLabel(int level, int x, int y) {
139-
return std::min(y / (height / nr_wh[2 * level + 1]), nr_wh[2 * level + 1] - 1) * nr_wh[2 * level]
140-
+ std::min((x / (width / nr_wh[2 * level])), nr_wh[2 * level] - 1);
139+
return std::min(y * nr_wh[2 * level + 1] / height, nr_wh[2 * level + 1] - 1) * nr_wh[2 * level]
140+
+ std::min(x * nr_wh[2 * level] / width, nr_wh[2 * level] - 1);
141141
}
142142
inline int nrLabels(int level) const {
143143
return nr_wh[2 * level + 1] * nr_wh[2 * level];

0 commit comments

Comments
 (0)