|
1 | | -from dynamsoft_capture_vision_bundle import * |
| 1 | +from dynamsoft_barcode_reader_bundle import * |
2 | 2 | import numpy as np |
3 | 3 |
|
4 | 4 |
|
@@ -58,81 +58,3 @@ def convertMat2ImageData(mat): |
58 | 58 | return imagedata |
59 | 59 |
|
60 | 60 |
|
61 | | -class MRZResult: |
62 | | - def __init__(self, item: ParsedResultItem): |
63 | | - self.doc_type = item.get_code_type() |
64 | | - self.raw_text = [] |
65 | | - self.doc_id = None |
66 | | - self.surname = None |
67 | | - self.given_name = None |
68 | | - self.nationality = None |
69 | | - self.issuer = None |
70 | | - self.gender = None |
71 | | - self.date_of_birth = None |
72 | | - self.date_of_expiry = None |
73 | | - if self.doc_type == "MRTD_TD3_PASSPORT": |
74 | | - if item.get_field_value("passportNumber") != None and item.get_field_validation_status("passportNumber") != EnumValidationStatus.VS_FAILED: |
75 | | - self.doc_id = item.get_field_value("passportNumber") |
76 | | - elif item.get_field_value("documentNumber") != None and item.get_field_validation_status("documentNumber") != EnumValidationStatus.VS_FAILED: |
77 | | - self.doc_id = item.get_field_value("documentNumber") |
78 | | - |
79 | | - line = item.get_field_value("line1") |
80 | | - if line is not None: |
81 | | - if item.get_field_validation_status("line1") == EnumValidationStatus.VS_FAILED: |
82 | | - line += ", Validation Failed" |
83 | | - self.raw_text.append(line) |
84 | | - line = item.get_field_value("line2") |
85 | | - if line is not None: |
86 | | - if item.get_field_validation_status("line2") == EnumValidationStatus.VS_FAILED: |
87 | | - line += ", Validation Failed" |
88 | | - self.raw_text.append(line) |
89 | | - line = item.get_field_value("line3") |
90 | | - if line is not None: |
91 | | - if item.get_field_validation_status("line3") == EnumValidationStatus.VS_FAILED: |
92 | | - line += ", Validation Failed" |
93 | | - self.raw_text.append(line) |
94 | | - |
95 | | - if item.get_field_value("nationality") != None and item.get_field_validation_status("nationality") != EnumValidationStatus.VS_FAILED: |
96 | | - self.nationality = item.get_field_value("nationality") |
97 | | - if item.get_field_value("issuingState") != None and item.get_field_validation_status("issuingState") != EnumValidationStatus.VS_FAILED: |
98 | | - self.issuer = item.get_field_value("issuingState") |
99 | | - if item.get_field_value("dateOfBirth") != None and item.get_field_validation_status("dateOfBirth") != EnumValidationStatus.VS_FAILED: |
100 | | - self.date_of_birth = item.get_field_value("dateOfBirth") |
101 | | - if item.get_field_value("dateOfExpiry") != None and item.get_field_validation_status("dateOfExpiry") != EnumValidationStatus.VS_FAILED: |
102 | | - self.date_of_expiry = item.get_field_value("dateOfExpiry") |
103 | | - if item.get_field_value("sex") != None and item.get_field_validation_status("sex") != EnumValidationStatus.VS_FAILED: |
104 | | - self.gender = item.get_field_value("sex") |
105 | | - if item.get_field_value("primaryIdentifier") != None and item.get_field_validation_status("primaryIdentifier") != EnumValidationStatus.VS_FAILED: |
106 | | - self.surname = item.get_field_value("primaryIdentifier") |
107 | | - if item.get_field_value("secondaryIdentifier") != None and item.get_field_validation_status("secondaryIdentifier") != EnumValidationStatus.VS_FAILED: |
108 | | - self.given_name = item.get_field_value("secondaryIdentifier") |
109 | | - |
110 | | - def to_string(self): |
111 | | - msg = (f"Raw Text:\n") |
112 | | - for index, line in enumerate(self.raw_text): |
113 | | - msg += (f"\tLine {index + 1}: {line}\n") |
114 | | - msg += (f"Parsed Information:\n" |
115 | | - f"\tDocumentType: {self.doc_type or ''}\n" |
116 | | - f"\tDocumentID: {self.doc_id or ''}\n" |
117 | | - f"\tSurname: {self.surname or ''}\n" |
118 | | - f"\tGivenName: {self.given_name or ''}\n" |
119 | | - f"\tNationality: {self.nationality or ''}\n" |
120 | | - f"\tIssuingCountryorOrganization: {self.issuer or ''}\n" |
121 | | - f"\tGender: {self.gender or ''}\n" |
122 | | - f"\tDateofBirth(YYMMDD): {self.date_of_birth or ''}\n" |
123 | | - f"\tExpirationDate(YYMMDD): {self.date_of_expiry or ''}\n") |
124 | | - return msg |
125 | | - |
126 | | - |
127 | | -def print_results(result: ParsedResult) -> None: |
128 | | - tag = result.get_original_image_tag() |
129 | | - if isinstance(tag, FileImageTag): |
130 | | - print("File:", tag.get_file_path()) |
131 | | - if result.get_error_code() != EnumErrorCode.EC_OK: |
132 | | - print("Error:", result.get_error_string()) |
133 | | - else: |
134 | | - items = result.get_items() |
135 | | - print("Parsed", len(items), "MRZ Zones.") |
136 | | - for item in items: |
137 | | - mrz_result = MRZResult(item) |
138 | | - print(mrz_result.to_string()) |
0 commit comments