Skip to content

Divide by zero error in SEEDS Superpixels #2935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
scloke opened this issue Apr 29, 2021 · 1 comment
Closed

Divide by zero error in SEEDS Superpixels #2935

scloke opened this issue Apr 29, 2021 · 1 comment

Comments

@scloke
Copy link
Contributor

scloke commented Apr 29, 2021

  • OpenCV => 4.2
  • Operating System / Platform => Windows 64 Bit
  • Compiler =>Visual Studio 2019
Detailed description

For opencv_contrib/modules/ximgproc/src/seeds.cpp
lines 136-141

//compute initial label for sublevels: level <= seeds_top_level
//this is an equally sized grid with size nr_h[level]*nr_w[level]
int computeLabel(int level, int x, int y) {
    return std::min(y / (height / nr_wh[2 * level + 1]), nr_wh[2 * level + 1] - 1) * nr_wh[2 * level]
            + std::min((x / (width / nr_wh[2 * level])), nr_wh[2 * level] - 1);
}

When processing a large number of images, a program crash can occur with a divide by zero error in the above function. This can be rectified by changing to the following:

//compute initial label for sublevels: level <= seeds_top_level
//this is an equally sized grid with size nr_h[level]*nr_w[level]
int computeLabel(int level, int x, int y) {
    return std::min(y * nr_wh[2 * level + 1] / height), nr_wh[2 * level + 1] - 1) * nr_wh[2 * level]
            + std::min((x * nr_wh[2 * level] / width)), nr_wh[2 * level] - 1);
}
@alalek
Copy link
Member

alalek commented Apr 29, 2021

Feel free to prepare PR with proposed fix (onto 3.4 branch if applicable)

scloke added a commit to scloke/opencv_contrib that referenced this issue Apr 30, 2021
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants