Images can not be saved with cv2.imwrite.

import os
import io import numpy as np import numpy.random as ran import random import string import cv2 from werkzeug import secure_filename from flask import Flask, render_template, request, redirect, url_for, send_from_directory app = Flask(name)

UPLOAD_FOLDER = './uploads'
ALLOWED_EXTENSIONS = set(['png', 'jpg', 'PNG', 'JPG'])
app.config['SECRET_KEY'] = os.urandom(24)

def allowed_file(filename):
    return '.' in filename and \
        filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS

def index():
    return render_template('index.html')

@app.route('/send', methods=['GET', 'POST'])
def send():
if request.method == 'POST':
    img_file = request.files['img_file']
    if img_file and allowed_file(img_file.filename):
        filename = secure_filename(img_file.filename)
        return render_template('index.html',name="許可されていない拡張子です。")
    f =
    bin_data = io.BytesIO(f)
    file_bytes = np.asarray(bytearray(, dtype=np.uint8)
    img = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR)
    dst = cv2.Laplacian(img, cv2.CV_32F, ksize=3)
    height, width, ch = dst.shape
    if(width > 1500):
        if (height > 1500):
            return render_template('index.html', name="ファイルサイズが上限を超えています。")
    if(height > 1500):
        if (width > 1500):
            return render_template('index.html', name="ファイルサイズが上限を超えています。")
    for i in range(height):
        blue = ran.randint(255)
        red = ran.randint(255)
        gleen = ran.randint(255)
        for j in range(width):
            if (dst[i, j, 0] >= 80):
                dst = cv2.line(dst, (j, i), (j, i), (blue, red, gleen), 1)
    img_url = os.path.join(app.config['UPLOAD_FOLDER'],''.join(random.choices(string.ascii_letters + string.digits, k=4))+'.png')
    cv2.imwrite(img_url, dst)
    return render_template('index.html',gray_img_url=img_url)
    return redirect(url_for('index'))

def uploaded_file(filename):
return send_from_directory(app.config['UPLOAD_FOLDER'], filename)

if __name__ == '__main__':

I want to see the image I sent, but why is not cv2.imwrite saved in the uploads directory.

See about the use of paths in web apps.

my images is not reading using


please fix it

What errors do you see?