• 카테고리

    질문 & 답변
  • 세부 분야

    컴퓨터 비전

  • 해결 여부

    미해결

detection 된 객체 구별하는 방법

21.07.28 20:03 작성 조회수 81

0

교수님 안녕하세요! TensorFlow Object Detection API를 이용해서 Custom Dateset을 학습시켰습니다.

한가지 궁금한 점이 있어서 질문하게 되었습니다.

첨부된 사진에 현재 2개의 로봇이 detection 됩니다.

이 상태에서 각 로봇마다 id를 지정하고 싶은데, 좋은 방법이 떠오르지 않아 혹시나 아이디어가 있을까 해서요... 

id는 간단히 생각해서 로봇끼리 구별하기 위한 방법입니다!

항상 좋은강의 감사합니다.

답변 1

답변을 작성해보세요.

0

안녕하십니까,

하나의 이미지에 오브젝트별로 id를 붙이고 싶으시다면, Detect된 object들을 시각화하는 loop 코드에 id를 하나씩 증가시켜서 이름을 만들면 되지 않을 까요?

가령 아래 코드라면,

id = 0

for detection in cv_out[0,0,:,:]:
    score = float(detection[2])
    class_id = int(detection[1])
    # detected된 object들의 score가 함수 인자로 들어온 score_threshold 이상만 추출
    if score > score_threshold:
        # detected된 object들은 scale된 기준으로 예측되었으므로 다시 원본 이미지 비율로 계산
        left = detection[3] * cols
        top = detection[4] * rows
        right = detection[5] * cols
        bottom = detection[6] * rows
        # labels_to_names 딕셔너리로 class_id값을 클래스명으로 변경하되 id를 순차적으로 부여.

        caption = "{}: {:.4f}".format(labels_to_names_0[class_id] + str(id), score)
        id += 1

        print(caption)
        #cv2.rectangle()은 인자로 들어온 draw_img에 사각형을 그림. 위치 인자는 반드시 정수형.
        cv2.rectangle(draw_img, (int(left), int(top)), (int(right), int(bottom)), color=green_color, thickness=2)
        cv2.putText(draw_img, caption, (int(left), int(top - 5)), cv2.FONT_HERSHEY_SIMPLEX, 0.4, red_color, 1)