【问题标题】:Finding contour from depth image从深度图像中寻找轮廓
【发布时间】:2021-06-09 05:55:13
【问题描述】:

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

From depth to grayscale

通过

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)

这没有用。当我做print(countours) 时,我可以看到坐标列表,但它不是由cv2.drawCountours 绘制的。

我哪里错了?

我试图做这样的事情:1:Detect approximately objects on depth map

【问题讨论】:

  • 你显示的图片是cv2.imshow吗?
  • 我们能有完整的代码和原始图像一起玩吗?
  • @stateMachine 是,通过 cv2.imshow
  • @pippo1980 这是相机的输出图像。摄像头是 RealSense D435
  • 是的,我知道,但是缺少导入,并不是我们都有相机,所以要测试您的代码并希望了解有关 pyrealsense2 的任何信息,我需要 ''depth_frame.get_data()'' 来测试您的代码,我理解它是来自套件的流,但在这里我们应该讨论有效的代码,即输入代码输出。很抱歉我的咆哮,但我在尝试理解新事物时感到沮丧

标签: python opencv image-processing opencv-python opencv-contour


【解决方案1】:

尝试从Detect approximately objects on depth map 开始重新创建您的问题;

输入图像:

这是我的代码:

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

【讨论】:

  • 非常感谢 pippo1980 抽出时间试用。我也高度怀疑 cv2.convertScaleAbs。原始深度图像(没有着色是没用的)。我正在尝试使用按位掩码的另一种方法。我会把结果放在这里。
猜你喜欢
  • 1970-01-01
  • 2015-03-10
  • 2019-07-18
  • 2012-01-04
  • 2012-01-16
  • 2022-01-11
  • 1970-01-01
  • 2018-02-21
  • 1970-01-01
相关资源
最近更新 更多