opencv_contrib icon indicating copy to clipboard operation
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

Open kishorgandham opened this issue 3 years ago • 1 comments

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 2308e3cd17da75cafc652cec781db0b4

kishorgandham avatar Aug 21 '22 06:08 kishorgandham

I made a fix to the above issue and created a PR

#3331 https://github.com/opencv/opencv_contrib/pull/3331

kishorgandham avatar Aug 21 '22 06:08 kishorgandham