OpenCV (Open source computer vision) is a library of programming functions mainly aimed at real-time computer vision. Originally developed by Intel, it was later supported by Willow Garage then Itseez (which was later acquired by Intel). The library is cross-platform and free for use under the open-source BSD license.
The library has more than 2500 optimized algorithms, which includes a comprehensive set of both classic and state-of-the-art computer vision and machine learning algorithms. These algorithms can be used to detect and recognize faces, identify objects, classify human actions in videos, track camera movements, track moving objects, extract 3D models of objects, produce 3D point clouds from stereo cameras, stitch images together to produce a high resolution image of an entire scene, find similar images from an image database, remove red eyes from images taken using flash, follow eye movements, recognize scenery and establish markers to overlay it with augmented reality, etc.
In this tutorial we are developing a facial recognition on a photo using Haar Cascades.
So Lets get started
OpenCV comes with a trainer as well as detector. If you want to train your own classifier for any object like car, planes etc. you can use OpenCV to create one. Here we will deal with detection. OpenCV already contains many pre-trained classifiers for face, eyes,smiles, etc. Those XML files are stored in the opencv/data/haarcascades/ folder. Let’s create a face and eye detector with OpenCV.
1. run pip install opencv-python if you need only main modules
2. run pip install opencv-contrib-python if you need both main and contrib modules (check extra modules listing from OpenCV documentation)
3. Create a new file as face.py and open it in your choice of editor.
4. And Type or paste following Code as save it.
FACE DETECTION CODE
img = cv2.imread(image)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.1, 4)
for (x, y, w, h) in faces:
cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0), 2)
Thats it guys try it with various images.
since this tutorial was short with no description on how the commands works. A detailed tutorial might come very soon.
Next time we will return for live facial detection with Webcam.
All required resources available in github below. You can download and simply run too.
84 Comments on “FACE DETECTION IN 11 LINES OF CODE – AI PROJECTS”
Thanks for finally writing about > FACE DETECTION IN 11 LINES
OF CODE – AI PROJECTS – < Loved it!
Thank you for any other magnificent post. The place else may just anyone
get that type of info in such a perfect manner of writing?
Hi to all, it’s really a pleasant for me
That is really interesting,
This post truly made my day.Thanks!
Will probably be again to get more. Thanks
naturally like your website but you need to check the spelling on quite a few of your posts.
Hello there, simply become aware of your blog through Google, and located that it’s truly informative. I’m going to be careful for brussels. I’ll appreciate in case you proceed this in future. A lot of other folks shall be benefited out of your writing. Cheers!
CAN’T EVEN COMPARE THE QUALITY OF THIS SITE TO ANY OTHER SITE … LOVED IT MAN
Thank you for every other informative web site.
Heya i am for the primary time here. I came across this board and I in finding It really useful & it helped me out much. I hope to provide something back and aid others like you helped me.
I am really impressed with your writing skills and also with the layout on your weblog.
it is rare to see a great blog like this one nowadays.
Wow! Thank you! I permanently wanted to write on my site something like that. Can I include a part of your post to my site?
I have been absent for a while, but now I remember why I used to love this website. Thanks , I will try and check back more frequently. How frequently you update your web site?
Great weblog right here! Also your web site lots up very fast! What host are you using? Can I am getting your affiliate link in your host? I want my website loaded up as fast as yours lol
this’s a good thing we should others
Hi there, I enjoy reading all of your article post.
I wanted to write a little comment to support you.
Hello there! I know this is kind of off topic but I was wondering if you knew where I could locate a captcha plugin for my comment form?
I’m using the same blog platform as yours and I’m having trouble
finding one? Thanks a lot!
I’ve been surfing online more than 2 hours today, yet I never found any interesting article
like yours. It is pretty worth enough for me. Personally, if
all site owners and bloggers made good content as you did, the web
will be much more useful than ever before.
You are so awesome! I do not believe I’ve truly read through something like this before.
So good to discover another person with a few genuine thoughts on this subject matter.
Really.. many thanks for starting this up. This site is
something that is needed on the web, someone with a bit
Woah! I’m really loving the template/theme of this site.
It’s simple, yet effective. A lot of times it’s difficult to get that “perfect balance”
between superb usability and visual appearance.
I must say that you’ve done a very good job with this.
In addition, the blog loads extremely fast for me on Firefox.
Hello, i feel that i noticed you visited my site so i got here to go back the want?.I am
attempting to in finding issues to enhance my web site!I
assume its adequate to use a few of your ideas!!
Unquestionably consider that which you stated.
Your favorite justification seemed to be on the web
the easiest thing to be mindful of. I say to you, I certainly get irked at the
same time as other folks consider issues that they plainly don’t understand about.
You controlled to hit the nail upon the top as neatly as defined out the whole thing with no need side effect
, other people could take a signal. Will probably be back to get more.
Thank you adreamoftrains best web hosting sites
Hmm it seems like your blog ate my first comment (it was extremely long) so
I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog.
I too am an aspiring blog writer but I’m still new to the whole thing.
Do you have any recommendations for newbie blog writers? I’d certainly
Like!! I blog frequently and I really thank you for your content. The article has truly peaked my interest.
What’s up Dear, are you actually visiting this site on a regular basis, if
so after that you will without doubt obtain nice knowledge.
I do not even know how I ended up here, but I thought this
post was great. I do not know who you are but certainly
you are going to a famous blogger if you are not already ;
I think the admin of this web site is actually working
hard in favor of his site, as here every data is quality based stuff.
I used to be recommended this website by way of my cousin. I’m no longer positive whether or not this put up is written by
means of him as nobody else know such precise approximately my trouble.
You are incredible! Thanks!
Simply want to say your article is as surprising. The clearness
for your submit is simply spectacular and that i could suppose you’re a professional in this subject.
Well along with your permission let me to grasp your RSS feed to
keep up to date with impending post. Thanks one million and please keep up the
Hi there! I know this is somewhat off topic but I was wondering which
blog platform are you using for this website? I’m getting fed up
of WordPress because I’ve had issues with hackers and I’m looking at alternatives
for another platform. I would be awesome if you
could point me in the direction of a good platform.
Hello there! Quick question that’s totally off topic. Do you know how to make your site mobile friendly?
My site looks weird when browsing from my iphone 4.
I’m trying to find a theme or plugin that might be able to correct this problem.
If you have any recommendations, please share. Thank you!
Thanks very nice blog!
Hello there! This is my first visit to your blog!
We are a collection of volunteers and starting a new
project in a community in the same niche. Your blog provided us beneficial information to work on. You have done a wonderful job!
WOW just what I was looking for. Came here by searching for 부천 안마
What’s up to every single one, it’s actually a fastidious for me to pay a visit
this web site, it consists of precious Information.
Hurrah! In the end I got a website from where I know how to actually obtain helpful data concerning my study and knowledge.
I take pleasure in, result in I discovered exactly what I was looking for.
You have ended my 4 day lengthy hunt! God Bless you man. Have a great day.
I was suggested this web site by my cousin. I’m not sure whether this post is written by him as nobody else know such detailed about my trouble. You are incredible! Thanks!|
Fantastic blog! Do you have any recommendations for aspiring writers?
I’m hoping to start my own blog soon but I’m a little lost on everything.
Would you suggest starting with a free platform
like WordPress or go for a paid option? There are so many options out there that I’m completely confused
.. Any recommendations? Thank you!
Keep this going please, great job!
you’re in point of fact a just right webmaster.
The web site loading pace is incredible. It sort of feels that you are doing
any distinctive trick. Moreover, The contents are
masterwork. you have done a excellent activity on this matter!
Thank you for the auspicious writeup. It in truth was a enjoyment
account it. Glance complicated to far brought agreeable from you!
By the way, how could we communicate?
I couldn’t refrain from commenting. Perfectly written!
I believe what you published made a lot of sense. However, what about this? what if you added a little content? I mean, I don’t wish to tell you how to run your website, however what if you added something that makes people desire more? I mean BLOG_TITLE is kinda boring. You could glance at Yahoo’s front page and watch how they create post titles to get viewers interested. You might try adding a video or a picture or two to get readers interested about what you’ve got to say. Just my opinion, it might make your blog a little bit more interesting.|
Today, while I was at work, my sister stole my iphone and tested to see if
it can survive a twenty five foot drop, just so she can be a
youtube sensation. My iPad is now broken and she has 83 views.
I know this is totally off topic but I had to share it with someone!
naturally like your website but you need to take a look
at the spelling on quite a few of your posts. A number of them are rife with spelling issues and I find it very bothersome to inform the truth on the other hand I will surely come again again.
Keep this going please, great job!
Undeniably believe that which you said. Your favorite reason seemed to be on the
web the simplest thing to be aware of. I
say to you, I definitely get annoyed while people think about worries that they just
don’t know about. You managed to hit the nail upon the top as well as
defined out the whole thing without having side effect , people could take a
signal. Will likely be back to get more.
I am really impressed together with your writing abilities and
also with the structure on your blog. Is that this a paid theme
or did you customize it yourself? Either way stay up the excellent quality writing, it’s rare
to peer a nice weblog like this one nowadays..
I’m really enjoying the design and layout of
your site. It’s a very easy on the eyes which makes it
much more enjoyable for me to come here and visit
more often. Did you hire out a designer to create your theme?
Great beat ! I would like to apprentice while you amend your site,
how can i subscribe for a blog web site? The account
helped me a acceptable deal. I had been a little bit acquainted
of this your broadcast provided bright clear idea
Hello there! This article could not be written much better!
Looking through this article reminds me of my previous
roommate! He continually kept talking about this. I most certainly will send this article to him.
Pretty sure he’s going to have a good read. Thank you for sharing!
Fastidious replies in return of this matter with solid arguments and explaining all
Usually I do not read post on blogs, however I would like to say that this write-up very pressured me to take a look at and do it!
Your writing taste has been amazed me. Thanks, quite nice post.
Hi there, all the time i used to check webpage posts here early in the morning, as i like to learn more and more.
Terrific article! That is the kind of info that are meant to be shared
around the internet. Disgrace on the search engines for no longer
positioning this put up upper! Come on over and talk over with my website .
Thank you =)
Hi there! Quick question that’s entirely off topic. Do you know how
to make your site mobile friendly? My website looks weird when browsing from my iphone4.
I’m trying to find a template or plugin that might be able to correct this problem.
If you have any recommendations, please share. With thanks!
What i don’t understood is in reality how you are no longer actually much more neatly-liked than you might be right now. You’re so intelligent. You already know thus considerably on the subject of this matter, produced me individually believe it from a lot of numerous angles. Its like men and women aren’t fascinated except it is one thing to do with Lady gaga! Your personal stuffs great. All the time deal with it up!
Hi there to all, the contents present at this site are really amazing for
people knowledge, well, keep up the good work fellows.
That is very fascinating, You’re an excessively professional blogger.
I have joined your rss feed and look forward to looking for extra of your wonderful post.
Also, I’ve shared your site in my social networks
First of all I would like to say excellent blog! I had a quick question in which
I’d like to ask if you do not mind. I was curious to
find out how you center yourself and clear your thoughts before writing.
I’ve had difficulty clearing my thoughts in getting my ideas out there.
I do take pleasure in writing but it just seems
like the first 10 to 15 minutes are generally lost just trying to figure out
how to begin. Any ideas or tips? Cheers!
Very rapidly this website will be famous among all blogging and site-building people,
due to it’s fastidious articles
It’s in reality a nice and helpful piece of information. I’m glad that you just shared this useful information with us. Please stay us up to date like this. Thank you for sharing.|
As a Newbie, I am always searching online for articles that can help me. Thank you
I have learn some excellent stuff here. Certainly value bookmarking for revisiting. I wonder how so much effort you set to create the sort of wonderful informative site.