MCPcopy Create free account
hub / github.com/Mrinank-Bhowmick/python-beginner-projects / decoder

Function decoder

projects/QRCode Scanner/main.py:6–27  ·  view source on GitHub ↗
(image)

Source from the content-addressed store, hash-verified

4
5
6def decoder(image):
7 # Creating a black and white style image to avoid confusion
8 gray_img = cv2.cvtColor(image, 0)
9 # Decoding the gray image to some binary image matrix
10 barcode = decode(gray_img)
11
12 # Algorithm to scan the obtained image
13 for obj in barcode:
14 points = obj.polygon
15 (x, y, w, h) = obj.rect
16 pts = np.array(points, np.int32)
17 pts = pts.reshape((-1, 1, 2))
18 cv2.polylines(image, [pts], True, (0, 255, 0), 3)
19
20 barcodeData = obj.data.decode("utf-8")
21 barcodeType = obj.type
22 string = "Data " + str(barcodeData) + " | Type " + str(barcodeType)
23
24 cv2.putText(
25 frame, string, (x, y), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (255, 0, 0), 2
26 )
27 print("Barcode: " + barcodeData + " | Type: " + barcodeType)
28
29
30# Getting user's choice of usage

Callers 1

main.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected