I have a project where I am implementing the Yolo object detection algorithm with different tracking algorithms. I am now struggling to implement the StrongSort tracking with my detection program. Can someone explain how I should implement the algorithm with the use of a GitHub repo. How can I feed the detection results into the tracking algorithm? This is my detection algorithm:
from ultralytics import YOLO
class YoloDetector:
def __init__(self, model_path, confidence):
self.model = YOLO(model_path)
self.classList = ["person"]
self.confidence = confidence
def detect(self, image):
results = self.model.predict(image, conf=self.confidence)
result = results[0]
detections = self.make_detections(result)
return detections
def make_detections(self, result):
boxes = result.boxes
detections = []
for box in boxes:
x1, y1, x2, y2 = box.xyxy[0]
x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2)
w, h = x2 - x1, y2 - y1
class_number = int(box.cls[0])
if result.names[class_number] not in self.classList:
continue
conf = box.conf[0]
detections.append((([x1, y1, w, h]), class_number, conf))
return detections
I have a project where I am implementing the Yolo object detection algorithm with different tracking algorithms. I am now struggling to implement the StrongSort tracking with my detection program. Can someone explain how I should implement the algorithm with the use of a GitHub repo. How can I feed the detection results into the tracking algorithm? This is my detection algorithm:
from ultralytics import YOLO
class YoloDetector:
def __init__(self, model_path, confidence):
self.model = YOLO(model_path)
self.classList = ["person"]
self.confidence = confidence
def detect(self, image):
results = self.model.predict(image, conf=self.confidence)
result = results[0]
detections = self.make_detections(result)
return detections
def make_detections(self, result):
boxes = result.boxes
detections = []
for box in boxes:
x1, y1, x2, y2 = box.xyxy[0]
x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2)
w, h = x2 - x1, y2 - y1
class_number = int(box.cls[0])
if result.names[class_number] not in self.classList:
continue
conf = box.conf[0]
detections.append((([x1, y1, w, h]), class_number, conf))
return detections
Share
Improve this question
asked Mar 25 at 15:12
ofhgofofhgof
1
1 Answer
Reset to default 0class YoloDetectorWithTracking:
def __init__(self, model_path, confidence):
self.model = YOLO(model_path)
self.classList = ["person"]
self.confidence = confidence
self.tracker = StrongSort()
def detect_and_track(self, image):
detections = self.detect(image)
boxes = np.array([det[0] for det in detections])
scores = np.array([det[2] for det in detections])
tracks = self.tracker.update(boxes, scores, image)
return tracks
def detect(self, image):
results = self.model.predict(image, conf=self.confidence)
result = results[0]
detections = self.make_detections(result)
return detections
def make_detections(self, result):
boxes = result.boxes
detections = []
for box in boxes:
x1, y1, x2, y2 = box.xyxy[0]
x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2)
w, h = x2 - x1, y2 - y1
class_number = int(box.cls[0])
if result.names[class_number] not in self.classList:
continue
conf = box.conf[0]
detections.append((([x1, y1, w, h]), class_number, conf))
return detections
I have added the StrongSort tracker to the YOLO detection class. The YOLO detections (bounding boxes and confidence scores) are passed to the tracker, which updates and returns the tracked objects with IDs. These tracked objects are then visualized with bounding boxes and IDs in the video frames.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744186679a4562236.html
评论列表(0条)