With OpenCV, you can create a fun real-time sketch effect using your webcam. This effect transforms your video stream into a pencil sketch, giving a hand-drawn look. It’s an exciting project for beginners in computer vision.
Use cv2.VideoCapture(0) to access your primary webcam.
import cv2
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
if not ret:
break
# Convert to grayscale
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Invert the grayscale image
inverted = cv2.bitwise_not(gray)
# Apply Gaussian Blur
blur = cv2.GaussianBlur(inverted, (21, 21), 0)
# Invert the blurred image
inverted_blur = cv2.bitwise_not(blur)
# Create sketch effect
sketch = cv2.divide(gray, inverted_blur, scale=256.0)
cv2.imshow("Real-Time Sketch Effect", sketch)
# Press 'q' to quit
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
✅ In this lesson, you learned how to apply a real-time sketch effect using OpenCV and your webcam.
This project combines grayscale conversion, image inversion, Gaussian blur, and blending to achieve the sketch look.
👉 Next, we’ll explore cartoonifying live video with OpenCV.
