I'm building something similar to a timelapse project where I'd like to be able to continuously detect faces and then align, scale and crop them before saving. I'm interested in having high quality images (at least 512x512 and not blurry) and as "front facing" as possible.

I am using a Raspberry Pi 3 Model B and the PI NoIR camera v2. Here is what I have working so far, using Python and OpenCV:

  • For the face detection, I'm using the default Haar Cascade classifier provided with OpenCV
  • For checking the image sharpness, I'm using OpenCV's Laplacian function as described here
  • To make sure my picture is at least 512x512, I set the detectMultiScale's minSize parameter to (400, 400).
  • For the alignment, I'm using eye detection and then rotate the image based on the angle formed from the eye line and the x axis
  • To get a front facing picture, I try to discard the ones where the distance between the eye rects and the face rect is not equal (with some threshold of course)

I have managed to have a somehow working version of all the above together, but I'm not very satisfied with the results.

First of all, it seems that raspistill's image quality is way better than the one I get in my python code. Any hints on that? I'm already using the bcm2835-v4l2 driver and I tried to change some of its parameters, but without any significant improvement.

Secondly, is it correct to do what I'm doing within a while loop and just discard the frames I'm not interested in? What is the optimal way to do something like

  • get a frame
  • apply some (relatively expensive) calculations
  • if every condition is satisfied:
    • save on disk
    • wait for X seconds
  • otherwise:
    • take a new frame
    • and keep trying

I think that when I do that in a while loop, the frames are somehow queued, which is something I don't really need. Note that I'm not interested in having this working in realtime or seeing the results on the screen - I'm mostly interested in satisfying the aforementioned conditions (sharp, front facing 512x512 images stored on the disk whenever a face is detected).

Finally, do you think that the hardware I'm using is capable of doing that, especially when running 24/7 for a long time (possibly months)?

Thanks in advance for any help!

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.