import cv2
import torch
import numpy as np

# Check if CUDA is available and set the default to GPU if possible
#device = 'cuda' if torch.cuda.is_available() else 'cpu'
#print(f'Using device: {device}')

# Load YOLOv5 model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s6')

model.cuda()
# Your supervision library would be used here
import supervision as sv

# Initialize the camera (0 for default camera, 1 for external cameras, and so on)
camera = cv2.VideoCapture(0)

# Define the BoxAnnotator from the supervision library
box_annotator = sv.BoxAnnotator(thickness=4, text_thickness=4, text_scale=2)

# Define the ROI polygon points (clockwise or counter-clockwise)
roi_polygon = np.array([
    [100, 300],  # Point 1 (x1, y1)
    [300, 200],  # Point 2 (x2, y2)
    [400, 400],  # Point 3 (x3, y3)
    [200, 500]   # Point 4 (x4, y4)
], dtype=np.int32)

def create_mask(frame, roi_polygon):
    # Create a black mask with the same dimensions as the frame
    mask = np.zeros_like(frame, dtype=np.uint8)
    
    # Fill the ROI polygon with white color
    cv2.fillPoly(mask, [roi_polygon], (255, 255, 255))
    
    # Mask the frame to only keep ROI and set everything else to black
    frame_roi = cv2.bitwise_and(frame, mask)
    return frame_roi

def live_inference(camera):
    while True:
        # Capture frame-by-frame from camera
        ret, frame = camera.read()
        if not ret:
            print("Failed to grab frame")
            break
        
        # Convert the image from BGR to RGB
        frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)

        # Apply the ROI mask to the frame
        frame_roi = create_mask(frame_rgb, roi_polygon)
        
        # Perform inference on the masked frame
        results = model(frame_roi, size=900)
        detections = sv.Detections.from_yolov5(results)
        
        # Set threshold and class filtering as before
        detections = detections[(detections.class_id == 0) & (detections.confidence > 0.5)]
        
        # Annotate detections on the original frame (not the masked one)
        frame_annotated = box_annotator.annotate(scene=frame_rgb, detections=detections)

        # Draw the ROI polygon on the annotated frame
        cv2.polylines(frame_annotated, [roi_polygon], isClosed=True, color=(0, 255, 0), thickness=3)
        
        # Get the number of detections within the ROI
        num_detections = len(detections)
        
        # Display the number of detected objects on the frame
        text = f"Detections in ROI: {num_detections}"
        cv2.putText(frame_annotated, text, (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2, cv2.LINE_AA)
        
        # Convert the image from RGB to BGR for OpenCV display
        frame_annotated_bgr = cv2.cvtColor(frame_annotated, cv2.COLOR_RGB2BGR)

        # Display the resulting frame
        cv2.imshow('OLOv5 Live Detection', frame_annotated_bgr)
        
        # Break the loop if ‘q’ is pressed
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    # When everything done, release the capture
    camera.release()
    cv2.destroyAllWindows()

# Run the live inference function
live_inference(camera)


please help me display the gridlines on the left hand side when running the inference for the video capture