简体   繁体   English

/app/ 'numpy.ndarray' 对象的 AttributeError 没有属性 'read'

[英]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.

相关问题 AttributeError:“ numpy.ndarray”对象没有属性“ A” - AttributeError: 'numpy.ndarray' object has no attribute 'A' 'numpy.ndarray' object 没有属性 'read' - 'numpy.ndarray' object has no attribute 'read' Numpy和Matplotlib-AttributeError:“ numpy.ndarray”对象没有属性“ replace” - Numpy and Matplotlib - AttributeError: 'numpy.ndarray' object has no attribute 'replace' AttributeError: 'numpy.ndarray' 对象没有属性 'insert' - AttributeError: 'numpy.ndarray' object has no attribute 'insert' AttributeError - 'numpy.ndarray' 对象没有属性 'drop' - AttributeError - 'numpy.ndarray' object has no attribute 'drop' AttributeError:“ numpy.ndarray”对象没有属性“ powers_” - AttributeError: 'numpy.ndarray' object has no attribute 'powers_' AttributeError:'numpy.ndarray'对象没有属性'sin'? - AttributeError: 'numpy.ndarray' object has no attribute 'sin'? AttributeError: 'numpy.ndarray' 对象没有属性 'clock' - AttributeError: 'numpy.ndarray' object has no attribute 'clock' AttributeError:'numpy.ndarray'对象没有属性'median' - AttributeError: 'numpy.ndarray' object has no attribute 'median' AttributeError: 'numpy.ndarray' 对象没有属性 'history' - AttributeError: 'numpy.ndarray' object has no attribute 'history'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM