Found 10784 Articles for Python

Addition and Blending of images using OpenCv in Python

Samual Sam
Updated on 30-Jul-2019 22:30:23

342 Views

We know that when we solve any image related problem, we have to take a matrix. The matrix content will vary depending upon the image type - either it would be a binary image(0, 1), gray scale image(0-255) or RGB image(255 255 255). So if we want to add of two images then that means very simple we have to add respective two matrices. In OpenCV library, we have a function cv2.add() to add the images. But for image addition the size of the two images should be same. Addition of two images import cv2 # Readingour Image1 my_firstpic ... Read More

Histograms Equalization using Python OpenCv Module

Samual Sam
Updated on 30-Jul-2019 22:30:23

559 Views

This is a method in image processing to do contrast adjustment using the image's histogram. Actually this method usually increases the global contrast of many images, especially when the usable data of the image is represented by close contrast values and through this adjustment, the intensities can be better distributed on the histogram and it allows for areas of lower local contrast to gain a higher contrast. OpenCV has a function to do this, cv2.equalizeHist() and its input is just grayscale image and output is our histogram equalized image. This technique is good when histogram of the image is confined ... Read More

Dunder or magic methods in python

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

364 Views

magic methods that allow us to do some pretty neat tricks in object oriented programming. These methods are identified by a two underscores (__) used as prefix and suffix. As example, function as interceptors that are automatically called when certain conditions are met. In python __repr__ is a built-in function used to compute the "official" string representation of an object, while __str__ is a built-in function that computes the "informal" string representations of an object. Example Code Live Demo class String: # magic method to initiate object def __init__(self, string): ... Read More

Reading an image using Python OpenCv module

Samual Sam
Updated on 30-Jul-2019 22:30:23

2K+ Views

In OpenCv module, we can use the function cv2.imread() to read an image. When inputting the image path, the image should be in the working directory or a full path of image should be given. cv2.IMREAD_COLOR − This function loads a color image and any transparency of image will be neglected. It is the default flag. cv2.IMREAD_GRAYSCALE − This function loads image in grayscale mode cv2.IMREAD_UNCHANGED − This function loads image as such including alpha channel Source Image Example import numpy as np import cv2 my_img = cv2.imread('C:/Users/TP/Desktop/poor/poverty_india.jpg', 0) cv2.imshow('image', my_img) k = cv2.waitKey(0) & 0xFF # wait ... Read More

Draw geometric shapes on images using Python OpenCv module

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

2K+ Views

The basic operations of OpenCV is to draw over images. The ability to add different geometric shapes just like lines, circles and rectangle etc. Often working with image analysis, we want to highlight a portion of the image, for example by adding a rectangle that defines that portion. Also as example an arrow to indicate something. cv2.line() − This function is used to draw line on an image. cv2.rectangle() − This function is used to draw rectangle on an image. cv2.circle() − This function is used to draw circle on an image. cv2.putText() − This function is used to write ... Read More

Rename multiple files using Python

AmitDiwan
Updated on 24-Aug-2023 14:24:44

48K+ Views

To rename files in Python, use the rename() method of the os module. The parameters of the rename() method are the source_address (old name) and the destination_address (new name). Install and Import the OS module To install the OS module − pip install os To import − import os Rename multiple files using rename() method The rename() method can be easily used to rename multiple files − Example import os # Function to rename multiple files def main(): i = 0 path="E:/amit/" for filename in os.listdir(path): my_dest ="new" + str(i) + ".jpg" my_source =path + filename my_dest =path ... Read More

Color game using Tkinter in Python

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

1K+ Views

For developing GUI applications tkinter is very popular and easy. Using tkinter easily develop GUI games. Here also we are trying to develop color game. In this game the player has to enter color of the word that appears on the screen and hence the score increases by one, the total time to play this game is 30 seconds and colors used in this game are Red, Blue, Green, Pink, Black, Yellow, Orange, White, Purple and Brown. The interface will display name of different colors in different colors. User has to identify the color and enter the correct color name ... Read More

Fetching top news using news API in Python

Samual Sam
Updated on 30-Jul-2019 22:30:23

571 Views

News API is very famous API for searching and fetching news articles from any web site, using this API anyone can fetch top 10 heading line of news from any web site. But using this API, one thing is required which is the API key. Example Code import requests def Topnews(): # BBC news api my_api_key="Api_number” my_url = = " https://newsapi.org/v1/articles?source=bbc-news&sortBy=top&apiKey=my_api_key" my_open_bbc_page = requests.get(my_url).json() my_article = my_open_bbc_page["articles"] my_results = [] for ar in my_article: ... Read More

Minkowski distance in Python

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

1K+ Views

The Minkowski distance is a metric and in a normed vector space, the result is Minkowski inequality. Minkowski distance is used for distance similarity of vector. scipy.spatial.distance.minkowski >>> from scipy.spatial import distance >>> distance.minkowski([1, 0, 0], [0, 1, 0], 1) 2.0 >>> distance.minkowski([1, 0, 0], [0, 1, 0], 2) 1.4142135623730951 >>> distance.minkowski([1, 0, 0], [0, 1, 0], 3) 1.2599210498948732 >>> distance.minkowski([1, 1, 0], [0, 1, 0], 1) 1.0 >>> distance.minkowski([1, 1, 0], [0, 1, 0], 2) 1.0 >>> distance.minkowski([1, 1, 0], [0, 1, 0], 3) 1.0 Example code from math import * from decimal import Decimal ... Read More

Python Program to crawl a web page and get most frequent words

Samual Sam
Updated on 30-Jul-2019 22:30:23

365 Views

Our task is to crawl a web page and count the frequency of the word. And ultimately retrieving most frequent words. First we are using request and beautiful soup module and with the help of these module creating web-crawler and extract data from web page and store in a list. Example code import requests from bs4 import BeautifulSoup import operator from collections import Counter def my_start(url): my_wordlist = [] my_source_code = requests.get(url).text my_soup = BeautifulSoup(my_source_code, 'html.parser') for each_text in my_soup.findAll('div', {'class':'entry-content'}): ... Read More

Advertisements