2
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

I have a basic algorithm for detecting faces from webcam > What should I do to show respective names of persons when they show up in Webcam ?

Please help !

1 Answer 1

0

you can declare font with it's text and also specify its position. In my example it will be below the rectangle

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
1
  • You can adjust the position of the text as you like for instance i found the perfect position to be left = (x, y+h+20) Commented Jul 19, 2016 at 20:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.