Programming Articles

Page 174 of 2547

How to check if an image contour is convex or not in OpenCV Python?

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

The function cv2.isContourConvex() is used to check whether a curve (contour) is convex or not. A contour of an object in the image is a curve joining all the continuous points along the boundary, having the same color or intensity. Contours are used for shape analysis and object detection and recognition. Syntax The syntax for cv2.isContourConvex() is − cv2.isContourConvex(cnt) Where, "cnt" is a numpy array of the contour points of an object in the image. It returns True if the contour cnt is convex, else False. Understanding Convex vs Non-Convex Shapes A ...

Read More

How to compute the area and perimeter of an image contour using OpenCV Python?

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

OpenCV provides powerful functions to compute the area and perimeter of image contours. A contour is a curve joining all continuous points along a boundary with the same color or intensity, making them essential for shape analysis and object detection. To compute area and perimeter, we first detect contours using cv2.findContours(), then apply cv2.contourArea() and cv2.arcLength() functions respectively. Syntax The functions use the following syntax: area = cv2.contourArea(cnt) perimeter = cv2.arcLength(cnt, True) Where cnt is a NumPy array containing the contour points of an object. Steps to Compute Area and Perimeter ...

Read More

How to compare two images in OpenCV Python?

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

To compare two images, we use the Mean Square Error (MSE) of the pixel values of the two images. Similar images will have less mean square error value. Using this method, we can compare two images having the same height, width and number of channels. What is Mean Square Error? Mean Square Error (MSE) measures the average squared differences between corresponding pixels of two images. Lower MSE values indicate greater similarity between images. Steps to Compare Images You can use the following steps to compare two images using OpenCV − Step 1: Import the required ...

Read More

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
Showing 1731–1740 of 25,469 articles
« Prev 1 172 173 174 175 176 2547 Next »
Advertisements