OpenCV Articles

Page 6 of 11

How to draw filled ellipses in OpenCV using Python?

Shahid Akhtar Khan
Shahid Akhtar Khan
Updated on 28-Sep-2022 3K+ Views

To draw a filled ellipse on an image, we use the cv2.ellipse() method. This method accepts different arguments to draw different types of ellipses. Syntax cv2.ellipse(img, center, axes, angle, start_angle, end_angle, color, thickness) Parameters img − The input image on which the ellipse is to be drawn. center − The center coordinate of the ellipse. axes − A tuple in (major axis length, minor axis length) format. angle − The rotation angle of an ellipse in degrees. start_angle − The starting angle of the elliptic arc in degrees. end_angle − The ending angle of the elliptic arc in ...

Read More

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

Shahid Akhtar Khan
Shahid Akhtar Khan
Updated on 28-Sep-2022 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, etc. 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. Steps You can use the following steps to check if a contour ...

Read More

How to Compute Image Moments in OpenCV Python?

Shahid Akhtar Khan
Shahid Akhtar Khan
Updated on 28-Sep-2022 6K+ Views

Image Moments are very important to compute the features like center of mass of an object, area of an object, etc., in a given image. Image moments are computed for an object using the contour of the object. So first, we detect the contour of the object, then apply cv2.moments(cnt) function to compute the moments. Syntax This is the syntax used for the function − cv2.moments(cnt) Where, "cnt" is a numpy array of the contour points of an object in the image. Steps You can use the following steps to compute the moments in an image − Import the ...

Read More

How to match image shapes in OpenCV Python?

Shahid Akhtar Khan
Shahid Akhtar Khan
Updated on 28-Sep-2022 8K+ Views

We use cv2.matchShapes() function to match two image shapes. This function returns a metric showing the similarity between the image shapes. This function uses 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, cnt1, 1, 0.0) Where, cnt1 − The contour points of the first image shape. cnt2 − The contour points of the second image ...

Read More

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

Shahid Akhtar Khan
Shahid Akhtar Khan
Updated on 28-Sep-2022 2K+ Views

We can form the Laplacian Pyramids from the Gaussian Pyramids. OpenCV does not provide any specific function to construct Laplacian Pyramids. In Laplacian pyramid, images look like edge images only. Laplacian Pyramids are used in image compression as well as in image enhancement. 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 in the Gaussian Pyramid. To create a level in the Gaussian pyramid, we apply the cv2.pyrDown() or cv2.pyrUp() function. Steps To construct a three-level Laplacian pyramid, follow the steps given below ...

Read More

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

Shahid Akhtar Khan
Shahid Akhtar Khan
Updated on 27-Sep-2022 2K+ Views

Using the Sobel operator, we can compute image gradients in horizontal as well as vertical direction. The gradients are computed for a grayscale image. The Laplacian operator computes the gradients using the second-order derivatives. Syntax The following syntaxes are used to compute the image gradients using Sobel and Laplacian derivatives − cv2.Sobel(img, ddepth, xorder, yorder, ksize) cv2.Laplacian(img, ddepth) Parameters img − The original input image. ddepth − Desired depth of the output image. It has information about what kind of data is stored in the output image. We use cv2.CV_64F to as ddepth. It is a 64bit floating-point ...

Read More

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

Shahid Akhtar Khan
Shahid Akhtar Khan
Updated on 27-Sep-2022 2K+ Views

In this tutorial, we will see how to apply two different low-pass filters to smooth (remove noise from) the image. The two filters are filter2D and boxFilter. These filters are 2D filters in space. 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". A bilateral filter operation preserves the edges.Syntax Following are the syntaxes of Filter2D and ...

Read More

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

Shahid Akhtar Khan
Shahid Akhtar Khan
Updated on 27-Sep-2022 6K+ Views

In Perspective Transformation, the straight lines remain straight even after the transformation. To apply a perspective transformation, we need a 3×3 perspective transformation matrix. We need four points on the input image and corresponding four points on the output image. We apply the cv2.getPerspectiveTransform() method to find the transformation matrix. Its syntax is as follows − M = cv2.getPerspectiveTransform(pts1, pts2) where, pts1 − An array of four points on the input image and pts2 − An array of corresponding four points on the output image. The Perspective Transformation matrix M is a numpy array. We pass M ...

Read More

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

Shahid Akhtar Khan
Shahid Akhtar Khan
Updated on 27-Sep-2022 5K+ Views

In Affine Transformation, all parallel lines in the original image will still be parallel in the output image. To apply affine transformation on an image, we need three points on the input image and corresponding point on the output image. So first, we define these points and pass to the function cv2.getAffineTransform(). It will create a 2×3 matrix, we term it a transformation matrix M. We can find the transformation matrix M using the following syntax − M = cv2.getAffineTransform(pts1, pts2) Where pts1 is an array of three points on the input image and pts2 is an array of ...

Read More

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

Shahid Akhtar Khan
Shahid Akhtar Khan
Updated on 27-Sep-2022 1K+ Views

To compute the histogram in OpenCV, we use the cv2.calcHist() function. In this tutorial, we will show how to compute the histogram for different colors (Blue, Green, and Red) of the input image. To compute and plot the histograms of different colors of an image, one could follow the steps given below − Steps Import the required libraries OpenCV and matplotlib. Make sure you have already installed them. import cv2 import matplotlib.pyplot as plt Read the images using cv2.imread() method. The width and height of images must be the same. img1 = cv2.imread('birds.jpg') Compute the histograms for different ...

Read More
Showing 51–60 of 107 articles
« Prev 1 4 5 6 7 8 11 Next »
Advertisements