Create Trackbar as 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

Convert RGB Image to HSV Image using OpenCV in Python

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

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

Create Black and White Images Using OpenCV in Python

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

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

Join Two Images Horizontally and Vertically Using OpenCV Python

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

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

Resize an Image in OpenCV Using Python

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

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

Use of Equivalence and Equality Operator in Python Classes

Sarika Singh
Updated on 23-Sep-2022 12:17:05

3K+ Views

Using comparison operators, we may compare various data types in Python. When creating custom classes, we are unable to simply compare them using the comparison operators. This article will go over various approaches to verify equivalence ("equality") in Python classes. Equality of class objects The == operator makes it simple to determine whether two built-in objects, such as strings or integers, are equal. This is demonstrated in the example below. Example Following is an example of == operator − char1 = 365 char2 = 83 result = char1 == char2 print("{} and {} are equivalent to each other:{}".format(char1, char2, result)) ... Read More

Compute Factorial of a Number in JavaScript

Nikhilesh Aleti
Updated on 23-Sep-2022 11:24:16

13K+ Views

In this article, the given task is to get the factorial of a number in JavaScript. What is the factorial of a number? The multiplication of all positive integers smaller than or equal to n gives the factorial of a non-negative integer. For example, assume the non-negative integer is 4 and the factorial of 4 will be 4*3*2*1 which is equal to 24. The symbol of factorial is represented by "!". so it will be (4!). The value of 0! Will be 1 as 0 is not a positive integer. The mathematical formula of factorial ("n!") This is ... Read More

Connect Your YouTube Mobile App to TV

Prachi Gupta
Updated on 23-Sep-2022 11:22:57

2K+ Views

Whether one wants to watch a favourite TV series or videos, YouTube offers a variety of entertaining content to his audiences. Viewers can enjoy watching YouTube on devices like computers, tablets, and mobile phones but all these devices have a very limited screen size making this online streaming less interesting. So, why settle for small-screen devices when we can watch YouTube videos on the big TV screen with the use of technology? With the new inventions that happen day-to-day in technology, users can now enjoy an optimal YouTube viewing experience by casting YouTube to TV. Casting on TV makes ... Read More

Convert Array of Objects to an Object in JavaScript

Nikhilesh Aleti
Updated on 23-Sep-2022 11:22:03

476 Views

The given there is an array and the task is to convert an array of objects to an object. Input-Output Scenario Let’s look into an input-output scenario of converting the array objects into an object. Consider there is an array having objects in it. Now, we need to convert those array objects into a single JSON object. Const Arr = [ {1:'one'}, {2:'two'} ]; Output = { "1":"one", "2":"two" }; //Object Using Object.assign() The ... Read More

Convert Two Arrays into a JSON Object in JavaScript

Nikhilesh Aleti
Updated on 23-Sep-2022 11:20:13

5K+ Views

Given two arrays and the task is to convert those two arrays into a JSON object. Where the first array elements are keys of the object and the second array elements are values of the object. Input-Output Scenario Let’s look into the scenario of how two arrays will be converted into a JSON object. Consider two arrays are having some elements. Now, we need to convert these two arrays into a JSON object. Array1 = [1, 2, 3, 4]; Array2 = ['A', 'B', 'C', 'D']; Output = {"1":"A", "2":"B", "3":"C", "4":"D"} //JSON object In this article, ... Read More

Advertisements