-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5camera_bitblit.py
68 lines (51 loc) · 1.91 KB
/
5camera_bitblit.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
58
59
60
61
62
63
64
65
66
67
68
import cv2
import numpy as np
import pygame
from skimage.transform import resize
import torch
def get_available_camera_indices(max_check=10):
available_indices = []
for index in range(max_check):
cap = cv2.VideoCapture(index)
ret, _ = cap.read()
if ret:
available_indices.append(index)
cap.release()
return available_indices
def smooth_filter(img_tensor_batch, target_colors, tolerance):
distances = torch.norm(img_tensor_batch * 255 - target_colors[:, None, None, :], dim=-1)
weights = (1 - torch.clamp(distances / tolerance, 0, 1)).unsqueeze(-1)
return img_tensor_batch * weights
camera_indices = get_available_camera_indices()
camera_indices = camera_indices[:5]
caps = [cv2.VideoCapture(index) for index in camera_indices]
color = [(255, 255, 255)] # Default white color
import pygame
from pygame import surfarray
pygame.init()
w = 1280
h = 256
display = pygame.display.set_mode((w, h))
running = True
while running:
x_offset = 0 # to position each camera feed
for cap in caps:
ret, frame = cap.read()
if ret:
# Convert the frame from BGR to RGB (as pygame uses RGB)
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
# Apply any processing here (like smooth_filter)
# For this example, I'm just resizing and displaying
# Resize frame to match the individual camera feed dimensions
frame_resized = cv2.resize(frame_rgb, (256, 256))
# Blit the frame at the correct position
display.blit(surfarray.make_surface(frame_resized), (x_offset, 0))
x_offset += 256 # move the position for the next camera feed
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
break
for cap in caps:
cap.release()
pygame.quit()