Skip to content

Commit 2726cd2

Browse files
added numpy input
1 parent ee9158f commit 2726cd2

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212

1313
This repository extracts the Machine Readable Zone (MRZ) from document images. The MRZ typically contains important information such as the document holder's name, nationality, document number, date of birth, etc.
1414

15-
**️Features:**
15+
## ️✨Features:
1616

17-
- Detects and extracts the MRZ region from document images
18-
- Contour detection to accurately identify the MRZ area
19-
- Custom trained models using ONNX
20-
- Contains checksum logics for data validation
21-
- Outputs the extracted MRZ region as text/json for further processing or analysis
17+
- 👁️Detects and extracts the MRZ region from document images
18+
- ️🔍Contour detection to accurately identify the MRZ area
19+
- 🪄Custom trained models using ONNX
20+
- 🆗Contains checksum logics for data validation
21+
- 📤Outputs the extracted MRZ region as text/json
2222

2323

2424
## 🛠️Built With
@@ -118,7 +118,7 @@ Now, based on the example of a national passport, let us take a closer look at t
118118
119119
- [x] Include mrva and mrvb documents
120120
- [x] Add wiki page
121-
- [ ] Support numpy array as input
121+
- [x] Support numpy array as input
122122
- [x] Support mrz text as input
123123
- [x] Support base64 as input
124124
- [ ] Support pdf as input

fastmrz/fastmrz.py

+5-13
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,6 @@ def _base64_to_image_array(self, base64_string):
138138

139139
return image_array
140140

141-
def get_details_old(self, image, ignore_parse=False, include_checkdigit=True):
142-
if not self._is_valid(image):
143-
return {"status": "FAILURE", "message": "Invalid input image"}
144-
mrz_text = self._get_mrz(image)
145-
146-
return mrz_text if ignore_parse else self._parse_mrz(mrz_text)
147-
148141
def _parse_mrz(self, mrz_text):
149142
if not mrz_text:
150143
return {"status": "FAILURE", "message": "No MRZ detected"}
@@ -269,7 +262,7 @@ def validate_mrz(self, mrz_text):
269262
def get_details(self, input_data, input_type="imagepath", ignore_parse=False, include_checkdigit=True):
270263
if input_type == "imagepath":
271264
if not self._is_valid(input_data):
272-
return {"status": "FAILURE", "message": "Invalid input image"}
265+
raise ValueError("Input is not a valid image file.")
273266
image_file = open(input_data, "rb")
274267
image_data = image_file.read()
275268
image_file.close()
@@ -279,12 +272,11 @@ def get_details(self, input_data, input_type="imagepath", ignore_parse=False, in
279272

280273
return mrz_text if ignore_parse else self._parse_mrz(mrz_text)
281274
elif input_type == "numpy":
282-
# get_details_from_numpy(input_data, ignore_parse=False, include_checkdigit=True)
283-
if isinstance(input_data, np.ndarray):
284-
image = input_data
285-
else:
275+
if not self._is_valid(input_data):
286276
raise ValueError("Input is not a valid NumPy array.")
287-
pass
277+
mrz_text = self._get_mrz(input_data)
278+
279+
return mrz_text if ignore_parse else self._parse_mrz(mrz_text)
288280
elif input_type == "base64":
289281
image_array = self._base64_to_image_array(input_data)
290282
mrz_text = self._get_mrz(image_array)

0 commit comments

Comments
 (0)