def mask(): ac = Aadhaar_Card(config); flag_mask = 0 requestid=uuid.uuid4(); temp_name = "input/"+str(requestid)+".png" r = request.get_json(force=True) #force=True #content type application/json #temp_name = "temp_unmasked.png" image = r['doc_b64'] # raw data with base64 encoding decoded_data = base64.b64decode(image) np_data = np.fromstring(decoded_data,np.uint8) img = cv2.imdecode(np_data,cv2.IMREAD_UNCHANGED) cv2.imwrite(temp_name,img) write = "temp_masked.png" flag_mask = ac.mask_image(temp_name, write, r['aadhaar']) delete_file(temp_name) content_type = 'application/json' headers = {'content-type': content_type} if flag_mask == 0: return Response(response=jsonpickle.encode({'doc_b64_masked':'None', 'is_masked': False}), status=200, mimetype="application/json", headers=headers) else: img_bytes = to_image_string(write) delete_file(write) #convert byte to string encoded_string = img_bytes.decode("utf-8") return Response(response=jsonpickle.encode({'doc_b64_masked':encoded_string, 'is_masked': True}), status=200, mimetype="application/json", headers=headers)
def sample_pipe(): ac = Aadhaar_Card(config); flag_mask = 0 r = request.get_json(force=True) #force=True #content type application/json requestid=uuid.uuid4(); temp_name = "temp/"+str(requestid)+".png" image = r['doc_b64'] # raw data with base64 encoding decoded_data = base64.b64decode(image) np_data = np.fromstring(decoded_data,np.uint8) img = cv2.imdecode(np_data,cv2.IMREAD_UNCHANGED) cv2.imwrite(temp_name,img) aadhaar_list = ac.extract(temp_name) content_type = 'application/json' headers = {'content-type': content_type} if len(aadhaar_list) == 0 and r['brut']: mode_executed = "BRUT-OCR-MASKING" write = "temp/"+"temp_"+str(requestid)+".png" mask_status = ac.mask_nums(temp_name, write) delete_file(temp_name) img_bytes = to_image_string(write) delete_file(write) #convert byte to string encoded_string = img_bytes.decode("utf-8") return Response(response=jsonpickle.encode({'doc_b64_masked':encoded_string, 'is_masked': True,'mode_executed' : mode_executed}), status=200, mimetype="application/json", headers=headers) if len(aadhaar_list) == 0 and not r['brut']: mode_executed = "OCR-MASKING" return Response(response=jsonpickle.encode({'doc_b64_masked':'None', 'is_masked': False, 'error':'Unable to find aadhaar number','mode_executed' : mode_executed}), status=200, mimetype="application/json", headers=headers) if len(aadhaar_list) > 0 : mode_executed = "OCR-MASKING" # for masking first 8 digits from the number ori_aadhaar_list = aadhaar_list aadhaar_list = list(map(lambda x: x[:8] , aadhaar_list)) # Comment out this incase you want to mask entire aadhaar write = "temp/temp_masked"+str(requestid)+".png" flag_mask = ac.mask_image(temp_name, write, aadhaar_list) delete_file(temp_name) img_bytes = to_image_string(write) delete_file(write) #convert byte to string encoded_string = img_bytes.decode("utf-8") valid_aadhaar_list = list(filter(lambda x: (ac.validate(x) == 1) , ori_aadhaar_list)) return Response(response=jsonpickle.encode({'doc_b64_masked':encoded_string, 'is_masked': True,'mode_executed' : mode_executed, 'aadhaar_list':ori_aadhaar_list, 'valid_aadhaar_list':valid_aadhaar_list}), status=200, mimetype="application/json", headers=headers)