Skip to content

Commit 493adb1

Browse files
committed
adds autoscaling of resized images
1 parent fb79c6a commit 493adb1

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

qr_code_extractor.py

+19-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
def get_qr_data(file, debug_show_image=False):
55
position_marker_coordinates = None
6+
max_pixels = 600
67
input_image = cv2.imread(file, cv2.IMREAD_COLOR)
78
payload, bounding_box, rectified_image = cv2.QRCodeDetector().detectAndDecode(input_image)
89

@@ -11,9 +12,24 @@ def get_qr_data(file, debug_show_image=False):
1112

1213
if debug_show_image:
1314
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)
1733
cv2.waitKey(0)
1834

1935
return payload, position_marker_coordinates

0 commit comments

Comments
 (0)