Skip to content

Commit a46093d

Browse files
committed
Replaced capture with capture_multi_pages
1 parent 232548a commit a46093d

3 files changed

Lines changed: 906 additions & 22 deletions

File tree

examples/official/camera_file/file.py

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,31 @@
3434
print("The image path does not exist.")
3535
continue
3636

37-
cv_image = cv2.imread(image_path)
38-
result = cvr_instance.capture(
39-
cv_image, EnumPresetTemplate.PT_READ_BARCODES.value)
40-
if result.get_error_code() != EnumErrorCode.EC_OK:
41-
print("Error:", result.get_error_code(),
42-
result.get_error_string())
43-
else:
44-
37+
result_array = cvr_instance.capture_multi_pages(
38+
image_path, EnumPresetTemplate.PT_READ_BARCODES_READ_RATE_FIRST.value)
4539

46-
items = result.get_items()
47-
print('Found {} barcodes.'.format(len(items)))
40+
results = result_array.get_results()
41+
if results is None or len(results) == 0:
42+
print("No pages were processed.")
43+
continue
44+
45+
total_barcodes = 0
46+
for page_result in results:
47+
page_number = 1
48+
tag = page_result.get_original_image_tag()
49+
if isinstance(tag, FileImageTag):
50+
page_number = tag.get_page_number() + 1
51+
52+
if page_result.get_error_code() != EnumErrorCode.EC_OK and \
53+
page_result.get_error_code() != EnumErrorCode.EC_UNSUPPORTED_JSON_KEY_WARNING:
54+
print("Page", page_number, "Error:",
55+
page_result.get_error_code(),
56+
page_result.get_error_string())
57+
continue
58+
59+
items = page_result.get_items()
60+
total_barcodes += len(items)
61+
print("Page {}: found {} barcode(s).".format(page_number, len(items)))
4862
for item in items:
4963
format_type = item.get_format_string()
5064
text = item.get_text()
@@ -67,16 +81,7 @@
6781
print("({}, {})".format(x4, y4))
6882
print("-------------------------------------------------")
6983

70-
pts = np.array([(x1, y1), (x2, y2), (x3, y3), (x4, y4)], np.int32).reshape((-1, 1, 2))
71-
cv2.drawContours(
72-
cv_image, [pts], 0, (0, 255, 0), 2)
73-
74-
cv2.putText(cv_image, text, (x1, y1 - 10),
75-
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)
76-
77-
cv2.imshow(
78-
"Original Image with Detected Barcodes", cv_image)
79-
cv2.waitKey(0)
80-
cv2.destroyAllWindows()
84+
print("Total: {} barcode(s) across {} page(s).".format(
85+
total_barcodes, len(results)))
8186

8287
input("Press Enter to quit...")

0 commit comments

Comments
 (0)