[英]Finding contour from depth image
我是圖像處理的新手。 我有一個已轉換為灰度的深度圖像,如下所示:
通過
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 : 檢測深度 map 上的近似物體
嘗試從Detect about 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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.