Discussing the nuts and bolts of software development

Monday, April 02, 2012

 

Real-time face detection with Android


In this post I will show you how to use the still image FaceDetector class from the Android SDK to achieve (mostly) real-time face detection.  The following method was used in the creation of the MonkeyCam application.

Since its first release, the Android SDK has made available the FaceDetector class, which “identifies the faces of people in a Bitmap graphic object”.  By using the FaceDetector on preview frames from the camera, we approximate the real-time face detection.  For example in the MonkeyCam application we achieved a rate of slightly over one second per frame which is in the same range as other solutions found around the Internet using more complex solutions like third party computer vision libraries.  Short of using the NDK to do GPU programming for the face detection algorithm this was a very usable compromise.


The Camera.PreviewCallback interface provides the onPreviewFrame callback to deliver copies of the preview frames as they are displayed.  The default image format is NV21 and I strongly recommend to stick with it as many cameras don’t support other formats and silently accept a different format from setPreviewFormat() only to return blank frames.  

Now that we have the preview frame in the NV21 format we need to convert it to a bitmap format so we can pass it to the FaceDetector.  Fortunately, since Android 2.2 we can use the YuvImage class to wrap our NV21 frame and then convert it to RGB_565 using its compressToJpeg method and decode the resulting stream into a Bitmap object using BitmapFactory.decodeStream().  For previous versions of the Android SDK you will have to do the conversion manually.

At this point all that is left to do is passing the newly created Bitmap frame to FaceDetector.findFaces and remember to re-add the callback buffer to the Camera object so onPreviewFrame gets called again.  At this point we now have a real-time face detection mechanism, it’s now time to let the creativity flow and add your own touch to make it into something special.


Edit [2012-12-21]: The source code for MonkeyCam as been released under Apache License 2.0 and can be found on github.

Labels: , , , , , , ,


Comments:
Nice but slow. Because of few redundant pixel conversions and copying.
FaceDetector internally converts Bitmap to grayscale, camera offers YUV, which already contains grayscale buffer, but FaceDetector doesn't accept anything else but RGB in Bitmap.

And you even mention conversion to/from JPG, which is overkill for realtime detection.

Shame, but FaceDetector is not good choice for this task to be fast.

Fast would be directly passing chroma values from YUV to detector lib.
 
Its Nice but we want portrait mode using front camera detect the face. Please give suggestions.
 
thanks for share

Chuyên cung cấp cầu nâng 1 trụ rửa xe oto giá rẻ cũng như máy nén khí hitachi giá tốt nhất cho các bạn.. máy rửa xe oto giá ưu đãi.. Sơn tùng lâm cung cấp máy nén khí giá rẻ cũng như máy rửa xe gia đình tốt và tư vấn ben nâng xe máydụng cụ rửa xe máy tại nhà giá rẻ


 
Thích chơi game lậu miễn phí như truy kich full vangkey office 2010 mới nhất cho bạn nào cần cũng như tha thu là gìchơi gunny lậu.... Chuyên tư vấn cách dịch vụ thành lập doanh nghiệp đà nẵng cũng như cách dang ky kinh doanh tai da nang giá rẻ
 
Information from this blog is very useful for me, am very happy to read this blog Kindly visit us @ Luxury Watch Box | Shoe Box Manufacturer | Luxury Cosmetics Box

 
Car Rental in Iran : Tehran -Tehran Airport - IKA-Shiraz - Isfahan-BandarAbbas
car rental tehran airport
iran attractions
iran tours
 
Trying to fix a problem with a too much homework left to do? here you go https://homeworkhelper.net/blog/too-much-homework
 
Dalam permainan judi tentunya anda harus mengontrol permainan dan deposit anda. Agar kekalahan yang anda alami tidak begitu besar. Anda juga tidak bisa menjadikan permainan judi sebagai hobi dan mengisi waktu luang anda saja
asikqq
http://dewaqqq.club/
http://sumoqq.today/
interqq
pionpoker
bandar ceme terpercaya
freebet tanpa deposit
paito warna
syair sgp
 
Awesome post. You Post is very informative. Thanks for Sharing.
Android Training Institute in Noida
 
Keuntungan yang melompat dari ratusan rendah ke ribuan menandakan ketergantungan yang berlebihan pada permainan celah, yang gagal membantu
data sgp
data sydney
datahk
syair sydney
syairsgp
datasgp
paito warna
http://warungsgp.com/
live hk 6d
live sydney
 

Pretty! This was a really wonderful article. Thanks for providing these details. online mobile repair marathahalli

Greetings! Very useful advice in this particular post! online lg display repair
 
It's the little changes that will make the most important changes. Many thanks for sharing! online iphone display repair

Hi there! This blog post could not be written much better! online nokia display repair
 
Assignment Help is completing the process of serving task staying in contact with customers with full interesting and veritable substance. All these are served from us which will reliably give the understudy best and full information on the focuses.
write my assignment
 
sangat mudah untuk bisa daftar slot sbobet, cukup melalui agen resmi dengan mengisi form yang disediakan di situs mereka.

saat ini telah banyak deposit judi slot tanpa potongan yang ditawarkan oleh agen taruhan online sehingga anda bisa mendapatkan keuntungan lebih banyak.

cara baru isi saldo judi yaitu deposit slot sbobet pulsa murah, cukup dengan transfer pulsa kedalam nomor yang ditunjuk oleh agen. Namun anda tetap membutuhkan nomor rekening bilamana anda ingin menarik uang kemenangan bermain slot online.

bandar slot sbobet deposit pulsa kini hadir untuk memudahkan anda dalam mengisi saldo slot online, namun tidak setiap agen memiliki fitur atau layanan ini.

main dingdong online saat ini sangat mudah dengan hadirnya game slot sbobet pulsa yang disediakan oleh bandar judi. Dengan adanya fitur ini telah meningkatkan jumlah member dan juga perputaran uang di dalamnya.
 
Are you looking to hire top quality Custom Term Paper Help Services and cheap Legitimate Term Paper Writing Services? Rather than risking abject failure, you should consider hiring Legitimate Term Paper Help Provider.
 
Custom Research Paper Services from a credible firm like our Legitimate Custom Research Paper Writing Company ensures that you attain excellence, especially in your College Research Paper Services endeavors.

 
Thanks for another informative website. The place else could I am getting that kind of information written in such a perfect means? I’ve a challenge that I’m simply now operating on, and I’ve been on the look out for such info.

Geek Squad Appointment |
Best Buy Geek Squad Appointment |
Best Buy Appointment |
Geek Squad Appointment Scheduling |
Best Buy Geek Squad Appointment Schedule |
BestBuy.com Appointments |
Geek Squad Appointments At Best Buy |
Make An Appointment With The Geek Squad |
Schedule Geek Squad Appointment |
 
Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?