3
3
4
4
def get_qr_data (file , debug_show_image = False ):
5
5
position_marker_coordinates = None
6
+ max_pixels = 600
6
7
input_image = cv2 .imread (file , cv2 .IMREAD_COLOR )
7
8
payload , bounding_box , rectified_image = cv2 .QRCodeDetector ().detectAndDecode (input_image )
8
9
@@ -11,9 +12,24 @@ def get_qr_data(file, debug_show_image=False):
11
12
12
13
if debug_show_image :
13
14
cv2 .circle (input_image , position_marker_coordinates , 10 , (0 , 255 , 0 ), - 1 )
14
- cv2 .namedWindow ('highlighted image' , cv2 .WINDOW_KEEPRATIO )
15
- cv2 .resizeWindow ('highlighted image' , 1280 , 960 )
16
- cv2 .imshow ("highlighted image" , input_image )
15
+
16
+ base = input_image .shape [0 ]
17
+ if base < input_image .shape [1 ]:
18
+ base = input_image .shape [1 ]
19
+
20
+ if max_pixels > input_image .shape [0 ] and max_pixels > input_image .shape [1 ]:
21
+ scale_percent = 100.0 # percent of original size
22
+ else :
23
+ scale_percent = max_pixels / base * 100.0
24
+
25
+ width = int (input_image .shape [1 ] * scale_percent / 100 )
26
+ height = int (input_image .shape [0 ] * scale_percent / 100 )
27
+ dim = (width , height )
28
+
29
+ # resize image
30
+ resized = cv2 .resize (input_image , dim , interpolation = cv2 .INTER_AREA )
31
+
32
+ cv2 .imshow ("highlighted image" , resized )
17
33
cv2 .waitKey (0 )
18
34
19
35
return payload , position_marker_coordinates
0 commit comments