Python 从深度图像中寻找轮廓

Python 从深度图像中寻找轮廓,python,opencv,image-processing,opencv-python,opencv-contour,Python,Opencv,Image Processing,Opencv Python,Opencv Contour,我是图像处理的新手。我有一个深度图像,已转换为灰度,如下所示: 通过 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(T

我是图像处理的新手。我有一个深度图像,已转换为灰度,如下所示:

通过

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)
这没用。当我执行
打印(countours)
时,我可以看到坐标列表,但它不是由
cv2.drawCountours绘制的

我哪里做错了


我试着这样做::

试着从开始重新创建您的问题

输入图像:

这是我的代码:

#!/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()


我的问题是:当我们谈论灰度图像时,为什么cv2.drawContours(为了灰度,轮廓,0,(0,0,255),2)指定颜色(0,0,255)

所以我想罪魁祸首就在这里:

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

您是否使用cv2.imshow来显示图像?我们是否可以使用原始图像的完整代码来播放?@stateMachine是通过cv2。imshow@pippo1980这是相机的输出图像。摄像头是RealSense D435是的,我知道,但是缺少导入,而且并不是我们都有摄像头,所以为了测试您的代码并希望了解关于pyrealsense2的任何内容,我需要“depth_frame.get_data()”来测试您的代码,我知道它是来自套件的流,但这里我们应该讨论工作的代码,即输入代码输出。很抱歉我的咆哮,但我在尝试理解新事物时感到沮丧。非常感谢你花时间尝试。我也高度怀疑cv2.2的可转换性。原始深度图像(未着色的图像无效)。我正在尝试另一种使用位屏蔽的方法。我会把结果放在这里。