基于open的二值图像楔块分割

2024-09-30 06:16:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个黑白图像,我该如何识别输入图像中的楔子,如标记的图像所示?你知道吗

输入图像

Input image

图像上标记的楔块

Wedges marked on image


Tags: 标记图像楔子楔块
1条回答
网友
1楼 · 发布于 2024-09-30 06:16:36

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)

相关问题 更多 >

    热门问题