gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=5,
minSize=(30, 30),
flags=cv2.cv.CV_HAAR_SCALE_IMAGE
)
# Draw a rectangle around the faces
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
# Display the resulting frame
cv2.imshow('Video', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
我有一个从网络摄像头检测面部的基本算法>当我们在网络摄像头出现时,我该怎么做才能显示相应的人名?
请帮忙!
答案 0 :(得分:0)
您可以使用文本声明字体并指定其位置。在我的例子中,它将在矩形
下面font = cv2.FONT_HERSHEY_SIMPLEX(
thickness = 1,
white = (255,) * 3,
size = 1,
left = (x, y+h+12))
# Draw a rectangle around the faces
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
cv2.putText(frame, 'Identity Unknown', left, font, size, white, thickness) #this line displays the text