Posts

Showing posts with the label Python

Face detection with Python

Image
Here is how you can implement Face detection with Python and  OpenCV  in less than 25 lines of code: Face detection with Python and OpenCV Install OpenCV. Now download the code from  repo Now Let's break down the code # Get user supplied values imagePath   =   sys . argv [ 1 ] cascPath   =   sys . argv [ 2 ] The above lines takes image and cascade as input. The default cascade will help in detecting image with OpenCV. # Create the haar cascade faceCascade   =   cv2 . CascadeClassifier ( cascPath ) Now we create a cascade, this loads the face cascade into memory for its use. Cascade is just an XML which contains data to detect faces. # Read the image image   =   cv2 . imread ( imagePath ) gray   =   cv2 . cvtColor ( image ,   cv2 . COLOR_BGR2GRAY ) Here we read the image and convert it into Grayscale. A lot of operations in OpenCV are done in GrayScale. # Detect faces in th...

Face detection with OpenCV

Image
Face detection with OpenCV OpenCV is the most popular library for computer vision. Originally written in C/C++, it now provides bindings for Python. OpenCV uses machine learning algorithms to search for faces within a picture. For something as complicated as a face, there isn’t one simple test that will tell you if it found a face or not. Instead, there are thousands of small patterns/features that must be matched. The algorithms break the task of identifying the face into thousands of smaller, bite-sized tasks, each of which is easy to solve. These tasks are also called  classifiers . For something like a face, you might have 6,000 or more classifiers, all of which must match for a face to be detected (within error limits, of course). But therein lies the problem: For face detection, the algorithm starts at the top left of a picture and moves down across small blocks of data, looking at each block, constantly asking, “ Is this a face? … Is this a face? … Is this a face ?...