繁体   English   中英

opencv:如何在单个深度图像中找到轮廓?

[英]opencv: how to find contours in a single depth image?

尝试在单个深度图像中查找轮廓时出现以下错误。 我已经有一个深度 img,我相信我不需要使用cv.cvtcolor

img = np.random.rand(224,224)
img.astype('uint8')
threshold_value = int(np.max(img) * 0.2)
print(threshold_value)
_, img = cv.threshold(img, threshold_value, 255, cv.THRESH_BINARY)
plt.imshow(img)
plt.show()
_, contours, _ = cv.findContours(img,
                                    cv.RETR_TREE, cv.CHAIN_APPROX_SIMPLE)
plt.imshow(img)
plt.show()

错误:

FindContours 仅在模式 != CV_RETR_FLOODFILL 时支持 CV_8UC1 图像,否则仅在函数 'cvStartFindContours_Impl' 中支持 CV_32SC1 图像

img.astype('uint8')

什么也没做。 您应该将结果分配给某些内容,例如:

img = img.astype('uint8')

那么你不会得到你描述的错误。

但结果仍然不会像您预期的那样,因为np.random.rand()分配范围 (0..1) 内的值,并且通过将它们转换为uint8一切都变为零。 可能也想修复那个部分。

8UC1 表示 8 位像素,因此尝试使用将图像转换为灰度。

您应该首先转换值,使值最多为 255。然后,您应该转换类型。 像这样的东西:

img = np.random.rand(224,224)
# Take values from 0-1 to 0-255
img *= 255
# Convert type
img = img.astype('uint8')
(...)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM