2024-09-30 06:16:36 发布
网友
我有一个黑白图像,我该如何识别输入图像中的楔子,如标记的图像所示?你知道吗
输入图像
图像上标记的楔块
可以使用findContours()来检测边界框和轮廓
findContours()
import cv2 import numpy as np image = cv2.imread('2.png') gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # Find contours cnts = cv2.findContours(gray, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) cnts = cnts[0] if len(cnts) == 2 else cnts[1] for c in cnts: cv2.drawContours(image,[c], 0, (0,255,0), 2) cv2.imshow('image', image) cv2.imwrite('image.png', image) cv2.waitKey(0)
可以使用
findContours()
来检测边界框和轮廓相关问题 更多 >
编程相关推荐