You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.0 KiB
33 lines
1.0 KiB
import cv2
|
|
import numpy as np
|
|
from IDataStreamModule import IDataStreamModule
|
|
|
|
|
|
class DataStreamModule(IDataStreamModule):
|
|
|
|
# Method to find available cameras and return their IDs
|
|
def findCameras(self):
|
|
# List to store the IDs of the found cameras
|
|
cameras = []
|
|
# Iterating through all possible camera IDs
|
|
i = 0
|
|
while True:
|
|
cap = cv2.VideoCapture(i)
|
|
if not cap.isOpened():
|
|
# No further cameras found, break the loop
|
|
break
|
|
# Camera found, store ID in the list
|
|
cameras.append(i)
|
|
cap.release()
|
|
i += 1
|
|
# Return the IDs of the found cameras
|
|
return cameras
|
|
|
|
# Method to get the camera stream from a given camera
|
|
def get_camera_stream(self, camera_name):
|
|
cap = cv2.VideoCapture(camera_name)
|
|
while cap.isOpened():
|
|
ret, frame = cap.read()
|
|
# Yield each frame as a numpy array
|
|
yield np.array(frame)
|
|
cap.release()
|
|
|