다음은 이미지를 위젯에 불러오고 사용자의 조작을 통해 경계 상자를 그립니다.
import base64
def encode_image(filepath): # ①
with open(filepath, 'rb') as f:
image_bytes = f.read()
encoded = str(base64.b64encode(image_bytes), 'utf-8')
return "data:image/jpg;base64,"+encoded
from google.colab import output # ②
output.enable_custom_widget_manager() # ③
from jupyter_bbox_widget import BBoxWidget
widget = BBoxWidget() # ④
widget.image = encode_image(IMAGE_NAME)
widget