A Feature is a measurable piece of data in an image. It could be a distinct color or a specific structure as a line, an edge, or an image segment. A good image recognizes an object in all ways it may appear.
Characteristics of a good feature:
Typically features are quite small and sets of them are used to identify larger objects
Read more about features here.
Feature extraction is used to reduce the dimensionality of image data. Features transform complex and large image data into smaller sets of features. This makes the task of classifying images based on their features done simpler and faster.
To classify images, we use supervised machine learning algorithms. Where we use labeled data to train the classifier (model) on the features of our data. The most popular model used to classify images is Convolutional Neural Networks (CNN). CNNs excel at recognizing patterns and features and detecting many types of objects.
Other ML models that are faster than CNNs and do a decent job:
You can choose any of these models based on how fast and complex you want the model to be and the type of problem you are trying to solve.
OpenCV comes with a few Haar Cascade detectors already trained. If you want to train your own classifier for any object like a banana, car, etc. you can use OpenCV to create one. Its full details are given here. For now, we'll just look at using a classifier to detect faces. First we need to load the required XML classifiers. Then load our input image (or video) in grayscale mode since face detection relies on patterns of intensity in an image.
import numpy as np
import cv2
# Load in the face detector XML file
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
# Read in an image
image = cv2.imread('face1.jpg')
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
#Convert to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Detect the faces in the image
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
This code will detect faces, and you can use that in analyzing faces and emotions.