Draw Arrowed Line on an Image in OpenCV Python

Shahid Akhtar Khan
Updated on 27-Sep-2022 13:13:41

3K+ Views

OpenCV provides the function cv2.arrowedLine() to draw an arrowed line on an image. This function takes different arguments to draw the line. See the syntax below. cv2.arrowedLine(img, start, end, color, thickness, line_type, shift, tip_length) img − The input image on which the line is to be drawn. Start − Start coordinate of the line in (width, height) format. End − End coordinate of the line in (width, height) format. Color − Color of the line. For a red color in BGR format we pass (0, 0, 255) Thickness − Thickness of the line in pixels. line_type − Type ... Read More

Draw a Rectangle in HTML5 SVG

Yaswanth Varma
Updated on 27-Sep-2022 13:12:55

2K+ Views

SVG is a markup language based on XML that is used to describe two-dimensional vector graphics. SVG is essentially what HTML is to text when it comes to visuals. A rectangle is drawn on the screen via the element. The placement and shape of the rectangles on the screen are determined by six fundamental properties. Syntax Attributes X − The top-left x-axis coordinate. Y − The top-left y-axis coordinate. width − The rectangle's width. height − The rectangle's height. rx − The x-axis' roundness. ry − The y-axis' roundness. style − Indicate an inline style. ... Read More

Apply Affine Transformation on an Image in OpenCV Python

Shahid Akhtar Khan
Updated on 27-Sep-2022 13:10:02

4K+ 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

Perform Bitwise AND Operation on Two Images in OpenCV Python

Shahid Akhtar Khan
Updated on 27-Sep-2022 13:07:30

3K+ Views

A very important application of bitwise AND operation in computer vision or image processing is for creating masks of the image. We can also use the operator to add watermarks to an image. The pixel values of an image are represented as a numpy ndarray. The pixel values are stored using 8-bit unsigned integers (uint8) in a range from 0 to 255. The bitwise AND operation between two images is performed on the binary representation of these pixel values of corresponding images. Given below is the syntax to perform bitwise AND operation on two images − cv2.bitwise_and(img1, img2, mask=None) ... Read More

Plot Histograms of Different Colors of an Image in OpenCV Python

Shahid Akhtar Khan
Updated on 27-Sep-2022 13:03:06

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

Perform Image Rotation in OpenCV Using Python

Shahid Akhtar Khan
Updated on 27-Sep-2022 12:57:33

2K+ Views

To perform image rotation by an angle, we first need to get the rotation matrix. To find the rotation matrix, we apply cv2.getRotationMatrix2D() function. The syntax for this function is − M = cv2.getRotationMatrix2D(cr, degree, scale) Where cr is the center of rotation, degree is the angle by which image is rotated and scale is scale factor to scale up or scale down the image. The rotation matrix M is a 2×2 matrix (numpy array). We pass the rotation matrix M to cv2.warpAffine() function as an argument. See the syntax below − Syntax cv2.warpAffine(img, M, (width, height)) Here, ... Read More

Perform Image Translation Using OpenCV in Python

Shahid Akhtar Khan
Updated on 27-Sep-2022 12:51:32

3K+ Views

Shifting the image location in a particular direction is referred to as Image Translation. To perform image translation, we should first understand what is a translation matrix and how to define it using OpenCV and NumPy. If we want to make a translation in (x, y) direction, let it be (tx, ty). tx is the shift in horizontal direction and ty is the shift in vertical direction. Using (tx, ty), we can define the translation matrix M as below − M = np.float32([[1, 0, tx], [0, 1, ty]]) The translation matrix M is a numpy array of type np.float32. ... Read More

Perform Otsu's Thresholding on an Image Using Python OpenCV

Shahid Akhtar Khan
Updated on 27-Sep-2022 12:45:23

4K+ Views

Otsu’s thresholding is a kind of thresholding technique. There are other types of thresholding techniques such as simple thresholding and adaptive thresholding. The simple thresholding technique uses a global threshold value while the adaptive thresholding technique uses different threshold values for different regions. Otsu’s thresholding technique uses a global threshold value but it is not chosen. It is determined automatically. It works accurately for bimodal images. The bimodal images are those images whose histogram has two peaks. The threshold value is the approximate value of the middle of these two peaks. If the image is not bimodal this thresholding is ... Read More

Perform Adaptive Mean and Gaussian Thresholding of an Image using Python OpenCV

Shahid Akhtar Khan
Updated on 27-Sep-2022 12:38:50

2K+ Views

Adaptive thresholding is a kind of thresholding technique. There are other types of thresholding techniques such as simple thresholding that uses a global threshold value. But using a global threshold value is not a good idea for an image having different lighting conditions in different areas. Adaptive thresholding calculates the threshold value for a small region in the image. So we have different threshold values for different regions in the image which gives better results in comparison to the simple thresholding technique. There are three special parameters: adaptive_method, block_size and const. See the syntax given below. Syntax cv2.adaptiveThreshold(img, max_val, adaptive_method, ... Read More

Different Simple Thresholding Techniques in Python OpenCV

Shahid Akhtar Khan
Updated on 27-Sep-2022 12:32:46

867 Views

In simple thresholding, we define a threshold value and if a pixel value is greater than a threshold value, it is assigned a value (say 255), else it is assigned another value (say 0). A simple thresholding can be applied using the function cv2.threshold(). It accepts four arguments− the source image, threshold value, the maxVal and the thresholding type. OpenCV provides the following different types of thresholding − cv2.THRESH_BINARY − In this thresholding, pixel value more than the threshold value is assigned to 255 else assigned to 0. cv2.THRESH_BINARY_INV − It is the opposite case of cv2.THRESH_BINARY. cv2.THRESH_TRUNC − ... Read More

Advertisements