我正在尝试提取绘制的图像,应在我的烧瓶Web应用程序上按“剪辑”按钮后再提取该图像。我无法组合从我的Web应用程序到python脚本的代码。 这是我的python脚本,在这里仍然是不完整的代码
from flask import Flask, render_template,request
import os
import cv2
import argparse
###################### READING IMAGE ###########################
img = cv2.imread('static/pics/img.png',0)
###################### UPLOADING PIC ############################
app = Flask(__name__)
picFolder = os.path.join('static', 'pics')
app.config['UPLOAD_FOLDER'] = picFolder
###############################################################
def shape_selection(event, x, y, flags, param):
# grab references to the global variables
global ref_point, crop
# if the left mouse button was clicked, record the starting
# (x, y) coordinates and indicate that cropping is being performed
if event == cv2.EVENT_LBUTTONDOWN:
ref_point = [(x, y)]
# check to see if the left mouse button was released
elif event == cv2.EVENT_LBUTTONUP:
# record the ending (x, y) coordinates and indicate that
# the cropping operation is finished
ref_point.append((x, y))
# draw a rectangle around the region of interest
cv2.rectangle(img, ref_point[0], ref_point[1], (0, 255, 0), 2)
####################### FLASK ###################################
@app.route("/")
def index():
UPLOAD_FOLDER='static/pics/';
pic1 = os.path.join(app.config['UPLOAD_FOLDER'], 'img.png')
pic2 = os.path.join(app.config['UPLOAD_FOLDER'], 'mask1.png')
return render_template("index.html", user_image=pic1,mask_image=pic2)
@app.route("/bonus")
def bonus():
# pic1 = os.path.join(app.config['UPLOAD_FOLDER'], 'img.png')
image = cv2.imread('static/pics/img.png', 0)
clone = image.copy()
cv2.namedWindow("image")
pic1= cv2.setMouseCallback("image", shape_selection)
return render_template("bonus.html", user_image=pic1)
app.run(debug=True)
这是我的HTML文件,我想在其中查看原始文件和裁剪文件