36
loading...
This website collects cookies to deliver better user experience
Note: To follow along with this guide, you simply need a basic understanding of how computers function.
import cv2
path = r'C:\Users\folksconnect\Pictures\2020-07'
image_path = cv2.imread(path)
grey_image = cv2.cvtColor(image_path, cv2.COLOR_BGR2GRAY
cv2.imshow('Image', grey_image)
invert = cv2.bitwise_not(grey_img)
blur = cv2.GaussianBlur(invert, (30, 30), cv2.BORDER_DEFAULT)
invertedblur = cv2.bitwise_not(blur)
sketch = cv2.divide(grey_img, invertedblur, scale =256.0)
cv2.imwrite('sketch.png', sketch)
OpenCV
library on your PC after you've successfully installed python on your computer. pip install opencv-python
Note: Any text (variable) at the left hand-side before the assignment symbol ( = ) is used to store information, the statement(code) at the right hand-side is stored into the left hand side.
Ctrl + N
shortcut and this will create a new file.import cv2
OpenCV
library into your Python code, so that you can gain functionalities of all the actions performed by it.r
at the front of the string(path). Here is an example below:path = r'C:\Users\folksconnect\Pictures\2020-07'
image_path = cv2.imread(path)
image_path
. Note if the path or image cannot be read (maybe it does not exist or there is an error in the path) this method returns an empty matrix.
grey_image = cv2.cvtColor(image_path, cv2.COLOR_BGR2GRAY )
cv2.imshow('Image', grey_image)
invert = cv2.bitwise_not(grey_img)
cv2.imshow('image', invert)
blur = cv2.GaussianBlur(invert, (30, 30), cv2.BORDER_DEFAULT)
GaussianBlur()
method is:cv2.GaussianBlur(src, ksize, sigmaX, sigmaY, borderType)
GaussianBlur()
method, you need to pass src
and ksize
values every time and either one, two, or all parameters value from remaining sigmaX
, sigmaY
and borderType
parameter should be passed.sigmaX and sigmaY
parameters become optional if you mention the ksize(kernal size)
value other than (0,0).src
stands for the source file which we've input has invert since we want to work on invert.ksize
value is always in tuple -- i.e. values enclosed in a parenthesis, You can set the value to any range you want depending on your preference.sigmaX
and sigmaX
are optional since ksize
as been setborderType
should also be included, but I love using the default type, so you pass in cv2.BORDER_DEFAULT
invertedblur = cv2.bitwise_not(blur)
sketch = cv2.divide(grey_img, invertedblur, scale =256.0)
cv2.imwrite('sketch.png', sketch)
OpenCV
.import cv2
path = r'C:\Users\folksconnect\Pictures\2020-07'
image_path = cv2.imread(path)
grey_image = cv2.cvtColor(image_path, cv2.COLOR_BGR2GRAY
cv2.imshow('Image', grey_image)
invert = cv2.bitwise_not(grey_img)
blur = cv2.GaussianBlur(invert, (30, 30), cv2.BORDER_DEFAULT)
invertedblur = cv2.bitwise_not(blur)
sketch = cv2.divide(grey_img, invertedblur, scale =256.0)
cv2.imwrite('sketch.png', sketch)
Note: Ensure you change the path of the image to your own path ( the path on your PC) as the above path is a directory to an image on my PC.