phi161
Posts: 2
Joined: Wed May 16, 2018 11:34 am

How to improve face detection's performance and image quality using the NoIR camera?

Wed May 16, 2018 12:01 pm

Hello,

I also posted this on stackexchange, but thought it could belong here as well:

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!

User avatar
topguy
Posts: 4552
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: How to improve face detection's performance and image quality using the NoIR camera?

Wed May 16, 2018 1:55 pm

When it comes to discussing quality of cameras or pictures then the old saying is particularly true "A picture says more than a thousand words".

phi161
Posts: 2
Joined: Wed May 16, 2018 11:34 am

Re: How to improve face detection's performance and image quality using the NoIR camera?

Wed May 16, 2018 5:44 pm

Something like this you mean?

Image

Just kidding, what do you like to know? What's my definition of a "high quality image"?

User avatar
topguy
Posts: 4552
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: How to improve face detection's performance and image quality using the NoIR camera?

Fri May 18, 2018 10:55 am

Take 2 pictures with Raspistill and then your code, upload them somewhere and post the links here.

Also probably relevant to show the setup & grabbing code you use.

Return to “Graphics, sound and multimedia”

Who is online

Users browsing this forum: No registered users and 9 guests