Skip to content

Filter detections by position of bbox coordinates #521

Answered by SkalskiP
yieniggu asked this question in Q&A
Discussion options

You must be logged in to vote

@yieniggu I think it is a perfect use-case for PolygonZone.

  1. Define PolygonZone. I'm using the coordinates you defined above.

    import supervision as sv
    import numpy as np
    
    polygon = np.array([
        [0, height * 0.2],
        [width, height * 0.2)],
        [width, height * 0.7],
        [0, height * 0.7]
    ]).astype(int)
    
    zone = sv.PolygonZone(
        polygon=polygon,
        frame_resolution_wh=(width, height)
    )
  2. Filter detections using zone as a condition. I'm going to assume you are using YOLOv8. Read more about from_ultralytics.

    import supervision as sv
    from ultralytics import YOLO
    
    model = YOLO('yolov8n.pt')
    result = model(image)[0]
    
    detections = sv.Detections.from_ultralytics(result)
    mask = zone.trigger(d…

Replies: 4 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@yieniggu
Comment options

@SkalskiP
Comment options

@yieniggu
Comment options

Answer selected by yieniggu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested
3 participants
Converted from issue

This discussion was converted from issue #491 on October 23, 2023 15:51.