Face and Eye Detection in Python using OpenCV.

Face and Eye Detection in Python using OpenCV.

OpenCV is an open-source computer vision library that uses machine learning algorithms for face detection, object tracking or colours detection. In this blog post, we’ll learn how to use the Haar Cascade algorithm to detect faces and eyes in an image or real-time video. Let’s dive in.

Approach:

  • Capture the video from the webcam.
  • Convert the frames to grayscale since the cascade algorithm works only with greyscale.
  • Detect the faces using multi-scale. It takes 3 arguments — the input image, scaleFactor and minNeighbors. Scale Factor specifies how much the image size is reduced at each image scale and min neighbours specify how many neighbours each candidate rectangle should have to retain it. You can read more about the arguments in this stack overflow post.
  • Draw the blue rectangle on the faces.
  • Draw the green rectangle on the eyes.

Don’t forget to import the libraries.

Make sure you have Python, OpenCV and Numpy already installed. I personally prefer Anaconda distribution but you are good to go without Anaconda if you have mentioned libraries installed.

The code once all written out will look like this. (Github Gist Link)

No alt text provided for this image

So that’s it! I hope you found it helpful, and also I hope that you have a nice day.

Till next time :) Happy Learning!

Bilal K.

要查看或添加评论,请登录

Bilal K.的更多文章

社区洞察

其他会员也浏览了