def get(self, id): '''render interactive 3d scene for result with motion capturing data for a job by id''' args = filter_parser.parse_args(strict=True) headers = {'Content-Type': 'text/html'} num_people = model.get_result_by_id(id).max_people urls = [] if args['border'] is None or args['u0'] is None: for i in range(1, num_people + 1): urls.append( url_for('api.results_result_bvh_file_for_person', id=id, person_id=i)) else: for i in range(1, num_people + 1): #ResultBvhFileForPersonFiltered urls.append( url_for('api.results_result_bvh_file_for_person', id=id, person_id=i, border=args['border'], u0=args['u0'])) print(urls) return make_response( render_template('bvh_import/index.html', title=model.get_job_by_id(id).name, url_array=urls), 200, headers)
def delete(self, id): '''Delete a job by a given id''' job = model.retrieve_job(id) check_auth(job, auth.get_auth()) if model.get_result_by_id(job.id).result_code == ResultCode.pending: return 400 return model.delete_job(job.id)
def get(self, id, person_id): '''Returns bvh-Files by person index (counting from 0) for a job by id''' args = filter_parser.parse_args(strict=True) result = model.get_result_by_id(id) if result is None: return 404 if result.result_code is not model.ResultCode.success: return 202 if person_id > result.max_people or person_id < 1: raise BadRequest("Person %d does not exist - Max index is %d." % (person_id, result.max_people)) path = os.path.join(Config.CACHE_DIR, str(result.id), Config.RESULT_DIR) job = model.get_job_by_id(id) myfile = "%s by %s (%d-%d).bvh" % (job.name, job.user.username, person_id, result.max_people) if args['border'] is not None and args['u0'] is not None: filter_bvh(result.id, args['border'], args['u0'], person_id) return send_from_directory( path, Config.OUTPUT_BVH_FILE_FILTERED_DYNAMIC_NUMBERED % person_id, as_attachment=True, attachment_filename=myfile, mimetype="application/octet-stream") return send_from_directory(path, Config.OUTPUT_BVH_FILE_RAW_NUMBERED % person_id, as_attachment=True, attachment_filename=myfile, mimetype="application/octet-stream")
def get(self, id): '''get result video for a job by id (visualization of joints) -- replaced by "results/{id}/render_html"''' check_auth(model.get_job_by_id(id), auth.get_auth()) result = model.get_result_by_id(id) if result is None: return 404 if result.result_code is not model.ResultCode.success: return 202 path = os.path.join(Config.CACHE_DIR, str(result.id), Config.RESULT_DIR) return send_from_directory(path, Config.OUTPUT_VIDEO_FILE, as_attachment=True, attachment_filename=str(result.id) + ".mp4", mimetype="video/mp4")
def get(self, id): '''Deprecated''' result = model.get_result_by_id(id) if result is None: return 404 if result.result_code is not model.ResultCode.success: return 202 path = os.path.join(Config.CACHE_DIR, str(result.id), 'results/imgs/2d_pose_vis') # create zip base_path = pathlib.Path(path) data = io.BytesIO() with zipfile.ZipFile(data, mode='w') as z: for f_name in base_path.iterdir(): z.write(f_name) data.seek(0) return {"status": "deprecated"}
def get_job_status(id): try: job = RedisJob.fetch(str(id), connection=conn) except NoSuchJobError as e: res = model.get_result_by_id(id) if res: if res.result_code == ResultCode.pending: return {"finished": False} else: return {"finished": True} return {"message": "job not found"}, 404 if job.is_finished: return {"finished": True} else: if job.is_failed: return {"finished": False, "problem": True} if 'stage' in job.meta: return {"stage": job.meta['stage'], "finished": False} return {"stage": {"name": "pending"}, "finished": False}
def get(self, id): '''Returns bvh-Files for a result as zip (or as .bvh, if only one person was tracked) for a job by id''' result = model.get_result_by_id(id) job = model.get_job_by_id(id) if result is None: return 404 if result.result_code is not model.ResultCode.success: return 202 path = os.path.join(Config.CACHE_DIR, str(result.id), Config.RESULT_DIR) # return 1 person if result.max_people == 1: myfile = "%s by %s (%d-%d).bvh" % (job.name, job.user.username, 1, result.max_people) return send_from_directory(path, Config.OUTPUT_BVH_FILE_RAW_NUMBERED % 1, as_attachment=True, attachment_filename=myfile, mimetype="application/octet-stream") return serve_zip(job, result)
def get(self, id): '''get results for a job by id''' check_auth(model.get_job_by_id(id), auth.get_auth()) return model.get_result_by_id(id)
def prepare(my_job_id, video): """ prepare a job and return several parameters :param my_job_id: database id of the job :param video: video file as bytes array """ from project.model import model # get the current job job = get_current_job() job.meta['stage'] = {'name': 'preparing', 'progress': None} # get the redis id for the job job_id = str(get_current_job().get_id()) # add to database job_cache_dir = Path(os.path.join(Config.CACHE_DIR, str(my_job_id))) # The cache dir will look like that : cache/aabb-ccc-dddd-fff-ggg/ (UUID) # Create a directory where the cache is stored. if not job_cache_dir.exists(): os.makedirs(job_cache_dir) # save the source video in the cache folder filename = os.path.join(job_cache_dir, Config.SOURCE_VIDEO_FILE) print("Saving video at %s" % filename) with (open(filename, 'wb')) as file: file.write(video) file.close() # save thumbnail videogen = skvideo.io.FFmpegReader(filename) for frame in videogen.nextFrame(): thumbnail_path = job_cache_dir / Config.THUMBNAIL_FILE skvideo.io.vwrite(str(thumbnail_path), frame) videogen.close() break # retrieve the fps from the video fps = videogen.inputfps # result result = model.get_result_by_id(my_job_id) result.result_code = model.ResultCode.pending model.db.session.commit() result_cache_dir = Path(os.path.join(job_cache_dir, Config.RESULT_DIR)) if not result_cache_dir.exists(): os.makedirs(result_cache_dir) # get specific file locations pose2d_file = result_cache_dir / Config.DATA_2D_FILE pose3d_file = result_cache_dir / Config.DATA_3D_FILE # create a thumbnail job.meta['stage'] = {'name': 'thumbnail'} job.save_meta() pose3d_world = None points_list = None job.meta['stage'] = {'name': '2d', 'progress': 0} job.save_meta() return job, job_id, model, job_cache_dir, pose2d_file, pose3d_file, thumbnail_path, filename, result, \ result_cache_dir, fps