IT skill/Python [python] center of gravity (무게중심) 구하기 - 반응형 무게중심 구하기 thresholding은 cv2.threshold 함수를 사용하면 된다. 폐곡선을 여러개 가진 이미지라면 여러개의 무게중심 좌표가 리턴된다. def COG(input_array): """ :param input_array: 반드시 thresholding 된 array여야 함. :return: """ global cx, cy contours, hierarchy = cv2.findContours(input_array, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) for cnt in contours: M = cv2.moments(cnt) cx = int(M['m10']/M['m00']) cy = int(M['m01']/M['m00']) result_cx.append(cx) result_cy.append(cy) return result_cx, result_cy 질량중심 구하기 (scipy.ndimage.center_of_mass) def get_centroid(image): # labeling (8 connectivity) blobs = image > 0 centroid = ndimage.center_of_mass(image) return (int(centroid[0]), int(centroid[1])) 도움이 되셨다면 아무 광고나 클릭 한 번 부탁드립니다👍 반응형 공유하기 URL 복사카카오톡 공유페이스북 공유엑스 공유 게시글 관리 구독하기Beelog 저작자표시 비영리 변경금지 Contents 당신이 좋아할만한 콘텐츠 Pycharm 가상환경 생성하기 2021.02.04 pycharm 에러 : @NotNull method com/intellij/execution/configurations/GeneralCommandLine.getExePath must not return null 2019.12.12 [python] np.percentile 사용법 2019.10.24 [python] np.stack / 여러 영상을 한 이미지의 여러 채널로 합치기(의료영상) 2019.10.10 댓글 0 + 이전 댓글 더보기