-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathcamera_async_api.py
More file actions
61 lines (46 loc) · 1.58 KB
/
camera_async_api.py
File metadata and controls
61 lines (46 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import barcodeQrSDK
import numpy as np
import cv2
import json
g_results = None
def callback(results):
global g_results
g_results = (results)
def run():
# set license
barcodeQrSDK.initLicense(
"DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==")
# initialize barcode scanner
scanner = barcodeQrSDK.createInstance()
params = scanner.getParameters()
# Convert string to JSON object
json_obj = json.loads(params)
params = json.dumps(json_obj)
ret = scanner.setParameters(params)
scanner.addAsyncListener(callback)
cap = cv2.VideoCapture(0)
while True:
ret, image = cap.read()
if image is not None:
scanner.decodeMatAsync(image)
if g_results != None:
for result in g_results:
x1 = result.x1
y1 = result.y1
x2 = result.x2
y2 = result.y2
x3 = result.x3
y3 = result.y3
x4 = result.x4
y4 = result.y4
cv2.drawContours(
image, [np.array([(x1, y1), (x2, y2), (x3, y3), (x4, y4)], dtype=np.int32)], 0, (0, 255, 0), 2)
cv2.putText(image, result.text, (x1, y1),
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
cv2.imshow('Barcode QR Code Scanner', image)
ch = cv2.waitKey(1)
if ch == 27:
break
scanner.clearAsyncListener()
if __name__ == '__main__':
run()