Please fix and improve the code so the mediapipe tracking stays continuous with the selected object, right now it stays in one spot and does not move: import torch
from transformers import CLIPSegProcessor, CLIPSegForImageSegmentation
from PIL import Image
import numpy as np
import cv2
import mediapipe as mp

# Initialize MediaPipe
mp_tracking = mp.solutions.objectron
mp_drawing = mp.solutions.drawing_utils

# Load CLIPSeg model and processor
processor = CLIPSegProcessor.from_pretrained("CIDAS/clipseg-rd64-refined")
model = CLIPSegForImageSegmentation.from_pretrained("CIDAS/clipseg-rd64-refined").eval()

device = 'cuda' if torch.cuda.is_available() else 'cpu'
model.to(device)

# Get the object to track from the user
object_to_track = input("Enter the object to track: ")

# Initialize video capture
cap = cv2.VideoCapture(0)

# Initialize variables
confirmed = False
bounding_box = None

# Initialize MediaPipe tracker
tracker = mp_tracking.Objectron(
    static_image_mode=False,
    max_num_objects=1,
    min_detection_confidence=0.5,
    min_tracking_confidence=0.5,
    model_name='Cup'
)

try:
    while True:
        ret, frame = cap.read()
        if not ret:
            break

        frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)

        if not confirmed:
            # CLIPSeg detection mode
            pil_image = Image.fromarray(frame_rgb)

            inputs = processor(
                images=pil_image,
                text=[object_to_track],
                padding="max_length",
                return_tensors="pt"
            ).to(device)

            with torch.no_grad():
                outputs = model(**inputs)
                logits = outputs.logits

            mask = torch.sigmoid(logits).squeeze().cpu().numpy()
            mask = cv2.resize(mask, (frame.shape[1], frame.shape[0]))
            mask_uint8 = (mask * 255).astype(np.uint8)

            colored_mask = cv2.applyColorMap(mask_uint8, cv2.COLORMAP_JET)
            alpha = 0.5
            overlayed_frame = cv2.addWeighted(frame, 1, colored_mask, alpha, 0)

            contours, _ = cv2.findContours(mask_uint8, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

            cv2.putText(overlayed_frame, "Press 'c' to confirm object", (10, 30),
                        cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255), 2)

            cv2.imshow('Dynamic Object Tracker', overlayed_frame)

        else:
            # MediaPipe tracking mode
            frame.flags.writeable = False
            tracking_result = tracker.process(frame_rgb)
            frame.flags.writeable = True

            if bounding_box:
                x, y, w, h = bounding_box
                cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)

            if tracking_result.detected_objects:
                for detection in tracking_result.detected_objects:
                    bbox = detection.location_data.bounding_box
                    h, w, _ = frame.shape
                    x = int(bbox.xmin * w)
                    y = int(bbox.ymin * h)
                    width = int(bbox.width * w)
                    height = int(bbox.height * h)

                    # Update bounding box
                    bounding_box = (x, y, width, height)

                    # Draw bounding box
                    cv2.rectangle(frame, (x, y), (x + width, y + height), (0, 255, 0), 2)

                    # Draw center point
                    center_x = x + width // 2
                    center_y = y + height // 2
                    cv2.circle(frame, (center_x, center_y), 4, (0, 255, 0), -1)

                    # Display tracking confidence
                    confidence = f"Confidence: {detection.score[0]:.2f}"
                    cv2.putText(frame, confidence, (x, y - 10),
                                cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)

            cv2.putText(frame, "Press 'r' to redetect, 'q' to quit", (10, 30),
                        cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255), 2)

            cv2.imshow('Dynamic Object Tracker', frame)

        key = cv2.waitKey(1) & 0xFF
        if key == ord('c'):
            if contours:
                largest_contour = max(contours, key=cv2.contourArea)
                if cv2.contourArea(largest_contour) > 500:
                    x, y, w, h = cv2.boundingRect(largest_contour)
                    bounding_box = (x, y, w, h)
                    confirmed = True
        elif key == ord('r'):
            confirmed = False
            bounding_box = None
            tracker = mp_tracking.Objectron(
                static_image_mode=False,
                max_num_objects=1,
                min_detection_confidence=0.5,
                min_tracking_confidence=0.5,
                model_name='Cup'
            )
        elif key == ord('q'):
            break
finally:
    cap.release()
    cv2.destroyAllWindows()