Programming Articles

Page 161 of 2547

How to detect humans in an image in OpenCV Python?

Shahid Akhtar Khan
Shahid Akhtar Khan
Updated on 26-Mar-2026 15K+ Views

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 More

How to detect polygons in image using OpenCV Python?

Shahid Akhtar Khan
Shahid Akhtar Khan
Updated on 26-Mar-2026 6K+ Views

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 More

How to detect eyes in an image using OpenCV Python?

Shahid Akhtar Khan
Shahid Akhtar Khan
Updated on 26-Mar-2026 12K+ Views

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 More

How to change the contrast and brightness of an image using OpenCV in Python?

Shahid Akhtar Khan
Shahid Akhtar Khan
Updated on 26-Mar-2026 50K+ Views

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 More

Opencv Python – How to display the coordinates of points clicked on an image?

Shahid Akhtar Khan
Shahid Akhtar Khan
Updated on 26-Mar-2026 16K+ Views

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

How to detect a face and draw a bounding box around it using OpenCV Python?

Shahid Akhtar Khan
Shahid Akhtar Khan
Updated on 26-Mar-2026 6K+ Views

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 More

How to perform image transpose using OpenCV Python?

Shahid Akhtar Khan
Shahid Akhtar Khan
Updated on 26-Mar-2026 2K+ Views

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 More

Color quantization in an image using K-means in OpenCV Python?

Shahid Akhtar Khan
Shahid Akhtar Khan
Updated on 26-Mar-2026 3K+ Views

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 More

How to create a depth map from stereo images in OpenCV Python?

Shahid Akhtar Khan
Shahid Akhtar Khan
Updated on 26-Mar-2026 10K+ Views

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 More

How to blur faces in an image using OpenCV Python?

Shahid Akhtar Khan
Shahid Akhtar Khan
Updated on 26-Mar-2026 3K+ Views

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 More
Showing 1601–1610 of 25,469 articles
« Prev 1 159 160 161 162 163 2547 Next »
Advertisements