繁体   English   中英

AttributeError: 'int' 对象没有属性 'read'

[英]AttributeError: 'int' object has no attribute 'read'

使用opencv-contrib-python ,同时阅读这一行:

cam = cv2.FONT_HERSHEY_SIMPLEX ret,img= cam.read()

我收到一个错误:

 ret,trackImg= cam.read() AttributeError: 'int' object has no attribute 'read'**

我的源代码:

def TrackImages():
  recognizer = cv2.face.LBPHFaceRecognizer_create()
recognizer.read("TrainingImageLabel\Trainner.yml")
harcascadePath = "haarcascaade_frontface_default.xml"
faceCascade = cv2.CascadeClassifier(harcascadePath)
df = pd.read_csv("StudentDetails\studentDetails.csv")
cam = cv2.FONT_HERSHEY_SIMPLEX
col_names = ['Id', 'Name', 'Date', 'Time']
attendance = pd.DataFrame(columns = col_names)
while True:
  ret, img = cam.read()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = detector.detectMultiScale(gray, 1.3, 5)

for (x, y, w, h) in faces:
  cv2.rectangle("test", (x, y), (x + w, y + h), (255, 0, 0), 2)
Id, conf = recognizer.predict(gray[y: y + h, x: x + w])
if (conf < 50):
  ts = time.time()
date = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d')
timestamp = datetime.datetime.fromtimestamp(ts).strftime('%H:%m,%s')
aa = df.loc[df['Id'] == Id]['Name'].values
tt = str(Id) + "-" + aa
attendance.loc[len(attendance)] = [Id, aa, date, timestamp]
else :
  Id = 'Unknown'
tt = str(Id)

if (conf > 75):
  noOfFile = len(os.listdir("ImageUnknown")) + 1
cv2.imwrite("ImageUnknown\Image" + str(noOfFile) + ".jpg", img[y: y + h, x: x + w])

而不是使用该行:

ret, im1 = cam.read() 

尝试使用这一行:

 im1 = cv2.VideoCapture(0)

它将解决这里的错误,您只需要捕获图像,就可以使用上面的行来完成。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM