'Error passing image path to Flask application

I have a Flask application that it supposed to receive two images and output a , but when I run the app I get these errors, the code is working perfectly without Flask

Errors:

[ WARN:[email protected]] global /io/opencv/modules/imgcodecs/src/loadsave.cpp (239) findDecoder imread_('/home/criuser/Téléchargements/20210728_122019.jpg'): can't open/read file: check file path/integrity
[2022-02-15 22:17:15,439] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
  File "/home/criuser/PycharmProjects/FINAL_AI/venv/lib/python3.8/site-packages/flask/app.py", line 2073, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/criuser/PycharmProjects/FINAL_AI/venv/lib/python3.8/site-packages/flask/app.py", line 1518, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/criuser/PycharmProjects/FINAL_AI/venv/lib/python3.8/site-packages/flask/app.py", line 1516, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/criuser/PycharmProjects/FINAL_AI/venv/lib/python3.8/site-packages/flask/app.py", line 1502, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/home/criuser/PycharmProjects/FINAL_AI/venv/final.py", line 19, in API
    result = change_bg.change_bg_img(f_image_path=original,
  File "/home/criuser/PycharmProjects/FINAL_AI/venv/lib/python3.8/site-packages/pixellib/tune_bg/__init__.py", line 236, in change_bg_img
    seg_image = self.segmentAsPascalvoc(f_image_path)
  File "/home/criuser/PycharmProjects/FINAL_AI/venv/lib/python3.8/site-packages/pixellib/tune_bg/__init__.py", line 53, in segmentAsPascalvoc
    h, w, n = image.shape
AttributeError: 'NoneType' object has no attribute 'shape'
127.0.0.1 - - [15/Feb/2022 22:17:15] "GET /?original=/home/criuser/Téléchargements/20210728_122019.jpg&background=/home/criuser/Téléchargements/Tableau_Dashboard.jpg HTTP/1.1" 500 -

Code:

curl "http://127.0.0.1:5000?original=/home/criuser/Téléchargements/20210728_122019.jpg&background=/home/criuser/Téléchargements/Tableau_Dashboard.jpg"

@app.route('/',methods=['GET'])
def API():
    if request.method == 'GET':
        original = request.args.get('original')
        background = request.args.get('background')
        change_bg = alter_bg(model_type="pb")
        change_bg.load_pascalvoc_model("/home/criuser/Téléchargements/xception_pascalvoc.pb")
        result = change_bg.change_bg_img(f_image_path=original,
                                b_image_path=background,
                                output_image_name="/home/criuser/Téléchargements/new.jpg")
        img_base64 = base64.b64encode(result.read())
        return jsonify(img_base64.decode())


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source