Site icon Machine Learning Projects

Make your Sketch using OpenCV in Python – simplest way – easy project – 2023

Machine Learning Projects

In today’s very short blog we will see that how we can make our sketch using OpenCV in the simplest way possible. This is going to be a very fun project for beginners. So without any further due, Let’s do it…

Code for making a sketch using OpenCV…

import cv2
import numpy as np

def sketch(image):
    gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
    blur_gray = cv2.GaussianBlur(gray,(5,5),900)
    edges = cv2.Canny(blur_gray,45,90)
    ret,thre = cv2.threshold(edges,70,255,cv2.THRESH_BINARY_INV)
    return thre

cam = cv2.VideoCapture(0)

while 1:
    ret,frame = cam.read()
    cv2.imshow('Live Sketch', sketch(frame))
    if cv2.waitKey(1)==27:
        break
    if cv2.waitKey(1)==13:
        cv2.imwrite('sketch.jpg',sketch(frame))
        print('Image Saved!!!')

cam.release()
cv2.destroyAllWindows()

Final result…

Can you guess who is in the sketch?

Download the Source Code…

Do let me know if there’s any query regarding sketch using OpenCV by contacting me by email or LinkedIn.

So this is all for this blog folks, thanks for reading it and I hope you are taking something with you after reading this and till the next time…

Read my previous post: IMMORTAL SNAKE GAME IN PYTHON USING OPENCV

Check out my other machine learning projectsdeep learning projectscomputer vision projectsNLP projectsFlask projects at machinelearningprojects.net.

Exit mobile version