Header Ads Widget

import cv2 import numpy as np def cartoonize_image(img): # Convert to grayscale gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # Apply median blur gray = cv2.medianBlur(gray, 5) # Detect edges edges = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 9, 9) # Convert back to color color = cv2.bilateralFilter(img, 9, 300, 300) # Cartoonize cartoon = cv2.bitwise_and(color, color, mask=edges) return cartoon # Open video file cap = cv2.VideoCapture('input.mp4') frame_count = 0 while(cap.isOpened()): ret, frame = cap.read() if ret == True: # Cartoonize the frame cartoon_frame = cartoonize_image(frame) # Save the cartoon image cv2.imwrite(f'cartoon_frame_{frame_count}.jpg', cartoon_frame) frame_count += 1 else: break # Release the video capture object cap.release()

Post a Comment

0 Comments