-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestground.py
48 lines (33 loc) · 1.17 KB
/
testground.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
ip = '128.61.117.190'
import pygame
import cv2
import numpy as np
pygame.init()
pygame.display.set_caption("Camera Braille Translation")
surface = pygame.display.set_mode([1280, 720])
cap = cv2.VideoCapture(1)
# cap = cv2.VideoCapture('http://'+ip+':4747/mjpegfeed')
# fps = cap.get(cv2.CAP_PROP_FPS)
# print("fps:", fps)
# cap.set(cv2.CAP_PROP_FPS, 60)
while True:
try:
success, frame = cap.read()
if not success:
print("not success")
# for some reasons the frames apear inverted
frame = np.fliplr(frame)
frame = np.rot90(frame)
# The video uses BGR colors and pygame likes RGB
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
surf = pygame.surfarray.make_surface(frame)
# for event in pygame.event.get():
# if event.type == pygame.KEYUP:
# background_color = 'red'
# surface.fill(background_color)
# pygame.display.update()
# # show the surface
surface.blit(surf, (0,0))
pygame.display.flip()
except Exception: pass
# https://stackoverflow.com/questions/59948996/how-to-use-webcam-as-a-screen-of-pygame