3

I run this (first one) example that launches the webcam of my latop 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 installed OpenBr on Ubuntu 14.04 LTS and I run successfully this command on a picture of myself:

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

The above command I run on the Terminal displays my picture 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 the webcam is launched I can see my face surrounded by the green rectangle ?

Why do I need this ?

I found similar programs in pure OpenCV/Python for this purpos. However, for later needs, I need more things than the simple face detection and I judge by myself that OpenBR will save me lot of headache. That is why I am looking for a way to run the command line somewhere inside the code above as a first but big step.

Hints:

The frame in the code corresponds to myself.png of the command line. The solution to be found will try to pass frame in the place of myself.png to the command line within the program itself.

Thank you very much in advance.


EDIT:

After correcting the typos of @Xavier's solution I have no errors. However the program does not run as I want it:

First, the camer is launched and I see myself but my face is not detected with a green rectangle. Secondly, I press any key to exit but the program does not exit: it shows me a picture of myself with my face detected. A last key press exists the program. My goal is to see my face detected during the camera functionment.

2 Answers2

2

you do not need openbr for this at all.

just see opencv's python face-detect tutorial

berak
  • 39,159
  • 9
  • 91
  • 89
  • 1
    I already run similar codes using pure OpenCV capabilities in Python. However I would love to achieve what I asked. But I thnak you very much for the interesting link. –  May 22 '15 at 09:44
1

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()
Xavier Combelle
  • 10,968
  • 5
  • 28
  • 52
  • Thank you very much. When I try on my other machine I will let you know. But I think you wanted to write `imread()` instead of `imwrite()` ? –  May 22 '15 at 14:01
  • The point is that `br` is waiting for a file and `cv2.imwrite()` is creating it – Xavier Combelle May 22 '15 at 14:18
  • Ah, yes, you are right about that. I just get an error about `system` it is not recognized but I will check on internet .. i think i found something like `subprocess.Popen()` –  May 22 '15 at 14:20
  • 1
    forget import os;os.system(...) – Xavier Combelle May 22 '15 at 14:20
  • don't forget the import os at top of script – Xavier Combelle May 22 '15 at 14:25
  • Yes, I imported everything necessary. Thank you. I edited in my question the error I get and the behavior, in case you have time . Thank you –  May 22 '15 at 14:28
  • You almost did it ! Now it shows my face in the camera. Nothing happens but when I exit the program it shows first a picture of myself with my eyes and face detected ! then i must press a key again to exitfully the progam –  May 22 '15 at 15:07