具有不同颜色和不同线条样式的python轮廓

问题描述 投票:-2回答:1

我有两个甜甜圈形状的图像。两者看起来相同但有些不同。我想用不同的颜色显示轮廓相同的外圈和内圈,并为另一张图片显示点状曲线。然后将两张图片叠加为一张图像。我已经走了.....请帮助

import numpy as np
import cv2
import matplotlib.pyplot as plt


image = cv2.imread('donut.png')
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
im, contours, hierarchy = cv2.findContours(gray_image, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
cv2.drawContours(image, contours, 0, (0, 255, 0), 2)
plt.imshow(image, cmap="gray")
plt.show()

enter image description here

python image opencv contour opencv-contour
1个回答
1
投票

这是您想要的吗?

enter image description here

import cv2
import matplotlib.pyplot as plt

image = cv2.imread('E:/1/12.jpg',1)
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
contours, hierarchy = cv2.findContours(gray_image, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_NONE)

for i in range(len(contours)):
    cv2.drawContours(image, contours,i, ((i+1)*128, 0, 0), 2)

plt.imshow(image, cmap="gray")
plt.show()
© www.soinside.com 2019 - 2024. All rights reserved.