Found 184 Articles for OpenCV

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

Shahid Akhtar Khan
Updated on 27-Sep-2022 12:22:11

12K+ 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. To find the HSV values of a color, follow the steps given below − Steps Import the required libraries. In all the following Python examples, the required Python ... Read More

How to create a trackbar as the HSV color palette using OpenCV Python?

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

1K+ Views

To create trackbars as the HSV (Hue, Saturation and Value) color palette in OpenCV, we apply two different functions. These functions are cv2.reateTrackbar() and cv2.getTrackbarPos() The cv2.reateTrackbar() function is used to create a trackbar, while cv2.getTrackbarPos() function is used to access the value of the selected trackbar position. Using these two functions, we create a window that contains the trackbars for H, S, V colors and a color window to display the selected color. By changing the position of trackbars, we can select a particular value of color. The range for H is between 0 and 179, whereas for ... Read More

How to create a trackbar as the RGB color palette using OpenCV Python?

Shahid Akhtar Khan
Updated on 27-Sep-2022 12:05:22

1K+ Views

In OpenCV, a trackbar can be created using cv2.reateTrackbar() function. To access the value of the selected trackbar position, we use cv2.getTrackbarPos() function. Using these two functions, we create a window that contains the trackbars for R, G, B colors and a color window to display the selected color. By changing the position of trackbars RGB colors change between 0 and 255. See the below syntaxes for both functions. Syntax cv2.createTrackbar(trackbar_name, window_name, default_value, max_value, callback_func) cv2.getTrackbarPos(trackbar_name, window_name) Parameters trackbar_name − It's the trackbar name. This name is used to access the trackbar position value. window_name − It is ... Read More

How to convert an RGB image to HSV image using OpenCV Python?

Shahid Akhtar Khan
Updated on 27-Sep-2022 11:57:39

19K+ Views

An RGB (colored) image has three channels, Red, Blue and Green. A colored image in OpenCV has a shape in [H, W, C] format, where H, W, and C are image height, width and number of channels. All three channels have a value range between 0 and 255. The HSV image also has three channels, the Hue, Saturation and Value channels. In OpenCV, the values of the Hue channel range from 0 to 179, whereas the Saturation and Value channels range from 0 to 255. In OpenCV, to convert an RGB image to HSV image, we use the cv2.cvtColor() function. ... Read More

How to create a black image and a white image using OpenCV Python?

Shahid Akhtar Khan
Updated on 27-Sep-2022 11:54:58

17K+ Views

To create a black image, we could use the np.zeros() method. It creates a numpy n-dimensional array of given size with all elements as 0. As all elements are zero, when we display it using cv2.imshow() or plt.imshow() functions, it displays a balck image. To create a white image, we could use the np.ones() method. It creates a numpy n-dimensional array of given size with all elements as 1. We multiply this array by 255 to create a white image. Now all elements are 255, so when we display it using cv2.imshow() or plt.imshow() functions it gives a white image. ... Read More

How to join two images horizontally and vertically using OpenCV Python?

Shahid Akhtar Khan
Updated on 27-Sep-2022 11:52:01

4K+ Views

Images in OpenCV are represented as numpy.ndarray. OpenCV provides two functions − cv2.hconcat() and cv2.vconcat() to join images. The function cv2.hconcat() joins images horizontally and the function cv2.vconcat() joins images vertically. These functions join two or more images. These functions accept a list of images of the same size to join them. The height, width and number of channels of all images must be the same to join them Syntax cv2.hconcat(img_list) cv2.vconcat(img_list) Where img_list is a list of images [img1, img2, …]. To join the images horizontally or vertically, one could follow the steps given below − ... Read More

How to resize an image in OpenCV using Python?

Shahid Akhtar Khan
Updated on 27-Sep-2022 10:33:16

10K+ Views

OpenCV provides the function cv2.resize() to resize an image. Resizing in OpenCV is referred to as scaling. We can resize an image by specifying the image size or scaling factor. The aspect ratio is preserved when we specify the scaling factor. There are different interpolation methods used in cv2.resize() function − cv2.INTER_AREA − Used for shrinking an image. cv2.INTER_CUBIC − It’s slow, used for zooming. cv2.INTER_LINEAR − Used for zooming. It is default for all resizing purposes. Steps You can use the following steps to resize an image − Import the required libraries. In all the following Python ... Read More

Detecting contours in an image using OpenCV

Prasad Naik
Updated on 17-Mar-2021 08:50:38

555 Views

In this program, we will detect contours in an image. Contours can be explained simply as a curve joining all the continuous points having the same color or intensity. The contours are a useful tool for shape analysis and object detection and recognition.Original ImageAlgorithmStep 1: Import OpenCV. Step 2: Import matplotlib. Step 3: Read the image. Step 4: Convert the image from bgr2rgb. Step 5: Convert the rgb image to grayscale. Step 4: Perform thresholding on the image. Step 5: Find contours on the image. Step 6: Draw contours on the image. Step 7: Display the output.Example Codeimport cv2 import ... Read More

Performing inverse zero thresholding on an image using OpenCV

Prasad Naik
Updated on 17-Mar-2021 08:41:43

217 Views

In this program, we will perform inverse zero thresholding on an image using openCV. Thresholding is a process in which the value of each pixel is changed in relation to a threshold value. The pixel is given a certain value if it is less than the threshold and some other value if it is greater than the threshold. In inverse zero thresholding, pixels having intensity value greater than the threshold value are set to 0.Original ImageAlgorithmStep 1: Import cv2. Step 2: Define the threshold and max_val. Step 3: Pass these parameters in the cv2.threshold value and specify the type of ... Read More

Performing zero thresholding on an image using OpenCV

Prasad Naik
Updated on 17-Mar-2021 08:42:20

424 Views

In this program, we will perform zero thresholding on an image using openCV. Thresholding is a process in which the value of each pixel is changed in relation to a threshold value. The pixel is given a certain value if it is less than the threshold and some other value if it is greater than the threshold. In zero thresholding, pixels having intensity value less than the threshold value are set to 0.Original ImageAlgorithmStep 1: Import cv2. Step 2: Define the threshold and max_val. Step 3: Pass these parameters in the cv2.threshold value and specify the type of thresholding you ... Read More

Advertisements