Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Gireesha Devara
Page 2 of 18
Python Program To Convert dictionary values to Strings
A dictionary in Python is an unordered collection of key-value pairs. It is a data structure that allows you to store and retrieve values based on a unique key associated with each value. Keys in a dictionary must be immutable (strings, numbers, or tuples), while values can be of any data type and can be mutable. When we want to convert dictionary values to strings, we need to iterate over the dictionary and convert each value to a string using the str() function. Input Output Scenarios See the following input-output scenarios to understand the concept of converting ...
Read MorePython Program to convert Dictionary to List by Repeating keys corresponding value times
In Python, dictionaries are key-value pairs where each key is associated with a corresponding value. When we want to convert a dictionary to a list by repeating keys, we need to iterate over each key-value pair and repeat the key based on its corresponding value. Input Output Scenarios See the following input-output scenarios to understand the concept of converting a dictionary to a list by repeating keys corresponding to the number present in the values ? Input dictionary: {'a': 3, 'b': 2, 'c': 1} Output list: ['a', 'a', 'a', 'b', 'b', 'c'] In the ...
Read MorePython program to convert Dict of list to CSV
A dictionary of lists is a common data structure where each key maps to a list of values. Converting this structure to CSV format is useful for data analysis and sharing tabular data. Here's an example of a dictionary of lists ? data = { 'numbers': [1, 2, 3, 4, 5, 6], 'states': ['UP', 'Tamil Nadu', 'Telangana', 'Gujarat', 'UP', 'Tamil Nadu'], 'cities': ['Agra', 'Chennai', 'Hyderabad', 'Surat', 'Lucknow', 'Coimbatore'] } print(data) {'numbers': [1, 2, 3, 4, 5, 6], 'states': ['UP', 'Tamil Nadu', 'Telangana', ...
Read MoreNegative transformation of an image using Python and OpenCV
An image with reversed brightness is referred to as a negative image, where the light parts appear dark and the darker parts appear lighter. In a colored image (RGB), the negative transformation reverses colors − red areas appear cyan, greens appear magenta, and blues appear yellow. Negative transformation is widely used in Medical Imaging, Remote Sensing, and other applications. It helps reveal details from darker regions of the image. Negative Transformation Formula For an 8-bit image with maximum intensity value 255, we subtract each pixel from 255 to produce the negative image ? s = ...
Read MoreGet video duration using OpenCV Python
OpenCV is an Open Source Computer Vision Library in Python that provides numerous functions for image and video processing operations. The library uses NumPy to represent video frames and images as ndarray objects. In this article, we will explore different methods to get video duration using OpenCV Python by leveraging the VideoCapture.get() method with specific property flags. Understanding VideoCapture Properties The OpenCV VideoCapture.get() method retrieves specified properties of a video by passing property identifier flags ? Syntax VideoCapture.get(propId) Key property identifiers for duration calculation ? CAP_PROP_FRAME_COUNT: Total number of frames ...
Read MoreDraw a triangle with centroid using OpenCV
The centroid (geometric center) of a triangle is the point where all three medians intersect. It can be calculated by taking the average of the x and y coordinates of all three vertices. Centroid A B C Centroid Formula For a triangle with vertices A(x1, y1), B(x2, y2), and C(x3, y3), the centroid is calculated as ? Centroid = ((x1+x2+x3)/3, (y1+y2+y3)/3) In this article, we will draw a triangle with its centroid using OpenCV in Python. ...
Read MoreDrawing a cross on an image with OpenCV
OpenCV is an Open Source Computer Vision Library in Python that provides numerous functions to perform various image and video processing operations. The library uses the NumPy module to represent all video frames and images as ndarray types. In this article, we will explore different ways to draw a cross on an image using OpenCV Python. A cross can be drawn using built-in marker functions or by drawing intersecting lines manually. Input Output Scenario We start with an input image and draw a cross marker on it. The output shows the cross overlaid on the original image ...
Read MoreDraw Multiple Rectangles in Image using OpenCV Python
OpenCV is an Open Source Computer Vision Library in Python that provides numerous functions to perform various image and video processing operations. In this article, we will explore different ways to draw multiple rectangles in an image using OpenCV Python. To draw rectangular shapes on an image, OpenCV provides the cv2.rectangle() method which can be used in various approaches to create multiple rectangles efficiently. The cv2.rectangle() Function The cv2.rectangle() method draws rectangular shapes on an image. Following is the syntax ? cv2.rectangle(img, pt1, pt2, color[, thickness[, lineType[, shift]]]) Parameters img: The ...
Read MoreRemoving Black Background and Make Transparent using OpenCV Python
In digital images, transparency is the functionality that supports transparent areas in an image or image layer. For image processing and editing, background removal allows us to highlight the subject of the photo and create a transparent background to place the subject into various new designs and destinations. Certain image formats do not support transparency. For example, PNG, TIFF, and WebP graphics formats support transparency, whereas JPEGs do not. In this article, we will see how to remove the black background from an image to make it transparent using OpenCV Python. Like RGB channels, the alpha channel is ...
Read MoreDraw a rectangular shape and extract objects using Python\'s OpenCV
OpenCV is an Open Source Computer Vision Library in Python. It provides numerous functions to perform various image and video processing operations. The library uses the NumPy module to represent all video frames and images as ndarray types. In this article, we will see different ways to draw rectangular shapes and extract objects using Python OpenCV. Drawing a Rectangle To draw a rectangular shape on an image, Python OpenCV provides the cv2.rectangle() method. Following is the syntax ? Syntax cv2.rectangle(img, pt1, pt2, color[, thickness[, lineType[, shift]]]) Parameters img: The source ...
Read More