Multi-Target Multi-Camera Tracking

215 views Asked by At

Hello everyone If anyone knows how to connect multiple cameras for object detection. Please tell me how to do this

The screenshot shows 4 cameras that were combined into one server, objects are tracked.

Need to connect several cameras and track each object and assign its own identification number; if from one camera it hits another camera, then the identification number must remain, as shown in the screen.

Please anyone who has experience or open source code or links please share

enter image description here


VIDEO_PATH = "C:/Users/winston/Downloads/"
camera_sources = [
    VIDEO_PATH+"1.mp4", VIDEO_PATH+"2.mp4", VIDEO_PATH+"3.mp4", VIDEO_PATH+"4.mp4"
]
cameras = [cv2.VideoCapture(source) for source in camera_sources]

# Set the desired canvas size (in this case, a 1280x720 frame)
canvas_width, canvas_height = 720,960

detect = Detect('yolov8s')

while True:
    frames = [camera.read()[1] for camera in cameras]

    # Create an empty canvas with the desired size
    canvas = np.zeros((canvas_height, canvas_width, 3), dtype=np.uint8)

    # Calculate the width and height for each camera feed based on the canvas size
    frame_width = canvas_width // 2
    frame_height = canvas_height // 2

    # Arrange frames in a 2x2 grid on the canvas (adjust layout as needed)
    for i, frame in enumerate(frames):
        detect.detect(frame)
        x = (i % 2) * frame_width
        y = (i // 2) * frame_height

        # Resize each frame to fit within its allocated space while maintaining the aspect ratio
        aspect_ratio = frame.shape[1] / frame.shape[0]
        if aspect_ratio > 1:  # Wider frame
            new_width = frame_width
            new_height = int(new_width / aspect_ratio)
        else:  # Taller frame or square frame
            new_height = frame_height
            new_width = int(new_height * aspect_ratio)

        # Resize the frame
        resized_frame = cv2.resize(frame, (new_width, new_height))

        # Paste the resized frame onto the canvas
        canvas[y:y + new_height, x:x + new_width] = resized_frame

    # Display the canvas with all camera feeds
    cv2.imshow("Multi-Camera View", canvas)

    # Handle user input and exit conditions (e.g., pressing 'q')
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# Release video capture objects and close windows
for camera in cameras:
    camera.release()
cv2.destroyAllWindows()
0

There are 0 answers