crack detection

@hanminss·2021년 11월 15일
0

Projects

목록 보기
2/2
post-thumbnail

토공과 교수님과 협의로 요구사항을 반영하기 위해 기존 코드를 ver1이라 칭하고 ver2 개발을 시작하였다.

요구사항이 바뀐점은 crack의 테두리의 길이는 이제 marker로 측정하지 않는다. 직접 측정하여 기입하기로 하였다. 이는 개발하는데는 더 편해지고 오차도 많이 줄어들겠지만 지금까지 갈린 시간을 생각하면 너무 아쉽다.

방식은 다음과 같이 사진을 업로드하면 사진을 찍을 때 미리 측정해둔 crack을 기준으로 만든 직사각형의 각 꼭지점을 마우스 클릭으로 좌표를 보낸다. 또한 평탄화 작업과 길이의 비율 변환을 위해 미리 재둔 각 변의 길이도 입력을 하여 back-end로 보내 opencv 처리를 한다.

평탄화를 위한 비율은 높이의 비를 1 이라 하였을 때
1:x = height:width 로 나오기 때문에
가로의 비는 width/height 가 된다. 비율을 이용하여 변환전 사진의 좌표인 네점 pts1과 변환 후 네 점의 예상 좌표 네점을 비율로 계산하여 getPerspectiveTransform를 해주었다.

        pts1 = np.float32([
            [int(top_left[0]),int(top_left[1])],
            [int(top_right[0]),int(top_right[1])],
            [int(bottom_right[0]),int(bottom_right[1])],
            [int(bottom_left[0]),int(bottom_left[1])]
        ])

        pixelWidth = max(np.linalg.norm(pts1[0] - pts1[1]), np.linalg.norm(pts1[2] - pts1[3]))
        pixelHeight = max(np.linalg.norm(pts1[0] - pts1[3]), np.linalg.norm(pts1[1] - pts1[2]))

        width_ratio = width/height
        height_ratio = 1

        pts2 = np.array([
                [0, 0],
                [int(width_ratio*pixelHeight),0],
                [int(width_ratio*pixelHeight), int(height_ratio*pixelHeight)],
                [0, int(height_ratio*pixelHeight)]
        ], dtype=np.float32)

        M = cv2.getPerspectiveTransform(pts1, pts2)
        dst = cv2.warpPerspective(img, M=M, dsize=(int(width_ratio*pixelHeight), int(height_ratio*pixelHeight)))

<좌: 평탄화, 우:원본>

짧은내용이지만 5시간 정도 걸렸던것 같다. 친구들과 live share 를 처음 사용해보며 작업을 하였는데 아주 편리하였다. 자주 애용해야겠다.

0개의 댓글