什么是剂量误差->
ret, im =image.read(); AttributeError: 'JpegImageFile' object has no attribute 'read'.
我正在从事图像处理工作,我编写了一个程序来检测人脸(在实时摄像头上),并且正在运行。我正在使用python2.7.12 code->
python
import cv2
import numpy as np
from PIL import Image
id=0
recognizer = cv2.face.LBPHFaceRecognizer_create()
recognizer.read('recognizer/trainner.yml')
cascadePath = "haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(cascadePath);
cam = cv2.VideoCapture(0)
fontFace = cv2.FONT_HERSHEY_SIMPLEX
fontScale = 1
fontColor = (255, 255, 255)
while True:
ret, im =cam.read();
gray=cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
faces=faceCascade.detectMultiScale(gray, 1.2,5)
for(x,y,w,h) in faces:
cv2.rectangle(im,(x,y),(x+w,y+h),(225,0,0),2)
id,conf = recognizer.predict(gray[y:y+h,x:x+w])
print(id)
if id==2:
id="mohan"
elif id==3:
id="krishna"
elif id==4:
id="satyam"
elif id==5:
id="Priyavrat"
elif id==0:
id="Unknown"
cv2.putText(im,str(id), (x,y+h),fontFace,fontScale,fontColor)
cv2.imshow('im',im)
if (cv2.waitKey(1)==ord('q')):
break;
cam.release()
cv2.destroyAllWindows()
正在工作 但是我想对特定图像使用此代码来检测面部,我将cam替换为图像地址.code->
import cv2
import numpy as np
from PIL import Image
id=0
recognizer = cv2.face.LBPHFaceRecognizer_create()
recognizer.read('recognizer/trainner.yml')
cascadePath = "haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(cascadePath);
image = Image.open('dataSet/User. 1.14.jpg')
fontFace = cv2.FONT_HERSHEY_SIMPLEX
fontScale = 1
fontColor = (255, 255, 255)
while True:
ret, im =image.read();
gray=cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
faces=faceCascade.detectMultiScale(gray, 1.2,5)
for(x,y,w,h) in faces:
cv2.rectangle(im,(x,y),(x+w,y+h),(225,0,0),2)
id,conf = recognizer.predict(gray[y:y+h,x:x+w])
print(id)
if id==2:
id="mohan"
elif id==3:
id="krishna"
elif id==4:
id="satyam"
elif id==5:
id="Priyavrat"
elif id==0:
id="Unknown"
cv2.putText(im,str(id), (x,y+h),fontFace,fontScale,fontColor)
cv2.imshow('im',im)
if (cv2.waitKey(1)==ord('q')):
break;
cam.release()
cv2.destroyAllWindows()
我使用image = Image.open('dataSet/User. 1.14.jpg')
选择图片
但是此代码显示错误
>
ret, im =image.read();
AttributeError: 'JpegImageFile' object has no attribute 'read
请任何人帮助我。