Found 184 Articles for OpenCV

OpenCV Python – How to draw curves using Mouse Events?

Shahid Akhtar Khan
Updated on 02-Dec-2022 07:22:31

1K+ Views

There are different types of muse events such as left or right button click, mouse move, left button double click etc. OpenCV provides us with different types of mouse events such as cv2.EVENT_LBUTTONDOWN for mouse left button down, cv2.EVENT_LBUTTONDBLCLK for left button double click and others. A mouse event returns the coordinates (x, y) of the mouse event. To perform an action when an event happens we define a mouse callback function. We use cv2.EVENT_LBUTTONDOWN cv2.EVENT_MOUSEMOVE and cv2.EVENT_LBUTTONUP mouse events to draw curves on the image. Steps To draw curves using mouse events, follow the steps given below − ... Read More

OpenCV Python – How to draw a rectangle using Mouse Events?

Shahid Akhtar Khan
Updated on 02-Dec-2022 07:16:05

5K+ Views

There are different types of muse 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 happens we define a mouse callback function. We use cv2.EVENT_LBUTTONDOWN, cv2.EVENT_MOUSEMOVE and cv2.EVENT_LBUTTONUP mouse events to draw rectangles on the image. Steps To draw rectangles using mouse events, follow the steps given below − Import required library OpenCV. Make sure you have already installed it. Create a black image. We draw the rectangles on this black image. We ... Read More

How to mask an image in OpenCV Python?

Shahid Akhtar Khan
Updated on 25-Aug-2023 01:20:28

38K+ Views

We can apply a mask to an image by computing the cv2.bitwise_and() between the mask and the image. To track a color, we define a mask in HSV color space using cv2.inRange() passing lower and upper limits of color values in HSV.Also Read: Color Identification in Images using Python and OpenCV To track a part of the image we can define a mask using np.zeros() and slicing the entries with white (255) for the region in the input image to examine. Follow the given steps to mask an image − The first step is to import required libraries. The ... Read More

How to flip an image in OpenCV Python?

Shahid Akhtar Khan
Updated on 02-Dec-2022 07:12:23

15K+ Views

In OpenCV, an image can be flipped using the function cv2.flip(). Using this function we can flip the image across X-axis, Y-axis and across both axes. It accepts a flag flipCode as an argument to flip the image across the axis. If the flipCode is set to 0, the image is flipped across the x-axis and if the flipCode is set to a positive integer (say 1), the image is flipped across the Y-axis. If the flipCode is set to a negative integer (say "-1"), the image is flipped across both axes. Steps To flip an image, one could ... Read More

How to access and modify pixel value in an image using OpenCV Python?

Shahid Akhtar Khan
Updated on 02-Dec-2022 07:10:33

13K+ Views

To access a single pixel value in an image we can use indexing the same as we do to NumPy array indexing. We can use slicing to access a sequence of pixel values. To modify the pixel values we use the simple Python assignment operator ("="). Steps To access and modify pixel values in an image we could follow the below steps- 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 RGB image using cv2.imread(). The RGB image read using this method ... Read More

How to split an image into different color channels in OpenCV Python?

Shahid Akhtar Khan
Updated on 02-Dec-2022 07:08:26

7K+ Views

A color image consists of three color channels- Red, Green and Blue. These color channels can be split using cv2.split() function. Let's look at the steps to split an image into different color channels- 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() method. Specify full path of image with the image type (i.e. png or jpg) Apply cv2.split() function on the input image img. It returns blue, green and red channel pixel values as numpy arrays. Assign ... Read More

OpenCV Python – How to perform SQRBox filter operation on an image?

Shahid Akhtar Khan
Updated on 02-Dec-2022 07:04:51

246 Views

We can perform SQRBox Filter operation on an image using cv2.sqrBoxFilter(). It calculates the normalized sum of squares of the pixel values overlapping the filter. We use the following syntax for this method − cv2.sqrBoxFilter(img, ddepth, ksize, borderType) where, img is the input image, ddepth is the output image depth, ksize is kernel size and borderType is border mode used to extrapolate pixels outside of the image. Steps To perform SQRBox filter operation, you could follow the steps given below- Import the required library. In all the following examples, the required Python library is OpenCV. Make sure ... Read More

OpenCV Python – How to add borders to an image?

Shahid Akhtar Khan
Updated on 02-Dec-2022 07:02:40

1K+ Views

OpenCV provides the function cv2.copyMakeBorder() to add borders in images. To add border in an image, you could follow the steps given below − The first step is to import required libraries. In all below Python examples the required Python library is OpenCV. Make sure you have already installed it. The next step is to read an input image using the cv2.imread() function. Specify the full image path with image types (.jpg or .png). Specify different parameters to the function cv2.copyMakeBorder(). The different parameters to be specified are src, dst, top, bottom, left, right, borderType, and value. Call ... Read More

OpenCV Python – How to find and draw extreme points of an object on an image?

Shahid Akhtar Khan
Updated on 02-Dec-2022 06:59:32

2K+ Views

To find and draw the extreme points of an object in the input image, we could follow the steps given below − The first step is to import required libraries. In all below Python examples the required Python library is OpenCV. Make sure you have already installed it. The next step is to read an input image using the cv2.imread() function. Specify the full image path with image types (.jpg or .png). Convert the input image to grayscale. Apply thresholding on the grayscale image to create a binary image. Adjust the second parameter to get a better contour ... Read More

OpenCV Python – How to draw circles using Mouse Events?

Shahid Akhtar Khan
Updated on 02-Dec-2022 06:55:16

2K+ Views

There are different types of muse events such as left or right button click, mouse move, left button double click etc. OpenCV provides us with different types of mouse events such as cv2.EVENT_LBUTTONDOWN for mouse left button down, cv2.EVENT_RBUTTONDOWN for right button down, cv2.EVENT_LBUTTONDBLCLK for left button double click and others. A mouse event returns the coordinates (x, y) of the mouse event. To perform an action when an event happens, we define a mouse callback function. We use mouse events to draw circles on the image. Steps To draw circles using mouse events, follow the steps given below ... Read More

Previous 1 ... 4 5 6 7 8 ... 19 Next
Advertisements