-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcam2display.py
57 lines (42 loc) · 1.52 KB
/
cam2display.py
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
import cv2 # pip install opencv-python
import configuration
import displayprovider
import time
class App:
def __init__(self):
self.cap = cv2.VideoCapture(0)
self.fdd = displayprovider.get_display()
self.fps = 30
def run(self):
while True:
self.draw()
time.sleep(1/self.fps)
def draw(self):
# Capture frame-by-frame
ret, frame = self.cap.read()
# flip frame vertically
frame = cv2.flip(frame, 1)
# Check if frame is captured successfully
if not ret:
print("Failed to capture frame")
resized_frame = cv2.resize(frame, (configuration.WIDTH, configuration.HEIGHT))
# Convert the frame to grayscale
gray_frame = cv2.cvtColor(resized_frame, cv2.COLOR_BGR2GRAY)
# Apply Gaussian blur
gray_frame = cv2.GaussianBlur(gray_frame, (5, 5), 0)
# Apply binary thresholding
_, bw_frame = cv2.threshold(gray_frame, 127, 255, cv2.THRESH_BINARY)
# Iterate over each pixel and send to filipdotdisplay
self.fdd.clear()
for y in range(configuration.HEIGHT):
for x in range(configuration.WIDTH):
pixel_value = bw_frame[y, x]
self.fdd.px(x, y, pixel_value != 0)
self.fdd.show()
# Display the resulting frame
cv2.imshow('Webcam', frame)
# Release the capture and close windows
#cap.release()
#cv2.destroyAllWindows()
if __name__ == "__main__":
App().run()