def _make_storage_config(self, config): storage = config['storage'] storage_type = storage['type'] if storage_type == 'posix': storage_config = StorageConfig.make_posix_config() elif storage_type == 'gcs': storage_config = StorageConfig.make_gcs_config(storage['bucket']) elif storage_type == 's3': storage_config = StorageConfig.make_s3_config( storage['bucket'], storage['region'], storage['endpoint']) else: raise ScannerException( 'Unsupported storage type {}'.format(storage_type)) return storage_config
def solve_thread(face_dict, tmp_dict_path, thread_id): print("Thread %d start computing..." % (thread_id)) res_dict = {} storage = StorageBackend.make_from_config( StorageConfig.make_gcs_config('esper')) for i, video in enumerate(sorted(face_dict)): print("Thread %d start %dth video: %s" % (thread_id, i, video)) prepare_clothing(video, face_dict[video], storage) # res_dict[video] = result # if i % 200 == 0 and i != 0: # pickle.dump(res_dict, open(tmp_dict_path, "wb" )) # pickle.dump(res_dict, open(tmp_dict_path, "wb" )) print("Thread %d finished computing..." % (thread_id))
def prepare_hairstyle(video_path, face_list, storage=None, out_folder='/app/result/clothing/images/'): # (frame_id, face_id, identity_id, bbox) = face_list[0] fid_list = [face[0] for face in face_list] # print("fid_list", fid_list) # load frames from google cloud if storage is None: storage = StorageBackend.make_from_config( StorageConfig.make_gcs_config('esper')) video_file = RandomReadFile(storage, video_path.encode('ascii')) video = Decoder(video_file) img_list = video.retrieve(fid_list) img_list = [cv2.cvtColor(img, cv2.COLOR_RGB2BGR) for img in img_list] # print("load %d frames" % len(fid_list)) H, W = img_list[0].shape[:2] # result = [] for i, face in enumerate(face_list): (frame_id, face_id, identity_id, bbox) = face frame = img_list[i] x1 = int(bbox[0] * W) y1 = int(bbox[1] * H) x2 = int(bbox[2] * W) y2 = int(bbox[3] * H) w = max(y2 - y1, x2 - x1) * 3 // 4 cx, cy = (x1 + x2) // 2, (y1 + y2) // 2 x1 = cx - w if cx - w > 0 else 0 x2 = cx + w if cx + w < W else W y1 = cy - w if cy - w > 0 else 0 y2 = cy + w if cy + w < H else H filename = '{}_{}.jpg'.format(identity_id, face_id) cv2.imwrite(os.path.join(out_folder, filename), img_list[i][y1:y2, x1:x2])
import pysrt import requests import enum from storehouse import StorageConfig, StorageBackend import traceback from pprint import pprint from esper.widget import * from esper.prelude import * import django.apps ESPER_ENV = os.environ.get('ESPER_ENV') BUCKET = os.environ.get('BUCKET') DATA_PATH = os.environ.get('DATA_PATH') if ESPER_ENV == 'google': storage_config = StorageConfig.make_gcs_config(BUCKET) else: storage_config = StorageConfig.make_posix_config() storage = StorageBackend.make_from_config(storage_config) VTT_FROM_CAPTION_INDEX = True # Prints and flushes (necessary for gunicorn logs) def _print(*args): pprint((*args)) sys.stdout.flush() # Renders home page def index(request):
from hwang import Decoder from storehouse import StorageConfig, StorageBackend, RandomReadFile from flask import Flask, request, send_file, Response import cv2 import os import io import sys import traceback app = Flask(__name__) FILESYSTEM = os.environ['FILESYSTEM'] if FILESYSTEM == 'google': config = StorageConfig.make_gcs_config(os.environ['BUCKET']) else: config = StorageConfig.make_posix_config() storage = StorageBackend.make_from_config(config) @app.route("/fetch") def fetch(): try: path = request.args.get('path') frame = int(request.args.get('frame')) scale = request.args.get('scale', None) height = request.args.get('height', None) if FILESYSTEM == 'local': path = '/host' + path video_file = RandomReadFile(storage, path.encode('ascii'))