Im trying to detect and decode barcode. My program works well but with this one barcode i have a problem because of weird background. If you know what operations performed on images will be able to reveal this code i will be grateful. Im attaching a mentioned photo and part of the code responsible for barcode detection.
gray = cv2.cvtColor(cropped_image, cv2.COLOR_RGB2GRAY)
gray = cv2.threshold(gray, 0, 255, cv2.THRESH_OTSU)[1]
(h, w) = gray.shape[:2]
point1 = int(0.75 * w)
point2 = int(0.25 * h)
point3 = int(0.98 * w)
point4 = int(0.8 * h)
start_point = (point1, point2)
end_point = (point3, point4)
color = (255, 0, 0)
thickness = 2
gray = gray[point2:point4, point1:point3]
barcodes = decode(gray)
for barcode in barcodes:
barcode_data = barcode.data.decode("utf-8")
barcode_type = barcode.type
print("Barcode Data:", barcode_data)
print("Barcode Type:", barcode_type)
(x, y, w, h) = barcode.rect
cv2.rectangle(cropped_image, (x, y), (x + w, y + h), (255, 0, 0), 2)
cv2.imshow('barcode', cropped_image)
cv2.waitKey(0)
I tried some operations on image but i ve never had problem like that in past.
New contributor
filipoo635 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.