opencv_contrib
opencv_contrib copied to clipboard
Divide by zero error in calCoherence() method (opencv_contrib/modules/barcode/src/detector/bardetect.cpp) if the event window_size value is zero
System information (version)
- OpenCV => 4.6.0
- Operating System / Platform => Ubuntu 20.04
- Compiler => g++
Detailed description
Steps to reproduce
Use an image with width 47 pixels and height 160 pixels (any image with width or height less than 100 pixels would work). 47x160 is the image size with which I found the issue.
I followed the steps listed in this doc to run bar code detection and decoding from the following tutorial https://opencv.org/recognizing-one-dimensional-barcode-using-opencv/
import cv2
bardet = cv2.barcode_BarcodeDetector() img = cv2.imread("your file path") ok, decoded_info, decoded_type, corners = bardet.detectAndDecode(img)
The above code results in floating point error (due to divide by zero error when window_size is 0 in calCoherence() method
Issue submission checklist
- [x] I report the issue, it's not a question
- [x] I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
- [x] I updated to the latest OpenCV version and the issue is still there
- [x] There is reproducer code and related data files: videos, images, onnx, etc

I made a fix to the above issue and created a PR
#3331 https://github.com/opencv/opencv_contrib/pull/3331