简体   繁体   English

从深度图像中寻找轮廓

[英]Finding contour from depth image

I am a newbie in image processing.我是图像处理的新手。 I have a depth image which has been converted to grayscale like below:我有一个已转换为灰度的深度图像,如下所示:

From depth to grayscale从深度到灰度

through通过

depth_image_raw = np.asanyarray(depth_frame.get_data())
to_grayscale = cv2.convertScaleAbs(depth_image_raw, alpha=0.30)
ret, Thresh = cv2.threshold(to_grayscale, 60, 155, 0)
contours, hierarchy = cv2.findContours(Thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(to_grayscale, contours, 0, (0, 0, 255), 2)

which didn't work.这没有用。 When I do print(countours) I can see list of coordinates but it's not drawn by cv2.drawCountours .当我执行print(countours)时,我可以看到坐标列表,但它不是由cv2.drawCountours绘制的。

Where am I going wrong?我哪里错了?

I tried to do something like this: 1 : Detect approximately objects on depth map我试图做这样的事情: 1检测深度 map 上的近似物体

tried to recreate your issues starting from Detect approximately objects on depth map ;尝试从Detect about objects on depth map开始重新创建您的问题;

input image:输入图像:

input_image_from_Detect 近似深度图上的对象-RESIZED

here my code:这是我的代码:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Jun  9 08:20:40 2021

@author: Pietro

https://stackoverflow.com/questions/67898354/finding-contour-from-depth-image


codice non utilizzabile manca import e immagine originale 
"""



import cv2

imagez1 = cv2.imread('1tCjh_resized.png') #from https://stackoverflow.com/questions/38094594/detect-approximately-objects-on-depth-map

print(imagez1.dtype,'   ',imagez1.shape)  

cv2.imshow('pippo',imagez1)
cv2.waitKey(0)
cv2.destroyAllWindows()

imagez = cv2.imread('1tCjh_resized.png', cv2.IMREAD_GRAYSCALE) #from https://stackoverflow.com/questions/38094594/detect-approximately-objects-on-depth-map  

print(imagez.dtype,'   ',imagez.shape)  

cv2.imshow('pippoZ',imagez)
cv2.waitKey(0)
cv2.destroyAllWindows()


ret,th = cv2.threshold(imagez,127,255, 1)


contours, hierarchy = cv2.findContours(th, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

print(contours)
cv2.drawContours(imagez, contours, 0, (0, 0, 255), 2) #black contours
# cv2.drawContours(imagez, contours, 0, (255, 0, 0), 2) #white contours



cv2.imshow('pippoZZ',imagez)
cv2.waitKey(0)
cv2.destroyAllWindows()


my question is: why cv2.drawContours(to_grayscale, contours, 0, (0, 0, 255), 2) specify counturs color (0, 0, 255) when we are talking about grayscale image?我的问题是:当我们谈论灰度图像时,为什么 cv2.drawContours(to_grayscale, contours, 0, (0, 0, 255), 2) 指定计数颜色 (0, 0, 255)?

SO I GUESS THE CULPRIT IS HERE:所以我猜罪魁祸首在这里:

depth_image_raw = np.asanyarray(depth_frame.get_data())
to_grayscale = cv2.convertScaleAbs(depth_image_raw, alpha=0.30)

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

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