Skip to content

Instantly share code, notes, and snippets.

@felipebastosweb
Created June 8, 2025 04:08
Show Gist options
  • Save felipebastosweb/96076a91891736a01c8d1a2688b1da35 to your computer and use it in GitHub Desktop.
Save felipebastosweb/96076a91891736a01c8d1a2688b1da35 to your computer and use it in GitHub Desktop.
Exibir várias cameras na mesma janela usando opencv
import cv2
import numpy as np
# Camera indices
camera_indices = [0, 1]
# Create capture objects
cameras = [cv2.VideoCapture(index) for index in camera_indices]
while True:
frames = []
all_frames_valid = True
for camera in cameras:
ret, frame = camera.read()
if not ret:
all_frames_valid = False
break
frames.append(frame)
if not all_frames_valid:
print("Error reading from cameras. Exiting...")
break
# Resize frames to the same size (optional)
resized_frames = []
for frame in frames:
resized_frames.append(cv2.resize(frame, (320, 240)))
# Combine frames horizontally
combined_frame = np.concatenate(resized_frames, axis=1)
# Display the combined frame
cv2.imshow("Combined Cameras", combined_frame)
if cv2.waitKey(1) & 0xFF == ord("q"):
break
# Release resources
for camera in cameras:
camera.release()
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment