Articles on Trending Technologies

Technical articles with clear explanations and examples

How to Compute Image Moments in OpenCV Python?

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

Image moments are statistical measures that describe the shape and size characteristics of objects in an image. They are essential for computing features like center of mass, area, and orientation of objects. In OpenCV, image moments are calculated using contours of detected objects. Syntax The basic syntax for computing image moments is ? cv2.moments(contour) Where contour is a NumPy array containing the contour points of an object. Understanding Image Moments Image moments provide valuable information about objects ? m00 ? Area of the object m10, m01 ? First-order moments used ...

Read More

How to match image shapes in OpenCV Python?

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

We use cv2.matchShapes() function to match two image shapes in OpenCV. This function returns a metric showing the similarity between the image shapes using Hu-Moments to calculate the metric value. Lower the metric value, higher the similarity between the image shapes. In the following examples, we will match the shapes from different images and also shapes from a single image. Syntax We use the following syntax to match two image shapes − ret = cv2.matchShapes(cnt1, cnt2, method, parameter) Where, cnt1 − The contour points of the first image ...

Read More

How to find Laplassian pyramids for an image using OpenCV in Python?

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

We can form Laplacian Pyramids from Gaussian Pyramids in OpenCV. While OpenCV doesn't provide a direct function to construct Laplacian Pyramids, we can create them by computing differences between Gaussian pyramid levels. In a Laplacian pyramid, images appear as edge-like representations and are commonly used in image compression and image enhancement applications. How Laplacian Pyramids Work A level in the Laplacian Pyramid is formed by the difference between that level in the Gaussian Pyramid and the expanded version of its upper level. The process involves: Creating a Gaussian pyramid using cv2.pyrDown() Expanding higher levels using ...

Read More

How to find the image gradients using Sobel and Laplacian derivatives in OpenCV Python?

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

Image gradients are essential in computer vision for detecting edges and boundaries. OpenCV provides Sobel and Laplacian operators to compute these gradients. The Sobel operator uses first-order derivatives to find gradients in horizontal and vertical directions, while the Laplacian operator uses second-order derivatives. Syntax The following syntaxes are used to compute image gradients ? cv2.Sobel(img, ddepth, dx, dy, ksize) cv2.Laplacian(img, ddepth) Parameters img − The input grayscale image. ddepth − Output image depth. Use cv2.CV_64F for 64-bit floating-point precision. dx − Order of derivative in X-direction (horizontal). Set dx=1, dy=0 for horizontal ...

Read More

How to apply custom filters to images (2D convolution) using OpenCV Python?

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

In this tutorial, we will learn how to apply custom filters to images using OpenCV Python. We'll explore two different low-pass filters: filter2D and boxFilter. These filters perform 2D convolution operations to smooth images and remove noise. Applying 2D filters to images is also known as the "2D Convolution operation". These filters are commonly referred to as averaging filters. The main disadvantage of these filters is that they also smooth the edges in the image. If you don't want to smooth the edges, you can apply a "bilateral filter" that preserves edges. Syntax Following are the syntaxes ...

Read More

How to apply Perspective Transformations on an image using OpenCV Python?

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

In Perspective Transformation, straight lines remain straight even after the transformation. To apply a perspective transformation, we need a 3×3 perspective transformation matrix and four points on both the input and output images. Key Functions We use cv2.getPerspectiveTransform() to find the transformation matrix − M = cv2.getPerspectiveTransform(pts1, pts2) Where: pts1 − An array of four points on the input image pts2 − An array of corresponding four points on the output image To apply the transformation, we use cv2.warpPerspective() − dst = cv2.warpPerspective(img, M, (width, height)) Where: ...

Read More

How to apply Affine Transformation on an image in OpenCV Python?

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

Affine Transformation is a geometric transformation that preserves parallel lines in an image. This transformation requires three corresponding points between the input and output images to create a transformation matrix. Syntax To get the transformation matrix ? M = cv2.getAffineTransform(pts1, pts2) To apply the transformation ? cv2.warpAffine(img, M, (cols, rows)) Parameters pts1 − Array of three points on the input image pts2 − Array of corresponding three points on the output image img − Input image to be transformed M − 2×3 transformation matrix of type np.float64 (cols, ...

Read More

How to plot histograms of different colors of an image in OpenCV Python?

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

To compute the histogram in OpenCV, we use the cv2.calcHist() function. In this tutorial, we will show how to compute and plot histograms for different color channels (Blue, Green, and Red) of an input image. A histogram shows the distribution of pixel intensities in an image. For color images, we can create separate histograms for each color channel to analyze the color composition. Understanding cv2.calcHist() Parameters The cv2.calcHist() function takes the following parameters ? images − Source image as a list [img] channels − Channel index [0] for Blue, [1] for Green, [2] for Red ...

Read More

How to perform image translation using OpenCV in Python?

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

Image translation is the process of shifting an image to a new position within the coordinate system. OpenCV provides the cv2.warpAffine() function along with translation matrices to perform this transformation efficiently. Translation Matrix To translate an image by (tx, ty) pixels, where tx is horizontal shift and ty is vertical shift, we define a 2x3 translation matrix: import numpy as np # Translation matrix for shifting by (tx, ty) tx, ty = 100, 50 # 100px right, 50px down M = np.float32([[1, 0, tx], [0, 1, ty]]) print("Translation matrix:") print(M) Translation ...

Read More

How to find the HSV values of a color using OpenCV Python?

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

To find the HSV values of a color, we can use color space conversion from BGR to HSV. First we define the color value in BGR format as numpy.ndarray and then convert it to HSV space. We can also find the lower and upper limits of HSV value as [H-10, 100, 100] and [H+10, 255, 255] respectively. These lower and upper limits can be used to track an object of particular color. Steps Import the required libraries. In all the following Python examples, the required Python libraries are OpenCV and NumPy. Make sure you have already installed ...

Read More
Showing 1–10 of 61,303 articles
« Prev 1 2 3 4 5 6131 Next »
Advertisements