Found 10476 Articles for Python

Line detection in python with OpenCV?

Ankith Reddy
Updated on 30-Jul-2019 22:30:26

3K+ Views

In this post, we are going to learn, how to detect lines in an image, with the help of a technique called Hough transform.Hough transform?Hough transform is a feature extraction method to detect any simple shape, if you can represent that shape in mathematical form. It somehow manage to detect the shape even if it is broken or distorted a little bit. We will see how it works for a line.A “simple” shape is one that can be represented by only a few parameters. For example, a line can be represented by two parameters only (slope, intercept) and a circle ... Read More

Packaging and Publishing Python code?

George John
Updated on 30-Jul-2019 22:30:26

270 Views

Python provides a very simple way of creating or publishing packages.Package management in Python is available through different tools−Pip- It remains one of the preferred choices because it virtually eliminates any manual installs and updates of software packages to operating systems. It manages full lists of packages and their corresponding version numbers, which fosters precise duplication of entire package groups in a distinct, separate environment.Python Package Index (PPI) is a public package repository of user-submitted packages that can be installed using pip .i.e. pip install package_name.Below is a step-by-step procedure on how to upload the package.Step 1: Have a package ... Read More

Mouse and keyboard automation using Python?

Chandu yadav
Updated on 30-Jul-2019 22:30:26

2K+ Views

In this section, we’ll try to automate the movements of mouse and keyboard using pyautogui module in python.Pyautogui is a library that allows you to control the mouse and keyboard to do various things.It  is a cross-platform GUI automation Python module for human beings.As it is a third party library, we need to install it.pip install pyautoguiMouseBelow is program to automate the movement of your mouse. On running your programme, you can see the mouse movement with every command. I run below command on CLI so as to capture the mouse movement. You can try with others different values too.Example>>> ... Read More

Using OpenCV in Python to Cartoonize an Image

Arjun Thakur
Updated on 31-Mar-2023 15:38:22

1K+ Views

Currently there are lots of professional cartoonizer applications available in the market but most of the them are not freeware. In order to get the basic cartoon effect, we just need the bilateral filter and some edge dectection mechanism. The bilateral filter will reduce the color palette, which is essential for the cartoon look and edge detection is to produce bold silhouettes.We are going to use openCV python library to convert an RGB color image to a cartoon image.AlgorithmFirstly apply the bilateral filter to reduce the color palette of the image.Then conver the actual image to grayscale.Now apply the median ... Read More

OpenCV Python Program to blur an image?

Ankith Reddy
Updated on 30-Jul-2019 22:30:26

612 Views

OpenCV is one of the best python package for image processing. Also like signals carry noise attached to it, images too contain different types of noise mainly from the source itself (Camera sensor). Python OpenCV package provides ways for image smoothing also called blurring. This is what we are going to do in this section. One of the common technique is using Gaussian filter (Gf) for image blurring. With this, any sharp edges in images are smoothed while minimizing too much blurring.Syntaxcv.GaussianBlur(src,  ksize,  sigmaX[,  dst[,  sigmaY[,  borderType=BORDER_DEFAULT]]] )Where−src – input imagedst – output imageksize – Gaussian kernel size[ height width]. If ksize ... Read More

Permutation and Combination in Python?

Chandu yadav
Updated on 30-Jul-2019 22:30:26

1K+ Views

In this section, we are going to learn how to find permutation and combination of a given sequence using python programming language.One of the key advantage of python over other programming language is that it comes with huge set of libraries with it.We are going to use python inbuilt package to find permutation and combinations of a given sequence.Algorithm to find the Permutation and combinationStep 1 : Import required package. First step is to import the required package, as we are going to use itertools package, so we just import it using.>>> import itertools >>>Step 2: Get all permutation & combination ... Read More

Python program to Rearrange a string so that all same characters become d distance away

Arjun Thakur
Updated on 30-Jul-2019 22:30:26

988 Views

Given a non-empty string str and an integer k , rearrange the string such that the same characters are at least distance k from each other.All input strings are given in lowercase letters. If it is not possible to rearrange the string, return an empty string "".Example 1:str = “tutorialspoint”, k = 3 Answer: “tiotiotalnprsu”The same characters are at least 3 character distance apart.str = "aabbcc", k = 3 Answer: "abcabc" The same characters are at least 3 character distance apart.Example 2str = "aaabc", k = 3 Answer: "" It is not possible to rearrange the string.Example 3:str = "aaadbbcc", k = ... Read More

Python program to Find the first non-repeating character from a stream of characters?

AmitDiwan
Updated on 11-Aug-2022 11:57:47

9K+ Views

In this article, we will find the first non-repeating character from a stream of character. Let’s say the following is our input − Thisisit The following should be our output displaying first non-repeating character − H Find the first non-repeating character from a stream of characters using while loop We will find the first non-repeating character, by comparing each character with the other using a loop − Example # String myStr = "thisisit" # Looping while myStr != "": slen0 = len(myStr) ch = myStr[0] myStr = myStr.replace(ch, "") slen1 = len(myStr) if slen1 == slen0-1: print ... Read More

Python program to Count words in a given string?

Chandu yadav
Updated on 30-Jul-2019 22:30:26

3K+ Views

Lets suppose we have a ‘string’ and the ‘word’ and we need to find the count of occurence of this word in our string using python. This is what we are going to do in this section, count the number of word in a given string and print it.Count the number of words in a given stringMethod 1: Using for loop#Method 1: Using for looptest_stirng = input("String to search is : ") total = 1 for i in range(len(test_stirng)):    if(test_stirng[i] == ' ' or test_stirng == '' or test_stirng == '\t'):       total = total + ... Read More

Increment and Decrement Operators in Python?

Arjun Thakur
Updated on 23-Aug-2023 14:01:38

66K+ Views

Python does not have unary increment/decrement operator (++/--). Instead to increment a value, usea += 1to decrement a value, use −a -= 1Example>>> a = 0 >>> >>> #Increment >>> a +=1 >>> >>> #Decrement >>> a -= 1 >>> >>> #value of a >>> a 0Python does not provide multiple ways to do the same thing .However, be careful if you are coming from a language like C, Python doesn’t have "variables" in the sense that C does, instead python uses names and objects and in python integers (int’s) are immutable.Let’s understand it with an example−>>> a =1 >>> ... Read More

Advertisements