forked from Fu-fangteng/Timeline-Video
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPixel Video
More file actions
38 lines (32 loc) · 1.19 KB
/
Copy pathPixel Video
File metadata and controls
38 lines (32 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import cv2
import numpy as np
def pixelate_half_frame(frame, gridSize):
height, width, channels = frame.shape
output = np.copy(frame)
for y in range(0, height, gridSize):
for x in range(0, width , gridSize):
rect = frame[y:y+gridSize, x:x+gridSize]
(b, g, r) = cv2.mean(rect)[:3]
cv2.rectangle(output, (x, y), (x + gridSize, y + gridSize), (b, g, r), -1)
return output
cap = cv2.VideoCapture('Your_Own_Video.mp4')
if not cap.isOpened():
print("Error opening video file")
else:
while True:
ret, frame = cap.read()
if ret:
gridSize = 30
pixelated_frame = pixelate_half_frame(frame, gridSize)
frame_resized = cv2.resize(frame, (640, 480))
pixelated_frame_resized = cv2.resize(pixelated_frame, (640, 480))
cv2.imshow('Original Video', frame_resized)
cv2.imshow('Pixelated Video', pixelated_frame_resized)
cv2.moveWindow('Original Video', 50, 100)
cv2.moveWindow('Pixelated Video', 750, 100)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
cap.release()
cv2.destroyAllWindows()