Ask Your Question
0

Multiple Text Dislay on Images

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

beta gravatar image

Hi,

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 = video_capture.read()


    # Loop through each face in this frame of video
    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)
        # 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'):
        break

# Release handle to the webcam
video_capture.release()
cv2.destroyAllWindows()

Thank you!

edit retag flag offensive close merge delete

Comments

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 -0600 )edit
1

@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 -0600 )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 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
0

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

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
0

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

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

Question Tools

1 follower

Stats

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

Seen: 1,577 times

Last updated: Jul 04 '17