OpenCV: face recognition using the command line

I am running this (first) example which launches my latop's webcam so that I can see myself on the screen.

import numpy as np
import cv2

cap = cv2.VideoCapture(0)

while(True):
    # Capture frame-by-frame
    ret, frame = cap.read()

    # Our operations on the frame come here
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    # Display the resulting frame
    cv2.imshow('frame',gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

      

I have installed OpenBr on Ubuntu 14.04 LTS and I have successfully executed this on an image of myself:

br - gui -algorithm ShowFaceDetection -enrollAll -enroll /home/nakkini/Desktop/myself.png

      

The above command I run in Terminal displays my photo and draws a square around my face (face detection), it also highlights my eyes in green.

My dream:

I wonder if there is a way to combine this command with the short program above so that when I launch the webcam I can see my face is surrounded by a green rectangle?

Why do I need it?

I found similar programs in pure OpenCV / Python for this object. For later needs, however, I need more things than simple facial recognition, and I judge myself that OpenBR will save me a lot of headaches. This is why I am looking for a way to run the command line somewhere inside the code above as a first but big step.

Hint:

frame

in the code corresponds to the myself.png

command line. The solution to be found will try to pass frame

instead myself.png

to the command line within the program itself.

Thank you in advance.


EDIT:

After correcting the typos of @ Xavier's solution, I have no errors. However, the program doesn't start the way I want it:

First, the camera starts up and I can see myself, but my face is not detected by the green rectangle. Secondly, I press any key to exit, but the program doesn't exit: it shows me a picture of my face. In the last keystroke there is a program. My goal is to see my face detected during camera operation.

+3


source to share


2 answers


you don't need openbr at all.



just look through opencv python face recognition tutorial

+2


source


something like this should work



import numpy as np
import cv2
import os

cap = cv2.VideoCapture(0)

while(True):
    # Capture frame-by-frame
    ret, frame = cap.read()

    # Our operations on the frame come here
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    # Display the resulting frame
    cv2.imshow('frame',gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        cv2.imwrite( "/home/nakkini/Desktop/myself.png", gray );
        os.system('br - gui -algorithm -ShowFaceDetection -enrollAll -enroll /home/nakkini/Desktop/myself.png')
        break

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

      

+1


source







All Articles