In this tutorial, we are going to learn about the arithmetic operations on Images using OpenCV. We can apply operations like addition, subtraction, Bitwise Operations, etc.., Let's see how we can perform operations on images.We need the OpenCV module to perform operations on images. Install the OpenCV module using the following command in the terminal or command line.pip install opencv-python==4.1.1.26If you run the above command, you will get the following successful message.Collecting opencv-python==4.1.1.26 Downloading https://files.pythonhosted.org/packages/1f/51/e0b9cef23098bc31c77b0e0 6221dd8d05119b9782d4c2b1d1482e22b5f5e/opencv_python-4.1.1.26-cp37-cp37m-win_amd64.w hl (39.0MB) Requirement already satisfied: numpy>=1.14.5 in c:\users\hafeezulkareem\anaconda3\l ib\site-packages (from opencv-python==4.1.1.26) (1.16.2) Installing collected packages: opencv-python Successfully installed opencv-python-4.1.1.26AdditionWe can add two images using ... Read More
In this tutorial, we are going to write a program that returns two numbers whose ratio is equal to the given float value. We have a method called as_integer_ratio() that helps to achieve our goal.Let's see some examples.Input: 1.5 Output: 3 / 2 Input: 5.3 Output: 5967269506265907 / 1125899906842624Let's examine the code.Example# initializing the float value float_value = 1.5 # getting integers tuple using the as_integer_ratio() method integers = float_value.as_integer_ratio() # printing the integers print(f'{integers[0]} / {integers[1]}')OutputIf you run the above code, you will get the following results.3 / 2 Let's see another example.Example# initializing the float value float_value = ... Read More
In this tutorial, we are going to perform arithmetic operations on images using OpenCV in Python. We need to install the OpenCV module.Run the following command to install the OpenCV module.pip install opencv-python==4.1.1.26If you run the above command, you will get the following successful message.Collecting opencv-python==4.1.1.26 Downloading https://files.pythonhosted.org/packages/1f/51/e0b9cef23098bc31c77b0e0 6221dd8d05119b9782d4c2b1d1482e22b5f5e/opencv_python-4.1.1.26-cp37-cp37m-win_amd64.w hl (39.0MB) Requirement already satisfied: numpy>=1.14.5 in c:\users\hafeezulkareem\anaconda3\l ib\site-packages (from opencv-python==4.1.1.26) (1.16.2) Installing collected packages: opencv-python Successfully installed opencv-python-4.1.1.26Adding Two ImagesWe need two images for the addition. We have a method called cv2.add(image_one, image_two) to perform addition. It's very hand method. The sizes of the two images must be the same. ... Read More
In this tutorial, we are going to work with the audio files. We will breakdown the audio into chunks to recognize the content in it. We will store the content of the audio files in text files as well. Install the following modules using the below commands.pip install pydubIf you run the above command, you will get the following successful messageCollecting pydub Downloading https://files.pythonhosted.org/packages/79/db/eaf620b73a1eec3c8c6f8f5 b0b236a50f9da88ad57802154b7ba7664d0b8/pydub-0.23.1-py2.py3-none-any.whl Installing collected packages: pydub Successfully installed pydub-0.23.1pip install audioreadIf you run the above command, you will get the following successful message.Collecting audioread Downloading https://files.pythonhosted.org/packages/2e/0b/940ea7861e0e9049f09dcfd 72a90c9ae55f697c17c299a323f0148f913d2/audioread-2.1.8.tar.gz Building wheels for collected packages: audioread Building wheel for audioread ... Read More
In this tutorial, we are going to learn about the Barnsley Fern, which is created by Michael Barnsley. The features of Barnsley Fern is similar to the fern shape. It is created by iterating over the four mathematical equations known as Iterated Function System(IFS). The transformation has the following formula.f(x, y)=$$\begin{bmatrix}a & b \c & d \end{bmatrix}\begin{bmatrix}x \y \end{bmatrix}+\begin{bmatrix}e \f \end{bmatrix}$$Source − WikipediaThe values of the variables are −Source − WikipediaThe four equation that Barnsley Fern proposed are −Source − WikipediaNow, we will see code to create the fern shape in Python.Example# importing matplotlib module for the plot import matplotlib.pyplot ... Read More
In this tutorial, we are going to write a solution for a challenge.ChallengeWe have to generate a random set of basic arithmetic operations. The user will give the number of questions, and we have to generate questions. After every question, the user will answer it. At the end of the program, we have to give the score. Let's try it.Example# importing random and operator modules import random import operator # main function # taking number of questions that we have to generate def main(n): print("Welcome to the quizYou should answer floats upto 2 decimals") # initialising score to ... Read More
In this tutorial, we are going to learn about data analysis and visualization using modules like pandas and matplotlib in Python. Python is an excellent fit for the data analysis things. Install the modules pandas and matplotlib using the following commands.pip install pandaspip install matplotlibYou will get a success message after the completion of the installation process. We will first learn about the pandas and then will see matplotlib.pandasPandas is an open-source library of Python which provides data analysis tools. We are going to see some useful methods from the pandas for data analysis.Creating DataFramesWe need multiple rows to create ... Read More
In this tutorial, we are going to learn about automating testing in Python. After writing code, we have to test them by giving different types of input and check whether the code is working correctly or not.We can do it manually or automatically. Doing manual testing is very hard. So, we are going to learn about automated testing in Python. Let's start.We have a module called unittest, which is used to test the code automatically. We are going to work with this module in this tutorial. It's straightforward for a beginner to get started with the unittest module for testing. ... Read More
In this tutorial, we are going to learn about the type and isinstance built-in functions of Python. These functions are used to determine the type of an object in general. Let's see them one by one.type(object)type is used to know the type of an object. For example, if we have an object val with value 5. The type of that object is int. We can get that using the type function. Let's follow the general procedure to achieve the result.Initialize the object.Get the type of the object using type(object) function.Display the type.Below is one example which explains the type(object) function.Example# ... Read More
Here we will see how to find the frequency of smallest element in an array. Suppose the array elements are [5, 3, 6, 9, 3, 7, 5, 8, 3, 12, 3, 10], here smallest element is 3, and the frequency of this element is 4. So output is 4.To solve this we will find the smallest element of the list, then we count the occurrences of first numbers, and that will be the result.Example#include using namespace std; int min_element(int arr[], int n){ int min = arr[0]; for(int i = 1; i
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP