gpt4 book ai didi

python - 使用 opencv 从二进制图像中分割楔形

转载 作者:太空宇宙 更新时间:2023-11-03 22:38:00 25 4
gpt4 key购买 nike

我有一张黑白图像,如何识别输入图像中标记图像中显示的楔形?

输入图片

Input image

图像上标记的楔子

Wedges marked on image

最佳答案

enter image description here

您可以使用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)

关于python - 使用 opencv 从二进制图像中分割楔形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56600894/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com