|
29 | 29 | if not os.path.exists(image_path): |
30 | 30 | print("The image path does not exist.") |
31 | 31 | continue |
| 32 | + |
32 | 33 | result = cvr.capture( |
33 | 34 | image_path, EnumPresetTemplate.PT_DETECT_AND_NORMALIZE_DOCUMENT.value) |
34 | 35 | if result.get_error_code() != EnumErrorCode.EC_OK: |
35 | 36 | print("Error:", result.get_error_code(), |
36 | 37 | result.get_error_string()) |
37 | | - normalized_images_result = result.get_normalized_images_result() |
38 | | - if normalized_images_result is None or len(normalized_images_result.get_items()) == 0: |
| 38 | + processed_document_result = result.get_processed_document_result() |
| 39 | + if processed_document_result is None or len(processed_document_result.get_deskewed_image_result_items()) == 0: |
39 | 40 | print("No normalized documents.") |
40 | 41 | else: |
41 | | - items = normalized_images_result.get_items() |
| 42 | + items = processed_document_result.get_deskewed_image_result_items() |
42 | 43 | print("Normalized", len(items), "documents.") |
43 | | - for index, item in enumerate(normalized_images_result.get_items()): |
| 44 | + for index, item in enumerate(processed_document_result.get_deskewed_image_result_items()): |
44 | 45 | out_path = "normalizedResult_" + str(index) + ".png" |
45 | | - image_manager = ImageManager() |
| 46 | + image_io = ImageIO() |
46 | 47 | image = item.get_image_data() |
47 | 48 | if image != None: |
48 | 49 |
|
|
51 | 52 | # Draw the detected rotation angle on the original image |
52 | 53 | cv_image = cv2.imread(image_path) |
53 | 54 |
|
54 | | - location = item.get_location() |
| 55 | + location = item.get_source_deskew_quad() |
55 | 56 | x1 = location.points[0].x |
56 | 57 | y1 = location.points[0].y |
57 | 58 | x2 = location.points[1].x |
|
71 | 72 | cv2.waitKey(0) |
72 | 73 | cv2.destroyAllWindows() |
73 | 74 |
|
74 | | - errorCode, errorMsg = image_manager.save_to_file( |
| 75 | + errorCode, errorMsg = image_io.save_to_file( |
75 | 76 | image, out_path) |
76 | 77 | if errorCode == 0: |
77 | 78 | print("Document " + str(index) + |
78 | 79 | " file: " + out_path) |
| 80 | + else: |
| 81 | + print("Error saving document " + str(index) + |
| 82 | + " file: " + out_path + ", ErrorCode:", errorCode, ", ErrorString:", errorMsg) |
79 | 83 | input("Press Enter to quit...") |
0 commit comments