def post(self): dbm = access.DBMan(LOST_CONFIG) identity = get_jwt_identity() user = dbm.get_user_by_id(identity) if not user.has_role(roles.ANNOTATOR): dbm.close_session() return "You need to be {} in order to perform this request.".format( roles.ANNOTATOR), 401 else: data = json.loads(request.data) img = dbm.get_image_anno(data['imageId']) flask.current_app.logger.info('img.img_path: {}'.format( img.img_path)) flask.current_app.logger.info('img.fs.name: {}'.format( img.fs.name)) # fs_db = dbm.get_fs(img.fs_id) fs = FileMan(fs_db=img.fs) #img = PIL.Image.open('/home/lost/data/media/10_voc2012/2007_008547.jpg') # img = PIL.Image.open(img_path) if data['clahe']['active']: img = fs.load_img(img.img_path, color_type='gray') else: img = fs.load_img(img.img_path, color_type='color') flask.current_app.logger.info( 'Triggered filter. Received data: {}'.format(data)) # img_io = BytesIO() # img.save(img_io, 'PNG') # img_io.seek(0) # return send_file(img_io, mimetype='image/png') if data['rotate']['active']: if data['rotate']['angle'] == 90: img = cv2.rotate(img, cv2.ROTATE_90_CLOCKWISE) elif data['rotate']['angle'] == -90: img = cv2.rotate(img, cv2.ROTATE_90_COUNTERCLOCKWISE) elif data['rotate']['angle'] == 180: img = cv2.rotate(img, cv2.ROTATE_180) if data['clahe']['active']: clahe = cv2.createCLAHE(data['clahe']['clipLimit']) img = clahe.apply(img) # img = img.rotate(data['rotate']['angle'], expand=True) # img = ImageOps.autocontrast(img) # data = BytesIO() # img.save(data, "PNG") _, data = cv2.imencode('.jpg', img) data64 = base64.b64encode(data.tobytes()) dbm.close_session() return u'data:img/jpg;base64,' + data64.decode('utf-8')
def post(self): dbm = access.DBMan(LOST_CONFIG) identity = get_jwt_identity() user = dbm.get_user_by_id(identity) # raise Exception('lostsession: {}'.format(dask_session.ds_man.session)) if not user.has_role(roles.ANNOTATOR): dbm.close_session() return "You need to be {} in order to perform this request.".format( roles.ANNOTATOR), 401 else: #TODO: Check if user is permitted to load this image #TODO: Read img from stream -> cv2.imdecode() data = json.loads(request.data) flask.current_app.logger.info( 'sia -> getimage. Received data: {}'.format(data)) db_img = dbm.get_image_anno(data['imgId']) if LOST_CONFIG.worker_management != 'dynamic': fm = FileMan(fs_db=db_img.fs) flask.current_app.logger.info( 'sia -> getimage. fs.name: {} fs.root_path: {}'.format( db_img.fs.name, db_img.fs.root_path)) img = fm.load_img(db_img.img_path) else: img = dask_session.ds_man.read_fs_img(user, db_img.fs, db_img.img_path) flask.current_app.logger.info( 'dask_session read_fs_img type: {}'.format(type(img))) flask.current_app.logger.info( 'dask_session read_fs_img shape: {}'.format(img.shape)) # img_path = fm.get_abs_path(db_img.img_path) # #raise Exception('sia -> getimage: {}'.format(img_path)) # img = cv2.imread(img_path) _, data = cv2.imencode('.jpg', img) data64 = base64.b64encode(data.tobytes()) dbm.close_session() return u'data:img/jpg;base64,' + data64.decode('utf-8')
def _read_fs_img(fs, img_path): fm = FileMan(fs_db=fs) img = fm.load_img(img_path) return img