def face_landmarks(): file_path = file_operations.save_file_and_return_path(request) out_image_sz = OUT_IMAGE_SZ if 'out_image_sz' in request.form and int( request.form['out_image_sz']) > 0: out_image_sz = int(request.form['out_image_sz']) # detect face landmarks out = recognition.face_landmarks(file_path, out_image_sz) # remove file after recognize file_operations.remove_file(file_path) if len(out['face_landmarks_list']) == 0: return json.dumps({ "code": "image_no_face", "message": "No face found" }), 422 # all images we return in base64 for fast use in browser out_w_lands_base64 = base64.b64encode( out['image_with_landmarks'].getvalue()).decode('ascii') result = { "app_version": APP_VERSION, # coords returning for original image "face_landmarks_list": out['face_landmarks_list'], "face_count": len(out['face_landmarks_list']), "image": "data:image/jpg;base64," + out_w_lands_base64, } return json.dumps(result), 200
def setUp(self): """ Testing folder setup the same way a downloads folder will be """ self.path = "testing" make_dir(self.path) make_dir(os.path.join(self.path,"The Way of Kings")) make_dir(os.path.join(self.path,"The Price of Spring")) make_dir(os.path.join(self.path,"Mistborn The Final Empire")) create_file(os.path.join(self.path, "test1")) remove_file(os.path.join(self.path, "test4"))
def run(self): ''' run algorithm and checks results''' _result = '{}_results'.format(self._main) self.get_data() # pylint: disable=W0612 cProfile.runctx('self.main()', globals(), locals(), _result) print('------------------------------------------') _stat = pstats.Stats(_result) _stat.strip_dirs().sort_stats(-1).print_stats(self._main) remove_file(_result)
def face_encodings(): file_path = file_operations.save_file_and_return_path(request) out = recognition.face_encodings(file_path) # remove file after recognize file_operations.remove_file(file_path) if len(out['face_encodings_list']) == 0: return json.dumps({ "code": "image_no_face", "message": "No face found" }), 422 result = { "app_version": APP_VERSION, "face_encodings_list": out['face_encodings_list'], "face_count": len(out['face_encodings_list']) } return json.dumps(result), 200
def face_locations(): file_path = file_operations.save_file_and_return_path(request) out_image_sz = OUT_IMAGE_SZ if 'out_image_sz' in request.form and int( request.form['out_image_sz']) > 0: out_image_sz = int(request.form['out_image_sz']) # detect faces out = recognition.face_locations(file_path, out_image_sz) # remove file after recognize file_operations.remove_file(file_path) if len(out['face_locations_list']) == 0: return json.dumps({ "code": "image_no_face", "message": "No face found" }), 422 faces_base64 = [] for image in out['images']: faces_base64.append("data:image/jpg;base64," + base64.b64encode(image.getvalue()).decode('ascii')) # change pos, in format for PIL.ImageDraw.Draw.rectangle([x0, y0, x1, y1]) pillow_rectangles = [] for face_location in out['face_locations_list']: bottom, right, top, left = face_location pillow_rectangles.append((left, bottom, right, top)) result = { "app_version": APP_VERSION, "face_locations": pillow_rectangles, "face_count": len(out['face_locations_list']), "images": faces_base64 } return json.dumps(result), 200
def create_rss_xml(infos, path): #RSS XML Files BACKUP = os.path.join(path, 'rss_backup.xml') RSS = os.path.join(path, 'rss.xml') #XML Template files HEADER = os.path.join(path, 'header.xml') ITEM = os.path.join(path, 'item.xml') FOOTER = os.path.join(path, 'footer.xml') remove_file(BACKUP) move_file(RSS, BACKUP) template = open(HEADER, 'r') rss = open(RSS, 'w') rss.write(template.read().format(datetime.today().strftime("%a, %d %b %Y %H:%M:%S GMT"))) template.close() for info in infos: template = open(ITEM, 'r') rss.write(template.read().format(**info)) template.close() template = open(FOOTER, 'r') rss.write(template.read()) template.close() rss.close()