fabio-sim / Depth-Anything-ONNX

ONNX-compatible Depth Anything: Unleashing the Power of Large-Scale Unlabeled Data
Apache License 2.0
234 stars 23 forks source link

How to obtain real distances. #5

Closed moruofan11 closed 2 months ago

moruofan11 commented 7 months ago

For an .onnx project, if the output from the model is a relative depth map or pseudo-RGB image, what operations are required to obtain a depth map representing actual distances? There should also be a relationship with the intrinsic parameters of a monocular camera; how should these parameters be reflected?

zoldaten commented 5 months ago

u may went gradient way. i.e. calculate sum of colors in roi in image in compare with white pixel. then check real distance and fix that gradient with real distance.

import cv2; import numpy as np
img = cv2.imread(frame, cv2.IMREAD_GRAYSCALE)
cv2.rectangle(img, (600, 330), (600+90, 330+70), [255, 0, 0], 2) #the center olf image for example
roi = img[330:330+70,600:600+90]
white = (255)
roi_diff=np.sum(cv2.absdiff(roi, white))

snapshot_0_depth