[英]AttributeError at /app/ 'numpy.ndarray' object has no attribute 'read'
I am making a wep app for face recognition by django and face_recogntion api, I don't how to solve this error我正在制作一个通过 django 和 face_recogntion api 进行人脸识别的 wep 应用程序,我不知道如何解决这个错误
from django.http import HttpResponse
from django.shortcuts import redirect, render
from .models import *
import face_recognition
import cv2
import urllib.request
import numpy as np
import dlib
def Home(request):
print(f'request method is {request.method}')
if(request.method=='GET'):
return render(request, "app.html")
elif(request.method=='POST'):
print(f'printing req body {request.POST["imageURL"]}')
imageURL = urllib.request.urlopen(request.POST["imageURL"])
imageURL = face_recognition.load_image_file(imageURL)
image = face_recognition.load_image_file(imageURL)
image = cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
imgLoc = face_recognition.face_locations(image);
print(f'Image imagLoc {imgLoc}')
cv2.imshow(image)
cv2.waitKey(3000)
return redirect('/app/')
I am asking question on stackoverflow for the first time so sorry for any mistakes.我第一次在stackoverflow上提出问题,对于任何错误,我深表歉意。
Your problem is here:你的问题在这里:
imageURL = urllib.request.urlopen(request.POST["imageURL"])
imageURL = face_recognition.load_image_file(imageURL)
image = face_recognition.load_image_file(imageURL)
First第一的
imageURL = face_recognition.load_image_file(imageURL)
Now imageURL has numpy.ndarray
type.现在 imageURL 有numpy.ndarray
类型。 Then然后
image = face_recognition.load_image_file(imageURL)
And here you are trying to load image once again passing that numpy.ndarray
as an argument instead of passing image file path, ie string.在这里,您尝试再次加载图像,将numpy.ndarray
作为参数传递,而不是传递图像文件路径,即字符串。 I don't understand why you are trying to load that image twice.我不明白您为什么要尝试两次加载该图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.