Skip to content

HorizonRoboticsInternal/grounded_sam2

 
 

Repository files navigation

Realtime SAM2.1 + Grounding DINO

To install and compile, simply run

./install.sh

To use SAM2.1 + Grounding Dino, users can use the GroundedSAM2Predictor class as shown below. A demo can be run by running grounded_sam2/inference.py.

import cv2
from grounded_sam2.inference import GroundedSAM2Predictor

gsam_predictor = GroundedSAM2Predictor()

cap = cv2.VideoCapture("your_video.mp4")

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

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

    # Language commands should be in the format of "class1, class2, class3"
    language = "yellow circle, light blue square, red square"

    masks = gsam_predictor.query(frame, language, display=(938, 532))

    key = "yellow circle"
    cv2.imshow(key, masks[key])
    cv2.waitKey(1)

cap.release()

About

Run Segment Anything Model 2 on a live video stream

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 88.3%
  • Cuda 10.0%
  • Other 1.7%