【问题标题】:How to draw contours? python如何绘制轮廓? Python
【发布时间】:2018-07-09 18:02:15
【问题描述】:

我正在尝试在源图像中绘制十个最大的轮廓,但它们没有出现。

import cv2
image_orig=cv2.imread('C:\Users\pc\Desktop\middleeast.jpg')
image_gray=cv2.cvtColor(image_orig,cv2.COLOR_BGR2GRAY)
image_contours=image_orig.copy()
_, image_threshold=cv2.threshold(image_gray,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
_,contours,_=cv2.findContours(image_threshold,cv2.RETR_LIST,cv2.CHAIN_APPROX_NONE)
largest_contours = sorted(contours, key=cv2.contourArea)[-10:]
print len(largest_contours)
for contour in largest_contours:
    print cv2.contourArea(contour)
cv2.drawContours(image_contours, largest_contours, -1, (255,255,0), 3)
cv2.imshow('contours',image_contours)
cv2.waitKey(0)

Source image

【问题讨论】:

  • 你有什么错误吗?
  • @Aaron 没有错误,使用 cv2.drawContours 后轮廓不会出现

标签: python opencv find draw contour


【解决方案1】:

代码运行良好。因为它是一个大图像,你无法看到。在imshow 之前添加此行,您将看到轮廓。

image_contours = cv2.resize(image_contours, None, fx=0.25,fy=0.25 , interpolation = cv2.INTER_CUBIC)

【讨论】:

    猜你喜欢
    • 2021-09-07
    • 1970-01-01
    • 2023-03-20
    • 2019-01-25
    • 1970-01-01
    • 2013-08-16
    • 2020-02-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多