Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Shahid Akhtar Khan
169 articles
How to detect license plates using OpenCV Python?
License plate detection is a crucial component in automated vehicle recognition systems. We can detect license plates in images using OpenCV's Haar cascade classifier, which is a machine learning-based object detection method. What is Haar Cascade Classifier? A Haar cascade classifier uses machine learning to detect objects in images. To train a license plate classifier, the algorithm needs many positive images (with license plates) and negative images (without license plates). Once trained, it can detect license plates in new images. Downloading the Haarcascade File You can download pre-trained Haar cascades from the OpenCV GitHub repository: ...
Read MoreSmile detection using haar cascade in OpenCV using Python
Smile detection using Haar cascade classifiers in OpenCV is a powerful computer vision technique. Haar cascades are pre-trained machine learning models that can detect specific features like faces and smiles in images using pattern recognition. Understanding Haar Cascade Classifiers A Haar cascade classifier is trained on thousands of positive images (containing the target feature) and negative images (without the feature). For smile detection, we need two cascades: haarcascade_frontalface_default.xml − detects faces haarcascade_smile.xml − detects smiles within face regions Downloading Haar Cascades You can download pre-trained Haar cascades from the official OpenCV GitHub repository: ...
Read MoreHow to find patterns in a chessboard using OpenCV Python?
Finding chessboard patterns is essential for camera calibration and computer vision applications. OpenCV provides two key functions: cv2.findChessboardCorners() to detect corner points and cv2.drawChessboardCorners() to visualize the detected pattern. Syntax ret, corners = cv2.findChessboardCorners(img, patternSize, None) cv2.drawChessboardCorners(img, patternSize, corners, ret) Parameters img − Input grayscale image patternSize − Number of inner corners per row and column (width, height) corners − Output array of detected corner coordinates ret − Boolean indicating if pattern was found Steps To find chessboard patterns, follow these steps − Import the required library. In ...
Read MoreHow to detect cat faces in an image in OpenCV using Python?
Cat face detection in images uses Haar cascade classifiers, a machine learning approach trained on positive images (with cat faces) and negative images (without cat faces). OpenCV provides a pre-trained Haar cascade specifically for cat face detection. Downloading the Haar Cascade You can find the required Haar cascade file at the official OpenCV GitHub repository ? https://github.com/opencv/opencv/tree/master/data/haarcascades Download haarcascade_frontalcatface.xml by clicking on the file, opening it in raw format, then right-clicking and saving it to your project directory. Steps for Cat Face Detection Import OpenCV and read the input image Convert the image ...
Read MoreHow to crop and save the detected faces in OpenCV Python?
OpenCV provides Haar cascade classifiers for detecting faces in images. When a face is detected, you get coordinates (x, y, w, h) representing the face's position and dimensions. To crop and save the detected face, we use array slicing: image[y:y+h, x:x+w]. How to Download Haar Cascades You can find different Haar cascades on the GitHub repository: https://github.com/opencv/opencv/tree/master/data/haarcascades To download the Haar cascade for human face detection, click on the haarcascade_frontalface_default.xml or haarcascade_frontalface_alt.xml file. Open it in raw format, right-click and save the file. Note: Save all Haar cascade XML files in a dedicated folder for ...
Read MoreHow to detect humans in an image in OpenCV Python?
To detect humans in an image and draw bounding boxes around them, you can use OpenCV's built-in HOG (Histogram of Oriented Gradients) descriptor with a pre-trained SVM classifier. This approach is effective for detecting pedestrians in upright positions. Steps for Human Detection Import the required library. In all the following examples, the required Python library is OpenCV. Make sure you have already installed it. Read the input image using cv2.imread(). Specify the full image path. Initialize a HOG descriptor object hog = cv2.HOGDescriptor() and set the SVM detector using hog.setSVMDetector() with the default people detector. Detect humans ...
Read MoreHow to detect polygons in image using OpenCV Python?
Polygon detection is a common computer vision task that involves finding multi-sided shapes in images. OpenCV provides powerful tools to detect polygons by first finding contours and then approximating them to identify shapes with 5 or more vertices. How It Works The polygon detection process follows these key steps: Contour Detection - Find all object boundaries in the image Contour Approximation - Simplify contours to approximate polygonal shapes Vertex Counting - Count vertices to identify polygons (≥5 vertices) Visualization - Draw detected polygons on the original image Step-by-Step Process Import the required ...
Read MoreHow to detect eyes in an image using OpenCV Python?
Haar cascade classifiers are machine learning-based algorithms trained to detect specific objects in images. For eye detection, we use pre-trained cascades that identify eyes by analyzing patterns from thousands of positive (eye images) and negative (non-eye images) samples. Eye detection requires two haar cascades: one for detecting faces first, then another for detecting eyes within those face regions. This two-step approach improves accuracy by limiting the search area. Required Haar Cascade Files Download these pre-trained cascade files from the OpenCV GitHub repository: haarcascade_frontalface_default.xml − for face detection haarcascade_eye_tree_eyeglasses.xml − for eye detection Note: ...
Read MoreHow to change the contrast and brightness of an image using OpenCV in Python?
In OpenCV, to change the contrast and brightness of an image we use cv2.convertScaleAbs() method. This function applies linear transformation to adjust pixel values effectively. Syntax cv2.convertScaleAbs(image, alpha, beta) Parameters image − The original input image. alpha − The contrast value. Use 0 < alpha < 1 for lower contrast, alpha > 1 for higher contrast. beta − The brightness value. Good range is [−127, 127]. Alternatively, we can use cv2.addWeighted() function for the same purpose with different parameter handling. Input Image We will use the following image as ...
Read MoreOpencv Python – How to display the coordinates of points clicked on an image?
OpenCV provides us with different types of mouse events. There are different types of mouse events such as left or right button click, mouse move, left button double click etc. A mouse event returns the coordinates (x, y) of the mouse event. To perform an action when an event is performed we define a mouse callback function. We use left button click (cv2.EVENT_LBUTTONDOWN) and right button click (cv2.EVENT_RBUTTONDOWN) to display the coordinates of the points clicked on the image. Steps To display the coordinates of points clicked on the input image, you can follow the steps given below ...
Read More