class betterDepth(): lastResult = 0.0 maxDistance = 0 def __init__(self,maxDistante : int = 1000): self.maxDistante = maxDistante def getProperDepth(self,vListe : list) -> float: def checkList(ele): if ele > 400 and ele < self.maxDistante: return True return False self.lastResult = 0.0 vNewListe = list(filter(checkList, vListe)) #Filter the list before we use it for i,val in enumerate(vNewListe): self.lastResult += val self.lastResult = self.lastResult / len(vNewListe) return self.lastResult #Pass the depthimage that has already been converted and the depth point x, y #The idea here is that one depth point is not enough so we use the 9 most adjacent points def wDepthImage(self, cv_depth_image : list, dX : int, dY : int) -> float: vDepthPoints = [] for z in range(0, 8): vDepthPoints.append(cv_depth_image[dX - 4 + z][dY - 4 + z]) self.getProperDepth(vDepthPoints) return self.lastResult vListe = [1,500,600,500,600,450,650,1999] bD = betterDepth() mmDepth = bD.getProperDepth(vListe) print(mmDepth)