import cv2

# 读取图片
img = cv2.imread('test.jpg')

# 显示图片编号
print('图片编号:', id(img))

# 将图片转为灰度图
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# 查找轮廓
contours, hierarchy = cv2.findContours(gray, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

# 对第1个轮廓用127灰色进行填充
cv2.drawContours(img, contours, 0, (127, 127, 127), -1)

# 显示图片
cv2.imshow('Image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()

其中,假设test.jpg是要处理的图片文件名。

Python OpenCV代码:显示图片编号并填充轮廓

原文地址: https://www.cveoy.top/t/topic/mQaB 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录