detections = sv.Detections.from_yolov8(yolo_results) detections = detections[detections.confidence > threshold] boxes = detections.xyxy conf = detections.confidence class_ids = detections.class_id results = [] if polygon.shape[0] > 0: for label, score, seg in zip(class_ids, conf, polygon): # 将多边形的点坐标转换为列表形式 points = [[float(coord[0]), float(coord[1])] for coord in seg] results.append({ "confidence": str(score), "label": labels.get(label, "unknown"), "points": points, "type": "polygon",})帮我改
时间: 2024-02-14 07:30:19 浏览: 276
COCO_test-dev2017_detections_AP_H_609_person.json
根据您提供的代码片段,以下是修改后的代码:
```python
detections = sv.Detections.from_yolov8(yolo_results)
detections = detections[detections.confidence > threshold]
boxes = detections.xyxy
conf = detections.confidence
class_ids = detections.class_id
results = []
if polygon.shape[0] > 0:
for label, score, seg in zip(class_ids, conf, polygon):
# 将多边形的点坐标转换为列表形式
points = [[float(coord[0]), float(coord[1])] for coord in seg]
results.append({
"confidence": str(score),
"label": labels.get(label, "unknown"),
"points": points,
"type": "polygon",
})
```
在这个修改后的代码中,将多边形的点坐标转换为列表形式,并将结果添加到 `results` 列表中。每个结果字典包含了置信度、标签、多边形点坐标和类型信息。
请注意,修改后的代码假设 `polygon`、`labels` 和 `threshold` 变量已经在之前的代码中定义或赋值。请确保这些变量的正确性,并根据需要进行调整。
阅读全文