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])