Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions unit-tests/live/frames/test-depth.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
DEBUG_MODE = False

# Defines how far in cm do pixels have to be, to be considered in a different distance
# for example, 10 for 10cm, will define the range 100-109 cm as one (as 100)
DETAIL_LEVEL = 10
FRAMES_TO_CHECK = 30
# for example, 5 for 5cm, will define the range 100-104 cm as one (as 100)
DETAIL_LEVEL = 5
BLACK_PIXEL_THRESHOLD = 0.8 # Fail if more than 80% pixels are zero
DEPTH_PERCENTAGE = 0.5 # Percentage of pixels that need to have different values to be considered meaningful
FRAMES_TO_CHECK = 30 # Number of frames to check for meaningful depth

dev, ctx = test.find_first_device_or_exit()
tw.start_wrapper( dev )
Expand Down Expand Up @@ -125,14 +127,23 @@ def is_depth_meaningful(save_image=False, show_image=False):
log.e("Error getting color frame")

dists, total = get_distances(depth)

# save or display image (only possible through manual debugging)
num_blank_pixels = dists.get(0, 0)
# Check for mostly black image
if num_blank_pixels > total * BLACK_PIXEL_THRESHOLD:
percent_blank = 100.0 * num_blank_pixels / total if total > 0 else 0
log.f(f"Too many blank pixels: {num_blank_pixels}/{total} ({percent_blank:.1f}%)")
return False, num_blank_pixels
# Remove zero values from dists for meaningful depth check
dists_no_zero = {k: v for k, v in dists.items() if k != 0}
if save_image or show_image:
frames_to_image(depth, color, save_image, show_image)

# If any distance is the same on more than 90% of the pixels, there is no meaningful depth
meaningful_depth = not any(v > total * 0.9 for v in dists.values())
num_blank_pixels = dists[0]
# If any distance is the same on more than DEPTH_PERCENTAGE of the pixels, there is no meaningful depth
# Find the largest non-zero depth bin
max_nonzero_count = max(dists_no_zero.values()) if dists_no_zero else 0
max_nonzero_percent = 100.0 * max_nonzero_count / total if total > 0 else 0
meaningful_depth = not (max_nonzero_count > total * DEPTH_PERCENTAGE)
fill_rate = 100.0 * (total - num_blank_pixels) / total if total > 0 else 0
log.i(f"Depth fill rate: {fill_rate:.1f}% (blank pixels: {num_blank_pixels}/{total}), meaningful depth: {meaningful_depth} (largest bin: {max_nonzero_percent:.1f}% - max allowed {DEPTH_PERCENTAGE * 100:.1f}%)")
return meaningful_depth, num_blank_pixels


Expand Down
Loading