简体   繁体   English

resize.cpp:4052: error: (-215:Assertion failed).ssize:empty() in function 'cv::resize'

[英]resize.cpp:4052: error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'

I am taking the picture from my app and uploading it on flask and on flask I am running the below python code to take the recently uploaded image from flask and perform the detection and extracting the number plate of vehicle from the image. I am taking the picture from my app and uploading it on flask and on flask I am running the below python code to take the recently uploaded image from flask and perform the detection and extracting the number plate of vehicle from the image. The actual error I ran into is the image is uploading on flask safe and fine but is showing invalid for the detection in the form of above error.我遇到的实际错误是图像正在 flask 上安全且正常上传,但以上述错误的形式显示对检测无效。

from fileinput import filename
from flask import Flask, request, jsonify
import cv2
import imutils
import numpy as np
import pytesseract
import werkzeug


app = Flask(__name__)  #creating flask server


@app.route('/upload', methods=["POST"])   #defining the route of pages
def upload():
    if(request.method == "POST"):
        imagefile = request.files['image']
        imagefile2=str(imagefile)
        # print('12132')
        filename = werkzeug.utils.secure_filename(imagefile.filename)
        
        imagefile.save("./uploadedimages/"+filename)
        pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files (x86)\Tesseract-OCR\tesseract.exe'
        
        img = cv2.imread(imagefile,cv2.IMREAD_COLOR)
        # print (imagefile2)
        img = cv2.resize(img, dsize=(600,400) )
        gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) 
        gray = cv2.bilateralFilter(gray, 13, 15, 15) 
        edged = cv2.Canny(gray, 30, 200) 
        contours = cv2.findContours(edged.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
        contours = imutils.grab_contours(contours)
        contours = sorted(contours, key = cv2.contourArea, reverse = True)[:10]
        screenCnt = None
        
        for c in contours:
            peri = cv2.arcLength(c, True)
            approx = cv2.approxPolyDP(c, 0.018 * peri, True)
            
            if len(approx) == 4:
                screenCnt = approx
                break
        
        if screenCnt is None:
            detected = 0
            print ("No contour detected")
        else:
            detected = 1
            
        if detected == 1:
            cv2.drawContours(img, [screenCnt], -1, (0, 0, 255), 3)
        
        mask = np.zeros(gray.shape,np.uint8)
        new_image = cv2.drawContours(mask,[screenCnt],0,255,-1,)
        new_image = cv2.bitwise_and(img,img,mask=mask)
        
        (x, y) = np.where(mask == 255)
        (topx, topy) = (np.min(x), np.min(y))
        (bottomx, bottomy) = (np.max(x), np.max(y))
        Cropped = gray[topx:bottomx+1, topy:bottomy+1]
        
        text = pytesseract.image_to_string(Cropped, config='--psm 11')
        print("programming_fever's License Plate Recognition\n")
        print("Detected license plate Number is:",text)
        img = cv2.resize(img,(500,300))
        Cropped = cv2.resize(Cropped,(400,200))
        cv2.imshow('car',img)
        cv2.imshow('Cropped',Cropped)
        cv2.waitKey(0)
        cv2.destroyAllWindows()

        return jsonify({
            "message":"Uploaded"
        })

if __name__ == "__main__":
    app.run(debug=True, port=4000 )

I have tried converting the image into string but didn't worked out.我尝试将图像转换为字符串,但没有成功。 I am using flutter for app.我正在为应用程序使用 flutter。 And below the is the app screen code where the response of the flask is being recieved.下面是正在接收 flask 响应的应用程序屏幕代码。

uploadImage() async {
    final request = http.MultipartRequest(
        "POST", Uri.parse("https://6a6d-59-103-181-239.ngrok.io/upload"));

    final headers = {"Content-type": "multipart/form-data"};

    request.files.add(http.MultipartFile('image',
        selectedImage.readAsBytes().asStream(), selectedImage.lengthSync(),
        filename: selectedImage.path.split("/").last));

    request.headers.addAll(headers);
    final response = await request.send();
    http.Response res = await http.Response.fromStream(response);
    final resJson = jsonDecode(res.body);
    message = resJson['message'];
    setState(() {});
  }

cv2 bindings for OpenCV have cryptic ways of telling you that you inadvertently passed None . cv2的 cv2 绑定有神秘的方式告诉您您无意中通过了None Here这里

img = cv2.imread(imagefile,cv2.IMREAD_COLOR)

is likely returning None, possibly because you meant to pass可能返回无,可能是因为您打算通过

"./uploadedimages/"+filename

instead of imagefile .而不是imagefile

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 cv2.error: OpenCV(4.5.2) resize.cpp:4051: error: (-215:Assertion failed).ssize:empty() in function 'cv::resize' - cv2.error: OpenCV(4.5.2) resize.cpp:4051: error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize' 错误:(-215:Assertion failed).ssize.empty() in function 'resize' - Error: (-215:Assertion failed) !ssize.empty() in function 'resize' CV2 图像错误:错误:(-215:Assertion failed).ssize:empty() in function 'cv::resize' - CV2 Image Error: error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize' OPEN-CV 错误:(-215:Assertion failed).ssize:empty() in function 'cv::resize' - OPEN-CV error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize' 错误:OpenCV(4.1.0) 错误:(-215:Assertion failed) !ssize.empty() in function 'cv::resize' - error: OpenCV(4.1.0) error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize' OpenCV(4.1.2) 错误: (-215:Assertion failed).ssize:empty() in function 'cv::resize' - OpenCV(4.1.2) error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize' 此错误的问题: (-215:Assertion failed).ssize:empty() in function 'cv::resize' OpenCV - Problem with this error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize' OpenCV 在函数 'cv::resize' 中检索 opencv 错误(-215:Assertion failed)!ssize.empty() - Retrieving opencv error (-215:Assertion failed) !ssize.empty() in function 'cv::resize' 错误:(-215:Assertion failed).ssize.empty() in function 'resize' 在为框架设置 cv2.resize 时出现 - error: (-215:Assertion failed) !ssize.empty() in function 'resize' shows up when setting a cv2.resize for frame OpenCV(4.2.0),imwrite() 到子文件夹会破坏模块; cv2.error: (-215:Assertion failed).ssize:empty() in function 'cv::resize'`' - OpenCV(4.2.0),imwrite() to a subfolder breaks the module; cv2.error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'`'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM