def processCamUploadImage(b64_Filedata): # Convert base64Image to openCV Image openCVImage = convrt.base64_to_openCVImage(b64_Filedata) # # Enhance Passport Image improve Ocr Results # openCVImage = cv2.cvtColor(openCVImage, cv2.COLOR_BGR2GRAY) croppedImage, preProcessAlerts = preProcessROICrop(openCVImage) # Run OCR Text Extraction # Format extracted data if croppedImage is not None: croppedImageGray = preProcessImageEnhance(croppedImage) extractedData, textExtractionAlerts = getVisaTextExtraction(croppedImageGray) else: openCVImageGray = preProcessImageEnhance(openCVImage) extractedData, textExtractionAlerts = getVisaTextExtraction(openCVImageGray) alertMessages = preProcessAlerts + textExtractionAlerts if len(alertMessages)>0: alertMessages.sort() responseError = getResponseError(alertMessages[0]) else: responseError = None return extractedData, responseError
def processCamUploadImage(b64_Filedata, pp_data): # Convert base64Image to openCV Image openCVImage = convrt.base64_to_openCVImage(b64_Filedata) # Enhance STL Image improve Ocr Results openCVImage = cv2.cvtColor(openCVImage, cv2.COLOR_BGR2GRAY) # Extract name from the passport try: matchName = pp_data[json_names.__PP_NAME__] except: matchName = None # Format extracted data extractedData, alertMessages = extract_information.extract_info_stl( openCVImage, matchName) if len(alertMessages) > 0: alertMessages.sort() responseError = getResponseError(alertMessages[0]) else: responseError = None return extractedData, responseError
def processCamUploadImage(b64_Filedata): # Convert base64Image to openCV Image openCVImage = convrt.base64_to_openCVImage(b64_Filedata) # Enhance Passport Image improve Ocr Results # openCVImage = cv2.cvtColor(openCVImage, cv2.COLOR_BGR2GRAY) # Run passport eye to extract details and mrz = preprocessCamUpload(openCVImage) # Format extracted data extractedData, alertMessages = formatPassportEyeData(mrz) if len(alertMessages) > 0: alertMessages.sort() responseError = getResponseError(alertMessages[0]) else: responseError = None return extractedData, responseError
def getDocumentDetails(): try: # Get JSON object from the frontend requestJsonObj = json.loads(request.data) # Get document type and Image document_type = requestJsonObj[json_names.__IN_DOCUMENT_TYPE__] document_file = requestJsonObj[json_names.__IN_DOCUMENT_IMAGE__] try: # Execute OCR engine based on the document type: if document_type == json_names.__IN_CODE_PASSPORT_CAM__: # Implement OCR on cam uploaded passport document. extracted_data, response_error = PassportDocProcess.Process.processCamUploadImage( document_file) return frame_output(extracted_data, None, response_error) elif document_type == json_names.__IN_CODE_PASSPORT_FILE__: # Implement OCR on file uploaded passport document. extracted_data, response_error = PassportDocProcess.Process.processFileUploadImage( document_file) return frame_output(extracted_data, None, response_error) elif document_type == json_names.__IN_CODE_EID_CAM__: # Implement OCR on cam uploaded EID document. extracted_data, response_error = EIDDocProcess.Process.processCamUploadImage( document_file) reference_document_data = requestJsonObj[ json_names.__IN_REF_DOCUMENT_DATA__] match_verification = compare_PP2EID(reference_document_data, extracted_data) return frame_output(extracted_data, match_verification, response_error) elif document_type == json_names.__IN_CODE_EID_FILE__: # Implement OCR on file uploaded EID document. extracted_data, response_error = EIDDocProcess.Process.processFileUploadImage( document_file) reference_document_data = requestJsonObj[ json_names.__IN_REF_DOCUMENT_DATA__] match_verification = compare_PP2Visa(reference_document_data, extracted_data) return frame_output(extracted_data, match_verification, response_error) elif document_type == json_names.__IN_CODE_VISA_CAM__: # Implement OCR on cam uploaded Visa document. extracted_data, response_error = VisaDocProcess.Process.processCamUploadImage( document_file) # print extracted_data, response_error reference_document_data = requestJsonObj[ json_names.__IN_REF_DOCUMENT_DATA__] # print reference_document_data match_verification = compare_PP2Visa(reference_document_data, extracted_data) return frame_output(extracted_data, match_verification, response_error) elif document_type == json_names.__IN_CODE_VISA_FILE__: # Implement OCR on file uploaded Visa document. extracted_data, response_error = VisaDocProcess.Process.processFileUploadImage( document_file) reference_document_data = requestJsonObj[ json_names.__IN_REF_DOCUMENT_DATA__] match_verification = compare_PP2Visa(reference_document_data, extracted_data) return frame_output(extracted_data, match_verification, response_error) elif document_type == json_names.__IN_CODE_STL_CAM__: # Implement OCR on cam uploaded Salary Letter document. reference_document_data = requestJsonObj[ json_names.__IN_REF_DOCUMENT_DATA__] extracted_data, response_error = STLDocProcess.Process.processCamUploadImage( document_file, reference_document_data) match_verification = compare_PP2STL(extracted_data) return frame_output(extracted_data, match_verification, response_error) elif document_type == json_names.__IN_CODE_STL_FILE__: # Implement OCR on file uploaded Salary Letter document. reference_document_data = requestJsonObj[ json_names.__IN_REF_DOCUMENT_DATA__] extracted_data, response_error = STLDocProcess.Process.processCamUploadImage( document_file, reference_document_data) match_verification = compare_PP2STL(extracted_data) return frame_output(extracted_data, match_verification, response_error) except Exception, e: print e response_error = getResponseError(9002) return frame_output({}, None, response_error) except Exception, e: print e response_error = getResponseError(9001) return frame_output({}, None, response_error)