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
Page 2 of 17
How to detect a face and draw a bounding box around it using OpenCV Python?
Face detection is a fundamental computer vision task that can be accomplished using OpenCV and Haar cascade classifiers. A Haar cascade classifier is an effective machine learning approach for object detection that uses pre-trained XML files to identify specific features like faces. We will use haarcascade_frontalface_alt.xml as our Haar cascade file for detecting frontal faces in images. Downloading Haar Cascade Files OpenCV provides pre-trained Haar cascade files on GitHub ? https://github.com/opencv/opencv/tree/master/data/haarcascades To download the face detection cascade, click on haarcascade_frontalface_alt.xml, view it in raw format, then right-click and save to your project directory. Note: ...
Read MoreHow to perform image transpose using OpenCV Python?
OpenCV represents images as NumPy ndarrays, allowing us to use array operations on images. Image transpose in OpenCV flips an image along its main diagonal − rows become columns and columns become rows. We use cv2.transpose() to perform this operation. Syntax The syntax for transposing an image is ? cv2.transpose(src) Parameters src ? Input image (NumPy array) Return Value Returns the transposed image as a NumPy array. Basic Image Transpose Let's create a simple example to demonstrate image transposition ? import cv2 import numpy as ...
Read MoreColor quantization in an image using K-means in OpenCV Python?
Color quantization reduces the number of colors in an image by grouping similar colors together. This technique helps reduce memory usage and is essential for devices with limited color display capabilities. OpenCV provides cv2.kmeans() to perform K-means clustering for efficient color quantization. How Color Quantization Works K-means clustering groups pixels with similar colors into K clusters. Each cluster's centroid becomes the representative color for all pixels in that cluster, effectively reducing the total number of colors to K. Steps for Implementation To implement color quantization using K-means clustering, follow these steps: Import required libraries ...
Read MoreHow to create a depth map from stereo images in OpenCV Python?
A depth map represents the distance of objects from the camera in a 3D scene. OpenCV Python provides stereo vision capabilities to create depth maps from two images taken from slightly different viewpoints. The process involves computing disparities between corresponding pixels in stereo image pairs using the StereoBM class. Understanding Stereo Vision Stereo vision mimics human binocular vision by using two cameras positioned horizontally apart. The disparity (difference in pixel positions) between corresponding points in the left and right images is inversely proportional to the depth − closer objects have larger disparities. Steps to Create a Depth ...
Read MoreHow to blur faces in an image using OpenCV Python?
Face blurring is a common computer vision task used for privacy protection in images. OpenCV provides an efficient way to detect and blur faces using Haar cascade classifiers combined with Gaussian blur filtering. Prerequisites Before starting, you need to download the Haar cascade XML file for face detection. You can find different haarcascades at the following GitHub repository − https://github.com/opencv/opencv/tree/master/data/haarcascades Download the haarcascade_frontalface_alt.xml file by opening it in raw format, right-clicking, and saving it to your project folder. Steps for Face Blurring Follow these steps to blur faces in an image − ...
Read MoreHow to implement ORB feature detectors in OpenCV Python?
ORB (Oriented FAST and Rotated BRIEF) is a fusion of FAST keypoint detector and BRIEF descriptors with many modifications to enhance performance. ORB is rotation invariant and resistant to noise, making it ideal for real-time applications like object recognition and image matching. Steps to Implement ORB Feature Detector To implement ORB feature detector and descriptors, follow these steps: Import the required libraries OpenCV and NumPy. Make sure you have already installed them. Read the input image using cv2.imread() method. Specify the full path of the image. Convert the input image to grayscale using cv2.cvtColor() method. Initiate ...
Read MoreHow to detect and draw FAST feature points in OpenCV Python?
FAST (Features from Accelerated Segment Test) is a high-speed corner detection algorithm designed for real-time applications. OpenCV provides a simple interface to detect corner features using the FAST algorithm through cv2.FastFeatureDetector_create(). How FAST Algorithm Works FAST detects corners by examining a circle of 16 pixels around each candidate point. If a continuous arc of pixels (usually 12 or more) are all brighter or darker than the center pixel by a threshold value, it's classified as a corner feature. Steps to Detect FAST Features To detect and draw feature points using the FAST detector, follow these steps ...
Read MoreOpenCV Python – How to detect and draw keypoints in an image using SIFT?
SIFT (Scale-Invariant Feature Transform) is a scale invariant feature descriptor that detects keypoints in images and computes their descriptors. SIFT keypoints are robust to changes in scale, rotation, and illumination, making them ideal for object recognition and image matching tasks. How SIFT Works SIFT detects keypoints by finding locations in an image that are distinctive and stable across different scales. The algorithm creates a SIFT object with cv2.SIFT_create(), detects keypoints using sift.detect(), and draws them using cv2.drawKeypoints(). Steps to Detect and Draw Keypoints To detect and draw keypoints in an input image using SIFT algorithm, follow ...
Read MoreHow to perform matrix transformation in OpenCV Python?
The cv2.transform() function performs matrix transformation of each element in an input array. Since images in OpenCV are NumPy arrays, we can apply transformations directly to modify pixel values using a transformation matrix. Syntax cv2.transform(src, m, dst=None) Parameters src − Input array (image) m − Transformation matrix of size (output_channels, input_channels) dst − Output array (optional) Steps to Perform Matrix Transformation Follow these steps to apply matrix transformation to an image − Import the required libraries OpenCV and NumPy Read the input image using cv2.imread() Define a transformation ...
Read MoreHow to extract the foreground of an image using OpenCV Python?
OpenCV's GrabCut algorithm is a powerful method for foreground extraction from images. The cv2.grabCut() function uses iterative graph cuts to separate foreground objects from the background based on a user-defined rectangle. Algorithm Overview GrabCut works by modeling foreground and background pixels using Gaussian Mixture Models (GMM). You define a rectangle around the object of interest, and the algorithm iteratively refines the segmentation ? Step-by-Step Process Import required libraries OpenCV and NumPy Read the input image using cv2.imread() Initialize variables: mask, bgdModel, and fgdModel Define rectangle coordinates (x, y, width, height) that enclose the foreground object ...
Read More