OpenCV barcode detection is detecting edge of sticker causing failure in barcode decode

Viewed 49

I am using OpenCV to detect barcodes in the image below, but for some reason, the detection bounding box it provides is including the edge of the sticker the barcode is on, which then when I go to decode the detections, I get no results.

Am I doing wrong? How can I have OpenCV detect the barcode inside of the white sticker?

Code I am using:

import cv2
import numpy as np

image = cv2.imread('image/path/image.jpg')

det = cv2.barcode.BarcodeDetector()
(rv, detections) = det.detect(image)

for barcode in detections:
    cv2.polylines(image, [np.int32(barcode)], isClosed=True, color=(0, 0, 255), thickness=2)

cv2.imshow('Image', image)
cv2.waitKey(0)

Original Image Original Image

Detected Image / Script Output Detected Image

0 Answers
Related