Skip to content

Commit 4c1367b

Browse files
committed
Update the API usage for the latest SDK
1 parent ee147e0 commit 4c1367b

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

examples/official/camera.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ def on_captured_result_received(self, captured_result):
8282

8383
del location
8484

85-
elif item.get_type() == EnumCapturedResultItemType.CRIT_NORMALIZED_IMAGE:
86-
location = item.get_location()
85+
elif item.get_type() == EnumCapturedResultItemType.CRIT_DESKEWED_IMAGE:
86+
location = item.get_source_deskew_quad()
8787
x1 = location.points[0].x
8888
y1 = location.points[0].y
8989
x2 = location.points[1].x

examples/official/file.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,21 @@
2929
if not os.path.exists(image_path):
3030
print("The image path does not exist.")
3131
continue
32+
3233
result = cvr.capture(
3334
image_path, EnumPresetTemplate.PT_DETECT_AND_NORMALIZE_DOCUMENT.value)
3435
if result.get_error_code() != EnumErrorCode.EC_OK:
3536
print("Error:", result.get_error_code(),
3637
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:
3940
print("No normalized documents.")
4041
else:
41-
items = normalized_images_result.get_items()
42+
items = processed_document_result.get_deskewed_image_result_items()
4243
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()):
4445
out_path = "normalizedResult_" + str(index) + ".png"
45-
image_manager = ImageManager()
46+
image_io = ImageIO()
4647
image = item.get_image_data()
4748
if image != None:
4849

@@ -51,7 +52,7 @@
5152
# Draw the detected rotation angle on the original image
5253
cv_image = cv2.imread(image_path)
5354

54-
location = item.get_location()
55+
location = item.get_source_deskew_quad()
5556
x1 = location.points[0].x
5657
y1 = location.points[0].y
5758
x2 = location.points[1].x
@@ -71,9 +72,12 @@
7172
cv2.waitKey(0)
7273
cv2.destroyAllWindows()
7374

74-
errorCode, errorMsg = image_manager.save_to_file(
75+
errorCode, errorMsg = image_io.save_to_file(
7576
image, out_path)
7677
if errorCode == 0:
7778
print("Document " + str(index) +
7879
" file: " + out_path)
80+
else:
81+
print("Error saving document " + str(index) +
82+
" file: " + out_path + ", ErrorCode:", errorCode, ", ErrorString:", errorMsg)
7983
input("Press Enter to quit...")

examples/official/orientation_detection.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@
3232
if result.get_error_code() != EnumErrorCode.EC_OK:
3333
print("Error:", result.get_error_code(),
3434
result.get_error_string())
35-
normalized_images_result = result.get_normalized_images_result()
36-
if normalized_images_result is None or len(normalized_images_result.get_items()) == 0:
35+
processed_document_result = result.get_processed_document_result()
36+
if processed_document_result is None or len(processed_document_result.get_deskewed_image_result_items()) == 0:
3737
print("No normalized documents.")
3838
else:
39-
items = normalized_images_result.get_items()
39+
items = processed_document_result.get_deskewed_image_result_items()
4040
print("Normalized", len(items), "documents.")
41-
for index, item in enumerate(normalized_images_result.get_items()):
41+
for index, item in enumerate(processed_document_result.get_deskewed_image_result_items()):
4242
out_path = "normalizedResult_" + str(index) + ".png"
43-
image_manager = ImageManager()
43+
image_io = ImageIO()
4444
image = item.get_image_data()
4545
if image != None:
4646

@@ -57,7 +57,7 @@
5757
# Draw the detected rotation angle on the original image
5858
cv_image = cv2.imread(image_path)
5959

60-
location = item.get_location()
60+
location = item.get_source_deskew_quad()
6161
x1 = location.points[0].x
6262
y1 = location.points[0].y
6363
x2 = location.points[1].x
@@ -92,7 +92,7 @@
9292
cv2.waitKey(0)
9393
cv2.destroyAllWindows()
9494

95-
errorCode, errorMsg = image_manager.save_to_file(
95+
errorCode, errorMsg = image_io.save_to_file(
9696
image, out_path)
9797
if errorCode == 0:
9898
print("Document " + str(index) +

0 commit comments

Comments
 (0)