15 lines
523 B
Python
15 lines
523 B
Python
import numpy as np
|
|
import cv2
|
|
|
|
# 读取图像
|
|
segmentation_result = cv2.imread('origionSeg.png', cv2.IMREAD_GRAYSCALE)
|
|
|
|
# 使用 findContours 函数找到图像中的轮廓
|
|
contours, _ = cv2.findContours(segmentation_result, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
|
|
|
# 遍历每个轮廓,找出边界框的坐标轴
|
|
for i, contour in enumerate(contours):
|
|
# 计算边界框
|
|
x, y, w, h = cv2.boundingRect(contour)
|
|
print(f"区域 {i+1} 的左上角坐标:({x}, {y}),右下角坐标:({x + w}, {y + h})")
|