File size: 1,611 Bytes
2e32a69 2d3fe4d 2e32a69 2d3fe4d 2e32a69 2d3fe4d 2e32a69 2d3fe4d 2e32a69 2d3fe4d 2e32a69 2d3fe4d 2e32a69 2d3fe4d 2e32a69 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | #!/usr/bin/env python3
"""VisDrone YOLOv26s 检测示例。
用法:
python example.py --model ../models/model.axmodel --image ../demo/demo_00.jpg
"""
import argparse
import sys
import cv2
from visdrone_yolov26s_sdk import VisDroneYOLODetector
from visdrone_yolov26s_sdk.preprocess import preprocess_image
from visdrone_yolov26s_sdk.postprocess import draw_detections
def main():
parser = argparse.ArgumentParser(description="VisDrone YOLOv26s Detection Demo")
parser.add_argument("--model", required=True, help="Path to model.axmodel")
parser.add_argument("--image", required=True, help="Path to input image")
parser.add_argument("--threshold", type=float, default=0.25, help="Detection threshold")
parser.add_argument("--output", default="result.jpg", help="Output image path")
args = parser.parse_args()
print(f"Loading image: {args.image}")
img_rgb = preprocess_image(args.image, target_size=640)
print(f"Loading model: {args.model}")
detector = VisDroneYOLODetector(
model_path=args.model,
num_classes=10,
threshold=args.threshold,
)
print("Running detection...")
objects = detector.detect(img_rgb)
print(f"Found {len(objects)} objects")
img_bgr = cv2.cvtColor(img_rgb, cv2.COLOR_RGB2BGR)
draw_detections(img_bgr, objects, threshold=args.threshold)
cv2.imwrite(args.output, img_bgr)
print(f"Result saved to: {args.output}")
for obj in objects:
if obj.score >= args.threshold:
print(f" [{obj.label}] {obj.score:.3f} box={obj.box}")
if __name__ == "__main__":
main()
|