더북(TheBook)
import numpy as np

print(widget.bboxes)
box = widget.bboxes[0] 
box = np.array([box['x'], box['y'], box['x'] + box['width'], box['y'] + 
box['height']])
[{'x': 302, 'y': 144, 'width': 593, 'height': 618, 'label': ''}]

그리고 변환한 경계 상자 정보를 사용해 SAM 모델로부터 분할 마스크를 예측하는 과정을 수행합니다.

mask_predictor = SamPredictor(sam)
image_bgr = cv2.imread(IMAGE_NAME)
image_rgb = cv2.cvtColor(image_bgr, cv2.COLOR_BGR2RGB)

mask_predictor.set_image(image_rgb) # ①

masks, scores, logits = mask_predictor.predict(
    box=box,              # ②
    multimask_output=True # ③
)
신간 소식 구독하기
뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.