
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 10476 Articles for Python

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

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

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

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

7K+ Views
In this article, we will learn about the “with” statement in python and its uses. The with statement in Python replaces a try-catch block with a simple shorthand. More significantly, it ensures that resources are closed immediately after processing. Reading or writing to a file is a common use of the with statement. A context manager is a function or class that supports the with statement. A context manager enables you to open and close resources right when you want to. The open() function, for example, is a context manager. When you use the with statement to call the ... Read More

11K+ Views
It can be difficult for beginners to grasp the concept of Python modules and libraries. You can tell from the zoom-out content that each of them is a collection of codes. But there is a significant difference between them. In this article, we will show you the major difference between python modules and libraries. Python Modules and Libraries Real-world programs are complicated. Even simple software contains thousands of lines of code. Because of this, writing code in continuous flow is difficult for programmers and developers to grasp. Developers utilize modular programming to facilitate learning and make it logically separated. It ... Read More

5K+ Views
In this article, we will explain what are the compound datatypes and data structures in python. Variables have so far only stored one value. What if we wish to save many related values? We could simply create distinct variables for each. But what if we don't know how many values will be present? What if we wish to use these values within a loop? Compound data structures are data types that can store a large number of values. In Python, there are various types of compound data structures. We will mostly concentrate on Lists. In the end, we will ... Read More

23K+ Views
To access the serial port in Python, use the pyserial module, which Python Serial Port Extension for Win32, OSX, Linux, BSD, Jython, IronPython. Let us see the features - Access to the port settings through Python properties. Support for different byte sizes, stop bits, parity and flow control with RTS/CTS and/or Xon/Xoff. Working with or without receive timeout. The files in this package are 100% pure Python. The port is set up for binary transmission. No NULL byte stripping, CR-LF translation etc. To install pyserial, use pip pip install pyserial At first import the required libraries. import ... Read More

13K+ Views
A module can find out its own module name by looking at the predefined global variable __name__. If this has the value '__main__', the program is running as a script. Example def main(): print('Testing…...') ... if __name__ == '__main__': main() Output Testing…... Modules that are usually used by importing them also provide a command-line interface or a selftest, and only execute this code after checking __name__. The__name__ is an in-built variable in python language, we can write a program just to see the value of this variable. Here’s an ... Read More

178 Views
To parcel out work among a bunch of worker threads, use the concurrent.futures module, especially the ThreadPoolExecutor class. With that an alternative, if you want fine control over the dispatching algorithm, you can write your own logic manually. Use the queue module to create a queue containing a list of jobs. The Queue class maintains a list of objects and has a .put(obj) method that adds items to the queue and a .get() method to return them. The class will take care of the locking necessary to ensure that each job is handed out exactly once. Example Following is an ... Read More