-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Update the URL for requesting the trial license key
- Add a DBR v.10 example
- Loading branch information
Showing
21 changed files
with
244 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import sys | ||
from dynamsoft_capture_vision_bundle import * | ||
import os | ||
import cv2 | ||
import numpy as np | ||
from utils import * | ||
|
||
if __name__ == '__main__': | ||
|
||
print("**********************************************************") | ||
print("Welcome to Dynamsoft Capture Vision - Barcode Sample") | ||
print("**********************************************************") | ||
|
||
error_code, error_message = LicenseManager.init_license( | ||
"DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==") | ||
if error_code != EnumErrorCode.EC_OK and error_code != EnumErrorCode.EC_LICENSE_CACHE_USED: | ||
print("License initialization failed: ErrorCode:", | ||
error_code, ", ErrorString:", error_message) | ||
else: | ||
cvr_instance = CaptureVisionRouter() | ||
while (True): | ||
image_path = input( | ||
">> Input your image full path:\n" | ||
">> 'Enter' for sample image or 'Q'/'q' to quit\n" | ||
).strip('\'"') | ||
|
||
if image_path.lower() == "q": | ||
sys.exit(0) | ||
|
||
if image_path == "": | ||
image_path = "../../../images/multi.png" | ||
|
||
if not os.path.exists(image_path): | ||
print("The image path does not exist.") | ||
continue | ||
result = cvr_instance.capture( | ||
image_path, EnumPresetTemplate.PT_READ_BARCODES.value) | ||
if result.get_error_code() != EnumErrorCode.EC_OK: | ||
print("Error:", result.get_error_code(), | ||
result.get_error_string()) | ||
else: | ||
cv_image = cv2.imread(image_path) | ||
|
||
items = result.get_items() | ||
print('Found {} barcodes.'.format(len(items))) | ||
for item in items: | ||
format_type = item.get_format() | ||
text = item.get_text() | ||
print("Barcode Format:", format_type) | ||
print("Barcode Text:", text) | ||
|
||
location = item.get_location() | ||
x1 = location.points[0].x | ||
y1 = location.points[0].y | ||
x2 = location.points[1].x | ||
y2 = location.points[1].y | ||
x3 = location.points[2].x | ||
y3 = location.points[2].y | ||
x4 = location.points[3].x | ||
y4 = location.points[3].y | ||
del location | ||
|
||
cv2.drawContours( | ||
cv_image, [np.intp([(x1, y1), (x2, y2), (x3, y3), (x4, y4)])], 0, (0, 255, 0), 2) | ||
|
||
cv2.putText(cv_image, text, (x1, y1 - 10), | ||
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2) | ||
|
||
cv2.imshow( | ||
"Original Image with Detected Barcodes", cv_image) | ||
cv2.waitKey(0) | ||
cv2.destroyAllWindows() | ||
|
||
input("Press Enter to quit...") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dynamsoft-capture-vision-bundle | ||
opencv-python |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
from dynamsoft_capture_vision_bundle import * | ||
import numpy as np | ||
|
||
|
||
def convertImageData2Mat(normalized_image): | ||
ba = bytearray(normalized_image.get_bytes()) | ||
width = normalized_image.get_width() | ||
height = normalized_image.get_height() | ||
|
||
channels = 3 | ||
if normalized_image.get_image_pixel_format() == EnumImagePixelFormat.IPF_BINARY: | ||
channels = 1 | ||
all = [] | ||
skip = normalized_image.stride * 8 - width | ||
|
||
index = 0 | ||
n = 1 | ||
for byte in ba: | ||
|
||
byteCount = 7 | ||
while byteCount >= 0: | ||
b = (byte & (1 << byteCount)) >> byteCount | ||
|
||
if index < normalized_image.stride * 8 * n - skip: | ||
if b == 1: | ||
all.append(255) | ||
else: | ||
all.append(0) | ||
|
||
byteCount -= 1 | ||
index += 1 | ||
|
||
if index == normalized_image.stride * 8 * n: | ||
n += 1 | ||
|
||
mat = np.array(all, dtype=np.uint8).reshape(height, width, channels) | ||
return mat | ||
|
||
elif normalized_image.get_image_pixel_format() == EnumImagePixelFormat.IPF_GRAYSCALED: | ||
channels = 1 | ||
|
||
mat = np.array(ba, dtype=np.uint8).reshape(height, width, channels) | ||
|
||
return mat | ||
|
||
|
||
def convertMat2ImageData(mat): | ||
if len(mat.shape) == 3: | ||
height, width, channels = mat.shape | ||
pixel_format = EnumImagePixelFormat.IPF_RGB_888 | ||
else: | ||
height, width = mat.shape | ||
channels = 1 | ||
pixel_format = EnumImagePixelFormat.IPF_GRAYSCALED | ||
|
||
stride = width * channels | ||
imagedata = ImageData(mat.tobytes(), width, height, stride, pixel_format) | ||
return imagedata | ||
|
||
|
||
class MRZResult: | ||
def __init__(self, item: ParsedResultItem): | ||
self.doc_type = item.get_code_type() | ||
self.raw_text = [] | ||
self.doc_id = None | ||
self.surname = None | ||
self.given_name = None | ||
self.nationality = None | ||
self.issuer = None | ||
self.gender = None | ||
self.date_of_birth = None | ||
self.date_of_expiry = None | ||
if self.doc_type == "MRTD_TD3_PASSPORT": | ||
if item.get_field_value("passportNumber") != None and item.get_field_validation_status("passportNumber") != EnumValidationStatus.VS_FAILED: | ||
self.doc_id = item.get_field_value("passportNumber") | ||
elif item.get_field_value("documentNumber") != None and item.get_field_validation_status("documentNumber") != EnumValidationStatus.VS_FAILED: | ||
self.doc_id = item.get_field_value("documentNumber") | ||
|
||
line = item.get_field_value("line1") | ||
if line is not None: | ||
if item.get_field_validation_status("line1") == EnumValidationStatus.VS_FAILED: | ||
line += ", Validation Failed" | ||
self.raw_text.append(line) | ||
line = item.get_field_value("line2") | ||
if line is not None: | ||
if item.get_field_validation_status("line2") == EnumValidationStatus.VS_FAILED: | ||
line += ", Validation Failed" | ||
self.raw_text.append(line) | ||
line = item.get_field_value("line3") | ||
if line is not None: | ||
if item.get_field_validation_status("line3") == EnumValidationStatus.VS_FAILED: | ||
line += ", Validation Failed" | ||
self.raw_text.append(line) | ||
|
||
if item.get_field_value("nationality") != None and item.get_field_validation_status("nationality") != EnumValidationStatus.VS_FAILED: | ||
self.nationality = item.get_field_value("nationality") | ||
if item.get_field_value("issuingState") != None and item.get_field_validation_status("issuingState") != EnumValidationStatus.VS_FAILED: | ||
self.issuer = item.get_field_value("issuingState") | ||
if item.get_field_value("dateOfBirth") != None and item.get_field_validation_status("dateOfBirth") != EnumValidationStatus.VS_FAILED: | ||
self.date_of_birth = item.get_field_value("dateOfBirth") | ||
if item.get_field_value("dateOfExpiry") != None and item.get_field_validation_status("dateOfExpiry") != EnumValidationStatus.VS_FAILED: | ||
self.date_of_expiry = item.get_field_value("dateOfExpiry") | ||
if item.get_field_value("sex") != None and item.get_field_validation_status("sex") != EnumValidationStatus.VS_FAILED: | ||
self.gender = item.get_field_value("sex") | ||
if item.get_field_value("primaryIdentifier") != None and item.get_field_validation_status("primaryIdentifier") != EnumValidationStatus.VS_FAILED: | ||
self.surname = item.get_field_value("primaryIdentifier") | ||
if item.get_field_value("secondaryIdentifier") != None and item.get_field_validation_status("secondaryIdentifier") != EnumValidationStatus.VS_FAILED: | ||
self.given_name = item.get_field_value("secondaryIdentifier") | ||
|
||
def to_string(self): | ||
msg = (f"Raw Text:\n") | ||
for index, line in enumerate(self.raw_text): | ||
msg += (f"\tLine {index + 1}: {line}\n") | ||
msg += (f"Parsed Information:\n" | ||
f"\tDocumentType: {self.doc_type or ''}\n" | ||
f"\tDocumentID: {self.doc_id or ''}\n" | ||
f"\tSurname: {self.surname or ''}\n" | ||
f"\tGivenName: {self.given_name or ''}\n" | ||
f"\tNationality: {self.nationality or ''}\n" | ||
f"\tIssuingCountryorOrganization: {self.issuer or ''}\n" | ||
f"\tGender: {self.gender or ''}\n" | ||
f"\tDateofBirth(YYMMDD): {self.date_of_birth or ''}\n" | ||
f"\tExpirationDate(YYMMDD): {self.date_of_expiry or ''}\n") | ||
return msg | ||
|
||
|
||
def print_results(result: ParsedResult) -> None: | ||
tag = result.get_original_image_tag() | ||
if isinstance(tag, FileImageTag): | ||
print("File:", tag.get_file_path()) | ||
if result.get_error_code() != EnumErrorCode.EC_OK: | ||
print("Error:", result.get_error_string()) | ||
else: | ||
items = result.get_items() | ||
print("Parsed", len(items), "MRZ Zones.") | ||
for item in items: | ||
mrz_result = MRZResult(item) | ||
print(mrz_result.to_string()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dbr | ||
opencv-python |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.