@@ -21,32 +21,53 @@ def get_time():
2121
2222def read_barcode ():
2323 global results
24- video_width = 640
25- video_height = 480
26-
24+ video_width = 0
25+ video_height = 0
26+ testVideo = r"D:\Work\TestVideoOrImage\QQ视频20191202145135.mp4"
27+
28+ # vc = cv2.VideoCapture(testVideo)
2729 vc = cv2 .VideoCapture (0 )
30+ video_width = vc .get (cv2 .CAP_PROP_FRAME_WIDTH )
31+ video_height = vc .get (cv2 .CAP_PROP_FRAME_HEIGHT )
2832 vc .set (3 , video_width ) #set width
2933 vc .set (4 , video_height ) #set height
3034
35+ stride = 0
3136 if vc .isOpened ():
32- dbr .InitLicense ('LICENSE-KEY ' )
37+ dbr .InitLicense ('Input your license ' )
3338 rval , frame = vc .read ()
39+ stride = frame .strides [0 ]
3440 else :
3541 return
3642
3743 windowName = "Barcode Reader"
38-
39- max_buffer = 2
40- max_results = 10
41- image_format = 1 # 0: gray; 1: rgb888
42-
43- dbr .StartVideoMode (max_buffer , max_results , video_width , video_height , image_format , onBarcodeResult )
44-
44+ parameters = dbr .InitFrameDecodingParameters ()
45+ parameters ["MaxQueueLength" ] = 30
46+ parameters ["MaxResultQueueLength" ] = 30
47+ parameters ["Width" ] = video_width
48+ parameters ["Height" ] = video_height
49+ parameters ["Stride" ] = stride
50+ parameters ["ImagePixelFormat" ] = dbr .IPF_RGB_888
51+ parameters ["RegionTop" ] = 0
52+ parameters ["RegionLeft" ] = 0
53+ parameters ["RegionRight" ] = 100
54+ parameters ["RegionBottom" ] = 100
55+ parameters ["RegionMeasuredByPercentage" ] = 1
56+ parameters ["Threshold" ] = 0.01
57+ parameters ["FPS" ] = 0
58+
59+
60+ dbr .StartVideoMode (parameters , onBarcodeResult )
61+
62+ count = 0
4563 while True :
4664 if results != None :
47- thickness = 2
48- color = (0 ,255 ,0 )
65+ # thickness = 2
66+ # color = (0,255,0)
4967 for result in results :
68+ # print("barcode format: " + result[0])
69+ # print("barcode text: " + result[1])
70+ print ("barcode format: " + str (result ["BarcodeFormat" ]))
5071 print ("barcode format: " + result ["BarcodeFormatString" ])
5172 print ("barcode text: " + result ["BarcodeText" ])
5273 localizationResult = result ["LocalizationResult" ]
@@ -58,35 +79,44 @@ def read_barcode():
5879 y3 = localizationResult ["Y3" ]
5980 x4 = localizationResult ["X4" ]
6081 y4 = localizationResult ["Y4" ]
82+ localizationPoints = [(x1 ,y1 ),(x2 ,y2 ),(x3 ,y3 ),(x4 ,y4 )]
83+ print (localizationPoints )
6184
62- cv2 .line (frame , (x1 , y1 ), (x2 , y2 ), color , thickness )
63- cv2 .line (frame , (x2 , y2 ), (x3 , y3 ), color , thickness )
64- cv2 .line (frame , (x3 , y3 ), (x4 , y4 ), color , thickness )
65- cv2 .line (frame , (x4 , y4 ), (x1 , y1 ), color , thickness )
66-
85+ # cv2.line(frame, (x1, y1), (x2, y2), color, thickness)
86+ # cv2.line(frame, (x2, y2), (x3, y3), color, thickness)
87+ # cv2.line(frame, (x3, y3), (x4, y4), color, thickness)
88+ # cv2.line(frame, (x4, y4), (x1, y1), color, thickness)
6789 results = None
6890
69- cv2 .imshow (windowName , frame )
7091 rval , frame = vc .read ()
71-
92+ if rval == False :
93+ break
94+ # cv2.imshow(windowName, frame)
95+
96+ # if count == 1000:
97+ # break
98+ # else:
99+ # count = count + 1
100+ # print(count)
72101 # start = time.time()
73102 try :
74103 ret = dbr .AppendVideoFrame (frame )
75104 except :
76105 pass
106+
77107
78108 # cost = (time.time() - start) * 1000
79109 # print('time cost: ' + str(cost) + ' ms')
80-
81110 # 'ESC' for quit
82- key = cv2 .waitKey (1 )
83- if key == 27 :
84- break
111+ # key = cv2.waitKey(1)
112+ # if key == 27:
113+ # break
85114
86115 dbr .StopVideoMode ()
87- cv2 .destroyWindow (windowName )
116+ # cv2.destroyWindow(windowName)
88117
89118
90119if __name__ == "__main__" :
91120 print ("OpenCV version: " + cv2 .__version__ )
92121 read_barcode ()
122+ print ("over" )
0 commit comments