1
1
import barcodeQrSDK
2
2
import numpy as np
3
-
4
- # set license
5
- barcodeQrSDK .initLicense ("DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==" )
6
-
7
- # initialize barcode scanner
8
- scanner = barcodeQrSDK .createInstance ()
3
+ import cv2
9
4
10
5
g_results = None
11
6
12
7
def callback (results ):
13
- global g_results
8
+ global g_results
14
9
g_results = results
15
-
16
- import cv2
17
- scanner .addAsyncListener (callback )
18
10
19
- cap = cv2 .VideoCapture (0 )
20
- while True :
21
- ret , image = cap .read ()
22
- if image is not None :
23
- scanner .decodeMatAsync (image )
24
-
25
- if g_results != None :
26
- for result in g_results :
27
- print ("barcode format: " + result .format )
28
- print ("barcode value: " + result .text )
29
- x1 = result .x1
30
- y1 = result .y1
31
- x2 = result .x2
32
- y2 = result .y2
33
- x3 = result .x3
34
- y3 = result .y3
35
- x4 = result .x4
36
- y4 = result .y4
37
-
38
- cv2 .drawContours (image , [np .int0 ([(x1 , y1 ), (x2 , y2 ), (x3 , y3 ), (x4 , y4 )])], 0 , (0 , 255 , 0 ), 2 )
39
-
11
+ def run ():
12
+ # set license
13
+ barcodeQrSDK .initLicense ("DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==" )
40
14
41
- cv2 .imshow ('Barcode QR Code Scanner' , image )
42
- ch = cv2 .waitKey (1 )
43
- if ch == 27 :
44
- break
15
+ # initialize barcode scanner
16
+ scanner = barcodeQrSDK .createInstance ()
17
+ scanner .addAsyncListener (callback )
45
18
19
+ cap = cv2 .VideoCapture (0 )
20
+ while True :
21
+ ret , image = cap .read ()
22
+ if image is not None :
23
+ scanner .decodeMatAsync (image )
24
+
25
+ if g_results != None :
26
+ for result in g_results :
27
+ print ("barcode format: " + result .format )
28
+ print ("barcode value: " + result .text )
29
+ x1 = result .x1
30
+ y1 = result .y1
31
+ x2 = result .x2
32
+ y2 = result .y2
33
+ x3 = result .x3
34
+ y3 = result .y3
35
+ x4 = result .x4
36
+ y4 = result .y4
37
+
38
+ cv2 .drawContours (image , [np .int0 ([(x1 , y1 ), (x2 , y2 ), (x3 , y3 ), (x4 , y4 )])], 0 , (0 , 255 , 0 ), 2 )
39
+
46
40
41
+ cv2 .imshow ('Barcode QR Code Scanner' , image )
42
+ ch = cv2 .waitKey (1 )
43
+ if ch == 27 :
44
+ break
45
+
46
+ scanner .clearAsyncListener ()
47
47
48
+ if __name__ == '__main__' :
49
+ run ()
0 commit comments