BananaPi Face Recognition using Python-OpenCV

11 10311
Basically, I wanna build a simple face recognition and track system step by step in the near future. Using the webcam to monitor(cheap), BananaPi+OpenCV for computer vision and data processing (a lot of source can be found on OpenCV wiki) , and python for a simple gui(python newbie, but seems it's fair friendly to me), as to the track system, I think a arduino controlled servo will be fine( BTW, maybe can be developed into a track robot).
DAY 1: Install Python-OpenCV
Python is already installed on BP, what we need to do is install the python-opencv. It's very simple, all you have to do is just use the apt-get command like belw:
  1. sudo apt-get install python-opencv
Copy the Code

     After the installation, I try to make it work with my webcam for video streaming:
  1. import numpy as np
  2. import cv2

  3. cap = cv2.VideoCapture(index_num)
Copy the Code

    import the module, and declare the Camera. You need to chek the index_num by
  1. ls /dev/video0,etc
Copy the Code

    For my webcam is video0, so VideoCapture(0).
    And it's very easy to capture a frame using the Opencv module. In order to get the video streaming, we get the frame in the loop.
  1. while(True):
  2.     # Capture frame-by-frame
  3.     ret, frame =  
  4.     # Display the resulting frame
  5.     cv2.imshow('Monkey-BananaPI@Lemaker',frame)
Copy the Code

   And everything ok, you can see the camera vedio straming output in a defualt 640x480
Thats just awesome. So you are streaming video using a USB web camera? Just wondering if you are using the Raspberry Pi Camera Board via the CSI port.

Yeah. I am using a web camera. I want to test the BP's ability on the DIP(Digital Image Processing). I dont have a RPi camera board at hand. BTW, I am always not familiar with the hardware., so CSI, I just forget about it.

Still Awesome cant wait to see if it works. You have more horse power than the PI so in theory if it works on a PI it should have no issue here.
Very Cool.

Post Last Edited by monkeyse7en at 2014-5-21 02:09

DAY 2: FaceDetection

    Partsof the ideas and algorithms comes from the book Digital Image Processingby RafaelC.Gonzalez, parts of the code comes from the wiki of

       Afterinstall the python-opencv, and the video streaming test ok. I wanna try someface detection work on BP. If this can be down on the BP, other CV works likecolor detection and feature detection can also will be possible.

      There are a lot of face detction code on based on opencv can be found inthe internet, but basically use the cv module. For now the python-opencv newmodule is cv2. And it’s much more effective.

      In cv2, it has a CascadeClassifier api. What we need is the trained data, mostly it is the intel haarcascade_frontalface_alt.xml. With this it can be farily easy in the python code:

     Import the cv2 as normal. And declare the cascade classifier, read the image.

  1. face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_alt.xml')
  2. img = cv2.imread('opencv02.jpg')
Copy the Code

     I transform the image to a gray image, it will decrease the computation, this is very important for the embedded system. Then we use the classifier to detect the face and draw a rectangle around the dectected face.

  1. gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  2. faces = face_cascade.detectMultiScale(gray, 1.3, 5)
  3. for (x,y,w,h) in faces:
  4.     cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
Copy the Code

     And I check the speed of the dection. The results is show below:



  It can detect Messi's face. But the speed... This cant be used in the video streaming.     

   I will figure out some other way to increase the speed. For what I know, this can be down in two ways,

   1) 640x320 ->320x160 -> Even more smaller,  sacrificing the accuracy, increasing the speed.

    2) try some other  classifier.



Reply 4# ChicagoBob

   It can use to face detection, but the speed is hard to bear. I try some other way to improve it.

How is your project going? Were you able to make it go faster?

Reply 7# ChicagoBob

   Yeah. It can works now, at least for me. Recently, I have been so busy, I dont have time to post it, Maybe later. But the solution is easy, reduce the pixel you process or using another Classifier( eg,LBP) . And the time it takes reduce to 100mm around.

100mm around.  You mean 100ms?
If that works that would be awesome fun.

How far did you get with this project?
Was the time 100ms?

You have to log in before you can reply Login | Sign Up

Points Rules