import cv2
def cartoonize_video():
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
if not ret:
break
# Apply bilateral filter to reduce noise while preserving edges
filtered = cv2.bilateralFilter(frame, 9, 250, 250)
# Apply color quantization to reduce the number of colors
# in the image, giving it a cartoonish appearance
quantized = cv2.cvtColor(filtered, cv2.COLOR_BGR2RGB)
quantized = cv2.resize(quantized, (32, 32), interpolation = cv2.INTER_AREA)
quantized = cv2.resize(quantized, frame.shape[:2][::-1], interpolation = cv2.INTER_NEAREST)