Javascript 将画布图像从js提取到flask但是图像';的背景变白为透明
我一直在做一个项目,我必须将画布图像发送到烧瓶,但每次发送到烧瓶时,它都会失去白色背景,变得透明 我的问题是,如何拍摄白色背景的图像 我已经尝试了这么多代码,但都不适合我 代码如下: js: python:Javascript 将画布图像从js提取到flask但是图像';的背景变白为透明,javascript,python,flask,canvas,Javascript,Python,Flask,Canvas,我一直在做一个项目,我必须将画布图像发送到烧瓶,但每次发送到烧瓶时,它都会失去白色背景,变得透明 我的问题是,如何拍摄白色背景的图像 我已经尝试了这么多代码,但都不适合我 代码如下: js: python: @app.route("/predict",methods = ['GET','POST']) def predict(): #code-1 data = request.values['url'] encoded_data = data.spl
@app.route("/predict",methods = ['GET','POST'])
def predict():
#code-1
data = request.values['url']
encoded_data = data.split(',')[1]
nparr = np.fromstring(encoded_data.decode('base64'), np.uint8)
img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
cv2.imshow(img)
cv2.waitKey(10)
cv2.destroyAllWindows()
#code-2
data_url = request.args.get('url') # here parse the data_url out http://xxxxx/?image={dataURL}
content = data_url.split(';')[1]
image_encoded = content.split(',')[1]
body = base64.decodebytes(image_encoded.encode('utf-8'))
img = Image.open(body)
#code-3
resp = urllib2.urlopen(url)
img = Image.open(urlopen(url).read())
img = Image.open(requests.get(url, stream=True).raw)
听起来你的图像一开始并没有白色背景。您可能正在绘制一个在画布上有透明部分的PNG,并让画布元素(或其后面的东西)的背景色“透亮”…?
@app.route("/predict",methods = ['GET','POST'])
def predict():
#code-1
data = request.values['url']
encoded_data = data.split(',')[1]
nparr = np.fromstring(encoded_data.decode('base64'), np.uint8)
img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
cv2.imshow(img)
cv2.waitKey(10)
cv2.destroyAllWindows()
#code-2
data_url = request.args.get('url') # here parse the data_url out http://xxxxx/?image={dataURL}
content = data_url.split(';')[1]
image_encoded = content.split(',')[1]
body = base64.decodebytes(image_encoded.encode('utf-8'))
img = Image.open(body)
#code-3
resp = urllib2.urlopen(url)
img = Image.open(urlopen(url).read())
img = Image.open(requests.get(url, stream=True).raw)