def style_qlssh_is(): """ 青山绿水图保留原色 @param image:base64编码后的图片字符串,如data:image/jpg;base64,/9j/4AAQSkZJRgABAQ... @param alpha:参数 @return code(200=正常返回,400=错误),url:图片地址 """ param = request.get_json() img_base64 = param.get('image') alpha = float(param.get('alpha')) user_id = param.get('id') if not all([img_base64, alpha]): return jsonify(code=400, msg='lack of parameters') img_path = utils.base64_to_imagefile(img_base64, save_path=INPUT_PATH) output_img_url = using_model(img_path, STYLE_QLSSH_PATH, alpha, True) img_url = HOST + '/' + str(output_img_url) if not user_id: return jsonify(url=img_url, code=200, msg='success without id') try: image = Image(url=img_url) db.session.add(image) db.session.flush() t = int(time.time()) relation = Transfer(user_id=user_id, image_id=image.id, timestamp=str(t)) db.session.add(relation) db.session.commit() return jsonify(url=img_url, code=200, msg='success with id') except Exception as e: return jsonify(url=img_url, code=500, msg='database error')
def Style_is(content, style, alpha, preserve_color): path = using_model(content, style, alpha, preserve_color) img01 = cv2.imread(str(path)) img_medianBlur = cv2.medianBlur(img01, 3) cv2.imwrite(str(path), img_medianBlur) return path
def Style_no(content, style, alpha): path = using_model(content, style, alpha) img01 = cv2.imread(str(path)) img_medianBlur = cv2.medianBlur(img01, 3) cv2.imwrite(str(path), img_medianBlur) return path