【问题标题】:drawcontours on different position在不同位置绘制轮廓
【发布时间】:2019-06-29 06:43:12
【问题描述】:

我想在空白图像的中间绘制轮廓。我不知道如何设置要绘制的轮廓位置。这是我使用的线。

cv2.drawContours(bimg, c, -1, 255, 1)

bimg 是空白图像,c 是我从图像中提取的轮廓。我相信我可以通过操纵c来移动轮廓,但是我不明白c实际上是怎么写的

【问题讨论】:

  • 好吧,如果你看opencv documentation,你会看到c是一个二维点的列表,所以你可以使用这些点在图像的中心绘制轮廓

标签: python opencv image-processing opencv-drawcontour


【解决方案1】:

contours可以看opencv的官方文档。此代码可用于查找图像阈值的轮廓并将其绘制在红色的白色背景上。

img = cv2.imread('image_name.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
_,thresh1 = cv2.threshold(img,127,255,cv2.THRESH_BINARY)
_, cnts, _ = cv2.findContours(mask,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
bgr = np.ones((img.shape[0], img.shape[1]), dtype= 'uint8')*255 #this creates a white background of the same size of input shape
cv2.drawContours(bgr, cnts, -1, (0,0,255), 1)

【讨论】:

    猜你喜欢
    • 2021-09-07
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 2019-01-25
    • 2016-05-13
    • 1970-01-01
    • 2019-01-24
    • 2018-07-09
    相关资源
    最近更新 更多