Ask Your Question

Multiple Text Dislay on Images

asked 2017-07-04 02:21:10 -0500

beta gravatar image


I'm trying to implement multiple text in a video frame. E.g. the following code just display 1 text for an image. In this code at present I can pass one "name" at a time. I want to pass multiple names. E.g. if 2 people are detected it should pass 2 names.

video_capture = cv2.VideoCapture(0)

while True:
    # Grab a single frame of video
    ret, frame =

    # Loop through each face in this frame of video
    faces = faceCascade.detectMultiScale(
    minSize=(30, 30),

    # 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)
        # Draw a label with a name below the face
        cv2.rectangle(frame, (left, bottom - 35), (right, bottom), (0, 0, 255), cv2.FILLED)
        font = cv2.FONT_HERSHEY_DUPLEX
        cv2.putText(frame, name, (left + 6, bottom - 6), font, 1.0, (255, 255, 255), 1)

    # Display the resulting frame
    cv2.imshow('Video', frame)

    # Hit 'q' on the keyboard to quit!
    if cv2.waitKey(1) & 0xFF == ord('q'):

# Release handle to the webcam

Thank you!

edit retag flag offensive close merge delete


btw, is this supposed to run on your docker webserver ?

(no camera, no gui there, you would need a significantly different code-flow for that.)

berak gravatar imageberak ( 2017-07-04 04:13:16 -0500 )edit

@berak: No. It's just for local system. I'm first trying to make it on local system before shifting it on docker.

beta gravatar imagebeta ( 2017-07-04 04:22:27 -0500 )edit

btw, you want to base the text location on x,y, not on something constant (else, your 2nd message will overwrite the 1rst, etc.)

berak gravatar imageberak ( 2017-07-04 08:40:57 -0500 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2017-07-04 03:50:04 -0500

berak gravatar image

unfortunately, your code is doing face detection only. it does not know anything about different ppl, or even their names .

have a look at opencv's face recognition framework to do that.

edit flag offensive delete link more

answered 2017-07-04 07:18:23 -0500

Once you have used @berak answer to resolve the name issue, getting the number of people is easy. The related equation is:

Number of faces = size of the face array

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-07-04 02:21:10 -0500

Seen: 769 times

Last updated: Jul 04 '17