Python-Flask API图像

问题描述 投票:0回答:1

我有一个脚本,希望与Flask一起用作Rest API进行图像检测。这是女巫假定要接收并成像并传递到yolo检测的Flask部分:

#initialize FLASK api
app = Flask(__name__)
#POST route
@app.route('/api/test', methods=['POST'])
def test():
    r = request
    nparr = np.fromstring(r.data, np.uint8)
    image = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
    r_image, ObjectsList = yolo.detect_img(image)
    response = {ObjectsList}
    response_pikled = jsonpickle.encode(response)

    return Response(response=response_pikled, status=200, mimetype="application/json")
app.run(host="localhost", port=5000)

当我使用CURL命令测试传递本地图像时:

curl -i -H "content-type: image/jpeg" --data "@c:/yolo/desktop.jpg" -X POST "http://localhost:5000/api/test"

我收到以下错误消息:

127.0.0.1 - - [17/Dec/2019 23:30:14] "?[1m?[35mPOST /api/test HTTP/1.1?[0m" 500 -
Corrupt JPEG data: 14 extraneous bytes before marker 0x3a
[2019-12-17 23:32:08,335] ERROR in app: Exception on /api/test [POST]
File "c:/yolo/YOLOv3-object-detection-tutorial/YOLOv3-custom-training/image_detect_api.py", line 27, in test
    r_image, ObjectsList = yolo.detect_img(image)
  File "c:/yolo/YOLOv3-object-detection-tutorial/YOLOv3-custom-training/image_detect_api.py", line 173, in detect_img
    original_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
cv2.error: OpenCV(4.1.2) C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

我可以毫无问题地打开文件。我想念什么吗?谢谢

python-3.x opencv flask yolo
1个回答
0
投票

来自cv2.imread的此问题您应该检查图像是否在您给出的路径中,然后检查count变量(如果他具有有效的数字)

© www.soinside.com 2019 - 2024. All rights reserved.