|
34 | 34 | print("The image path does not exist.") |
35 | 35 | continue |
36 | 36 |
|
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) |
45 | 39 |
|
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))) |
48 | 62 | for item in items: |
49 | 63 | format_type = item.get_format_string() |
50 | 64 | text = item.get_text() |
|
67 | 81 | print("({}, {})".format(x4, y4)) |
68 | 82 | print("-------------------------------------------------") |
69 | 83 |
|
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))) |
81 | 86 |
|
82 | 87 | input("Press Enter to quit...") |
0 commit comments