def colorizer(): if request.method == 'POST': global handling_filename npimg = np.array( Image.open( os.path.join(app.config['UPLOAD_PATH'], 'test' + handling_filename))).astype(np.float32) imgbase64 = request.values.get('image').split(",")[1] left = float(request.values.get('left')) right = float(request.values.get('right')) up = float(request.values.get('up')) down = float(request.values.get('down')) mark = Basicprocess().base64_to_rgb(imgbase64) mark = np.array(mark) markforcut = np.zeros(mark.shape[:2]) markforcut[int(up) - 1:int(down) + 2, int(left) - 1:int(right) + 2] = gb.P_fgd mark[int(up) - 1:int(up) + 2, :] = 0 mark[int(down) - 1:int(down) + 2, :] = 0 mark[:, int(left) - 1:int(left) + 2] = 0 mark[:, int(right) - 1:int(right) + 2] = 0 markforcut[np.where(mark[:, :, 0] > 200)] = gb.GT_fgd markforcut[np.where(mark[:, :, 1] > 200)] = gb.GT_bgd ##we use red to mark foreground and green to mark background retimg = gb(1, npimg, markforcut) img_str = Basicprocess().img2base64(retimg) return jsonify({'code': 200, 'img64': img_str}) if request.method == 'GET': return jsonify({'code': 0, 'progress': 0})
def filtering(method): if session.get('handlingfile_filter') is not None: img_path = os.path.join(app.config['UPLOAD_PATH'], session.get('handlingfile_filter')) filtering = Filtering(img_path) #buffered = BytesIO() if method == "mean-filter": img = filtering.mean_filter() elif method == "median-filter": img = filtering.median_filter() elif method == "gaussian-filter": img = filtering.gaussian_filter() elif method == "bilateral-filter": img = filtering.bilateral_filter() session['handlingfile_filter_tmp'] = osutils().add_tmp_in_filename( session.get('handlingfile_filter')) img.save(os.path.join(app.config['UPLOAD_PATH'], session['handlingfile_filter_tmp']), format="PNG") img_str = Basicprocess().img2base64(img) return jsonify({'code': 200, 'img64': img_str}) else: return jsonify({'code': 404})
def show_photo(): if request.method == 'GET': global handling_filename img = Image.open( os.path.join(app.config['UPLOAD_PATH'], handling_filename)) img = img.resize((400, 400)) img.save( os.path.join(app.config['UPLOAD_PATH'], 'test' + handling_filename)) img_str = Basicprocess().img2base64(img) return jsonify({'code': 200, 'img64': img_str})
def colorizer(): if request.method == 'POST': if session.get('handlingfile_colorizer') is not None: imgbase64 = request.values.get('image').split(",")[1] #basicprocess=Basicprocess() mark = Basicprocess().base64_to_rgb(imgbase64) img_path = os.path.join(app.config['UPLOAD_PATH'], session.get('handlingfile_colorizer')) img = cl.colorize(img_path, mark) #buffered=BytesIO() #img.save(buffered, format="PNG") #img_str = base64.b64encode(buffered.getvalue()).decode('utf-8') session['handlingfile_colorizer_tmp'] = osutils( ).add_tmp_in_filename(session.get('handlingfile_colorizer')) img.save(os.path.join(app.config['UPLOAD_PATH'], session['handlingfile_colorizer_tmp']), format="PNG") img_str = Basicprocess().img2base64(img) return jsonify({'code': 200, 'img64': img_str}) else: return jsonify({'code': 404}) if request.method == 'GET': return jsonify({'code': 0, 'progress': cl.get_progress()})
def show_photo(method): if request.method == 'GET': str = "handlingfile_" + method if session.get(str) is not None: #buffer=BytesIO() print(os.path.join(app.config['UPLOAD_PATH'], session.get(str))) img = Image.open( os.path.join(app.config['UPLOAD_PATH'], session.get(str))) img = img.resize((400, 400)) #img.save(buffer,'PNG') img.save(os.path.join(app.config['UPLOAD_PATH'], session.get(str)), 'PNG') #img_str = base64.b64encode(buffer.getvalue()).decode('utf-8') img_str = Basicprocess().img2base64(img) return jsonify({'code': 200, 'img64': img_str}) else: return jsonify({'code': 404})
def dehaze(): if session.get('handlingfile_dehaze') is not None: img_path = os.path.join(app.config['UPLOAD_PATH'], session.get('handlingfile_dehaze')) img = Dehaze().deHaze(img_path) #buffered = BytesIO() #img.save(buffered, format="PNG") #img_str = base64.b64encode(buffered.getvalue()).decode('utf-8') session['handlingfile_dehaze_tmp'] = osutils().add_tmp_in_filename( session.get('handlingfile_dehaze')) img.save(os.path.join(app.config['UPLOAD_PATH'], session['handlingfile_dehaze_tmp']), format="PNG") img_str = Basicprocess().img2base64(img) return jsonify({'code': 200, 'img64': img_str}) else: return jsonify({'code': 404})
def searchimg(): ''' #img_path = os.path.join(app.config['UPLOAD_PATH'], session.get('handlingfile_search')) #imgpathlist=.GetImageFeature('../205.jpg') img_url = {"code": 200, "len": 7} for i in range(7): imgpath='files/wanglijuan/searchpath/'+str(i)+'.jpg' img_url['img'+str(i)]=Basicprocess().img2base64(Image.open(imgpath)) return jsonify(img_url) ''' if session.get('handlingfile_search') is not None: img_path = os.path.join(app.config['UPLOAD_PATH'], session.get('handlingfile_search')) imgpathlist = searchimage().GetImageFeature(img_path) img_url = {"code": 200, "len": 7} for idx, path in enumerate(imgpathlist): img_url['img' + str(idx)] = Basicprocess().img2base64( Image.open(path)) return jsonify(img_url) else: return jsonify({'code': 404})
def basicprocess(method): if session.get('handlingfile_basicprocess') is not None: radio = request.form[method] img_path = os.path.join(app.config['UPLOAD_PATH'], session.get('handlingfile_basicprocess')) #basic_process = #buffered = BytesIO() if method == "contrast": img = Basicprocess().change_contrast(img_path, float(radio)) elif method == "value": img = Basicprocess().change_value_quick(img_path, float(radio)) elif method == "saturation": img = Basicprocess().change_saturation_quick( img_path, float(radio)) elif method == "hue": img = Basicprocess().change_hue_quick(img_path, float(radio)) session['handlingfile_basicprocess_tmp'] = osutils( ).add_tmp_in_filename(session.get('handlingfile_basicprocess')) img.save(os.path.join(app.config['UPLOAD_PATH'], session['handlingfile_basicprocess_tmp']), format="PNG") #img.save(buffered, format="PNG") #img_str = base64.b64encode(buffered.getvalue()).decode('utf-8') img_str = Basicprocess().img2base64(img) return jsonify({'code': 200, 'img64': img_str}) else: return jsonify({'code': 404})