face_recognition python flask不处理通过的图像

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

我制作了Flask API,我想将图像从Flutter应用传递到API POST端点。我成功传输了图像,但是当我想在[]中使用它时

  first_image = face_recognition.load_image_file(image_from_post_request or down below image1)

它只是给我错误!

[当我尝试将此功能与本地保存的图像一起使用时,它将起作用。例如:

  first_image = face_recognition.load_image_file('./img/mj.png')

我已经尝试过在本地保存该帖子图像,然后对其进行解析,但这是行不通的。我是一个初学者,因此将不胜感激。

谢谢

我的代码:

@app.route('/compare', methods=['POST'])
  def compare():
  image1 = request.files['face1']
  image2 = request.files['face2']

  first_image = face_recognition.load_image_file(image1)
  first_image_encoding = face_recognition.face_encodings(first_image)[0]


  unknown_image = face_recognition.load_image_file(image2)
  second_image_encoding = face_recognition.face_encodings(unknown_image)[0]

  results = face_recognition.compare_faces([first_image_encoding], second_image_encoding)

  if results[0]:
      print('These images are same')
      return jsonify({'response' : 'These images are same'})
  else: 
      print('These images are not same')
      return jsonify({'response' : 'These images are not same'})

错误:

127.0.0.1 - - [25/May/2020 00:07:05] "POST /compare HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/Users/bilal/.local/share/virtualenvs/face_reck_api-svbO_hqN/lib/python3.8/site-packages/flask/app.py", line 2464, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/bilal/.local/share/virtualenvs/face_reck_api-svbO_hqN/lib/python3.8/site-packages/flask/app.py", line 2450, in wsgi_app
    response = self.handle_exception(e)
  File "/Users/bilal/.local/share/virtualenvs/face_reck_api-svbO_hqN/lib/python3.8/site-packages/flask/app.py", line 1867, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/bilal/.local/share/virtualenvs/face_reck_api-svbO_hqN/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/Users/bilal/.local/share/virtualenvs/face_reck_api-svbO_hqN/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/bilal/.local/share/virtualenvs/face_reck_api-svbO_hqN/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/bilal/.local/share/virtualenvs/face_reck_api-svbO_hqN/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/bilal/.local/share/virtualenvs/face_reck_api-svbO_hqN/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/Users/bilal/.local/share/virtualenvs/face_reck_api-svbO_hqN/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/bilal/.local/share/virtualenvs/face_reck_api-svbO_hqN/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/bilal/Desktop/Python/face_reck_api/app.py", line 74, in someting
    first_image_encoding = face_recognition.face_encodings(first_image)[0]
IndexError: list index out of range

我制作了Flask API,我想将图像从Flutter应用传递到API POST端点。我成功传输了图像,但是当我想在first_image = face_recognition ...中使用它时。

python flask image-processing face-recognition flask-restful
1个回答
0
投票

由于我没有足够的声誉来发表评论,因此我将在此处添加它

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