-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.py
More file actions
65 lines (38 loc) · 1.61 KB
/
Test.py
File metadata and controls
65 lines (38 loc) · 1.61 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import Screenshotwithcursor
import time
import numpy as np
import cv2
import keyboard
if __name__ == "__main__":
# Take screenshot with cursor
screenshot1 = Screenshotwithcursor.take_screenshot_with_cursor()
img1 = np.array(screenshot1)
img1 = cv2.cvtColor(img1, cv2.COLOR_RGB2BGR)
cv2.imwrite('Recordings/firstimage.png',img1)
output_filename = 'Recordings/difference_video.mp4'
fps = 10 # Frames per second
frame_size = (img1.shape[1], img1.shape[0]) # (width, height)
# Create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'mp4v') # Codec for mp4
out = cv2.VideoWriter(output_filename, fourcc, fps, frame_size)
while True:
screenshot2 = Screenshotwithcursor.take_screenshot_with_cursor()
img2 = np.array(screenshot2)
img2 = cv2.cvtColor(img2, cv2.COLOR_RGB2BGR)
color_diff = cv2.absdiff(img1, img2)
gray1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
gray2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
abs_diff = cv2.absdiff(gray1, gray2)
_, mask = cv2.threshold(abs_diff, 30, 255, cv2.THRESH_BINARY)
# Show only differences
diff_image = np.zeros_like(img2)
diff_image[mask > 0] = color_diff[mask > 0]
diff_image = cv2.convertScaleAbs(diff_image, alpha=2.0, beta=50)
out.write(diff_image)
# cv2.imshow('Colored Differences - Press any key to close', diff_image)
img1 = img2
if keyboard.is_pressed('q'):
print("Stopping recording...")
break
out.release()
cv2.destroyAllWindows()