【问题标题】:How to convert pyplot.contour(..) to opencv equivalent?如何将 pyplot.contour(..) 转换为等效的 opencv?
【发布时间】:2018-06-28 02:44:20
【问题描述】:

我有一张这样的图片:(original.png)

人体检测结果如下:(detection.png)

并使用打击代码:

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

original  = cv2.imread('original.png')
detections = cv2.imread('detection.png')
fig = plt.figure(figsize=[12,12])
plt.imshow( original[:,:,::-1] )
plt.contour( detections[:,:,1]/256.,10, linewidths = 1 )
plt.contour( detections[:,:,2]/256.,10, linewidths = 1 )
plt.axis('off') ;
plt.show()

会生成这样的图像: 我试图转换这个:

plt.contour( detections[:,:,1]/256.,10, linewidths = 1 )

相当于opencv:

_, contours, _ = cv2.findContours(detections,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)

各种组合

retrieve mode + approximation method

但都没有给出预期的结果,那么如何解决这个问题?

【问题讨论】:

  • 您能否标记为已解决或说明未解决的原因?

标签: matplotlib opencv-contour


【解决方案1】:

OpenCv findcontours 需要一个黑白图像。

试试:

_, thresh = cv2.threshold(detections[:,:,1], 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)

_, contours, _ = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)

【讨论】:

    猜你喜欢
    • 2012-12-23
    • 2017-02-14
    • 2019-01-09
    • 2018-12-07
    • 2014-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-11
    相关资源
    最近更新 更多