python-opencv获取二值图像轮廓及中心点坐标代码:
groundtruth = cv2.imread(groundtruth_path)[:, :, 0]
h1, w1 = groundtruth.shape
contours, cnt = cv2.findContours(groundtruth.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
if len(contours) != 1:#轮廓总数
continue
M = cv2.moments(contours[0]) # 计算第一条轮廓的各阶矩,字典形式
center
2021-10-01 15:27:14
36KB
c
nc
op
1