feat: Implement background depth distance feature for depth processing
- Added `background_depth_distance` property to `ActiveJob` and `RunJob` classes to manage background depth settings. - Updated job execution to handle background depth distance, allowing for fixed negative displacement in depth calculations. - Introduced new functions in the worker module to apply background depth distance to depth frames and manage original background depth. - Enhanced tests to cover new functionality, ensuring correct behavior of background depth processing and reference depth extraction. - Refactored job submission to run in a separate thread, improving responsiveness during execution.
This commit is contained in:
@@ -87,6 +87,21 @@ class ImageDepthTest(unittest.TestCase):
|
||||
|
||||
self.assertEqual(depth.shape, (2, 3))
|
||||
|
||||
def test_extracts_optional_reference_depth(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
npz_path = Path(directory) / "results.npz"
|
||||
np.savez_compressed(
|
||||
npz_path,
|
||||
depth=np.ones((1, 2, 2), dtype=np.float32),
|
||||
snapform_reference_depth=np.float32(2.5),
|
||||
)
|
||||
|
||||
reference_depth = self.image_depth.extract_reference_depth(
|
||||
npz_path
|
||||
)
|
||||
|
||||
self.assertEqual(reference_depth, 2.5)
|
||||
|
||||
def test_is_animated_image_accepts_movie_and_sequence(self):
|
||||
self.assertTrue(
|
||||
self.image_depth.is_animated_image(
|
||||
@@ -430,6 +445,28 @@ class ImageDepthTest(unittest.TestCase):
|
||||
|
||||
self.assertEqual(bounds, (-1.0, 1.0, -0.5, 0.5))
|
||||
|
||||
def test_camera_plane_bounds_use_stored_unmasked_reference_depth(self):
|
||||
source = SimpleNamespace(
|
||||
data=SimpleNamespace(size=(200, 100)),
|
||||
empty_image_offset=(-0.5, -0.5),
|
||||
)
|
||||
depth = np.full((100, 200), 9.0, dtype=np.float32)
|
||||
intrinsics = np.array(
|
||||
((100.0, 0.0, 100.0), (0.0, 100.0, 50.0), (0.0, 0.0, 1.0)),
|
||||
dtype=np.float32,
|
||||
)
|
||||
|
||||
bounds, reference_depth = self.image_depth.camera_plane_bounds(
|
||||
source,
|
||||
depth,
|
||||
intrinsics,
|
||||
-1.0,
|
||||
reference_depth=2.0,
|
||||
)
|
||||
|
||||
self.assertEqual(bounds, (-2.0, 2.0, -1.0, 1.0))
|
||||
self.assertEqual(reference_depth, 2.0)
|
||||
|
||||
def test_camera_plane_bounds_preserve_square_source_aspect(self):
|
||||
source = SimpleNamespace(
|
||||
data=SimpleNamespace(size=(447, 447)),
|
||||
@@ -460,20 +497,33 @@ class ImageDepthTest(unittest.TestCase):
|
||||
|
||||
def test_raw_distance_preserves_original_values(self):
|
||||
depth = np.array(
|
||||
((1.25, 2.5), (5.0, np.nan)),
|
||||
((1.25, -2.5), (0.0, np.nan)),
|
||||
dtype=np.float32,
|
||||
)
|
||||
|
||||
mapped = self.image_depth.prepare_depth_values(depth)
|
||||
|
||||
self.assertEqual(float(mapped[0, 0]), 1.25)
|
||||
self.assertEqual(float(mapped[0, 1]), 2.5)
|
||||
self.assertEqual(float(mapped[1, 0]), 5.0)
|
||||
self.assertEqual(float(mapped[0, 1]), -2.5)
|
||||
self.assertEqual(float(mapped[1, 0]), 0.0)
|
||||
self.assertEqual(float(mapped[1, 1]), 0.0)
|
||||
|
||||
def test_depth_values_are_scaled_before_creating_depth_image(self):
|
||||
depth = np.array(
|
||||
((0.5, -1.0), (0.0, 2.0)),
|
||||
dtype=np.float32,
|
||||
)
|
||||
|
||||
scaled = self.image_depth.scale_depth_values(depth, 4.1)
|
||||
|
||||
np.testing.assert_allclose(
|
||||
scaled,
|
||||
((2.05, -4.1), (0.0, 8.2)),
|
||||
)
|
||||
|
||||
def test_depth_plane_uses_fixed_import_settings(self):
|
||||
self.assertEqual(self.image_depth.DISPLACEMENT_STRENGTH, -1.0)
|
||||
self.assertEqual(self.image_depth.DISPLACEMENT_MIDLEVEL, 1.0)
|
||||
self.assertEqual(self.image_depth.DISPLACEMENT_STRENGTH, 1.0)
|
||||
self.assertEqual(self.image_depth.DISPLACEMENT_MIDLEVEL, 0.0)
|
||||
self.assertEqual(self.image_depth.BUMP_BASE_DISTANCE, 0.001)
|
||||
|
||||
def test_grid_segments_follow_aspect_ratio_from_subdivision_power(self):
|
||||
|
||||
Reference in New Issue
Block a user