python opencv 라이브러리 질문 드립니다.

조회수 650회
for ii in range (0, numImages):

    # Filename to store plot for each image
    plt_file = '{}{}.png'.format(args['predictions_subfolder'], ii)

    # Ground truth
    gt = (db["labels"][ii].squeeze())*color

    # Define im array
    im = (np.zeros(db["images"][ii].shape)).astype('uint8')  // 원본 이미지
    im[:,:,0] = (db["images"][ii][:,:,2] * 255) .astype('uint8') 
    im[:,:,1] = (db["images"][ii][:,:,1] * 255) .astype('uint8') 
    im[:,:,2] = (db["images"][ii][:,:,0] * 255) .astype('uint8')

    img = np.reshape(im[:,:,1],(224,224,1))
    #print(img.shape)
    #img = cv.imread((db["images"][ii][:,:,1] * 255) .astype('int32'))

    #print(img.shape)
    #image_ori = np.reshape((np.zeros(db["images"][ii].shape)).astype('int32'),(

    ret, thr = cv.threshold(img, 127, 255, 0)
    contours, hierarchy = cv.findContours(thr, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)
    sortt = sorted(contours, key=cv.contourArea, reverse=True)
    #print(sortt)
    for cnt in sortt:
        x, y, w, h = cv.boundingRect(cnt)
        cv.rectangle(im, (w, y), (w + x, h + y), (0, 255, 255), 5)
        #print(im)
        cv.imwrite('output/bbox/[box]'+ cnt + '.png', im)

딥러닝 모델을 사용하여 원본 이미지와 mask 이미지 그리고 예측이미지를 뽑아내고 있는 코드 일부입니다.

여기서 제가 질문 드리는 것은 mask이미지를 contour 하여 원본이미지에 bounding box를 쳐서 이미지를 저장하려고 하는데요. 제가 코드를 구성한 부분으로는 문제 없이 될 것으로 예상했으나, 여러가지 오류가 발생하고 있습니다.( shape 차원 수, signature matching types error 등등) 혹시 위 설명처럼 bounding box를 생성할 수있는 방법에 대해서 도움을 받았으면 합니다.

감사합니다.

  • (•́ ✖ •̀)
    알 수 없는 사용자

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)