Commit ca011df0 authored by Vincent POLLET's avatar Vincent POLLET

Remove stereo related code

Remove camera member of Stream
Remove warp, stereo and reproject filters
Remove camera_config of StreamFile
Remove unit test associated with the above
Implement missing test for remaining filters
parent e949854d
Pipeline #47529 passed with stage
in 6 minutes and 20 seconds
......@@ -15,7 +15,7 @@ from bob.io.stream.stream_file import StreamFile
from bob.io.stream.stream import Stream, stream_filter, StreamFilter
# Filters are decorated to be integrated in the stream class, which happens when the module implementing them is
# Filters are decorated to be integrated in the stream class, which happens when the module implementing them is
# imported. We import them here to make sure the they are available.
# import filters defined in stream.py
......@@ -28,9 +28,6 @@ from bob.io.stream.stream_image_filters import (
StreamNormalize,
StreamClean,
StreamStacked,
StreamWarp,
StreamStereo,
StreamReproject,
StreamSubtract,
)
......
......@@ -17,22 +17,19 @@ new filter accessible when using "import bob.io.stream", it is necessary to impo
Example
-------
A stereo reprojection using the `bob.io.stream` module. Here we make use of the filters defined in stereo_filters.py.
Image processing using stream filters:
>>> from bob.io.stream import StreamFile, Stream
>>> # Open a Streamfile to a hdf5 file.
>>> f = StreamFile(input_example.h5", face_streams.json", face_calibration.json)
>>> # Define processing pipeline as cascading streams:
>>> # First define the streams to load the data from the file, and align them through the adjust filter
>>> f = StreamFile("input_example.h5", idiap_face_streams_config.json")
>>> # Define streams
>>> color = Stream("color", f)
>>> nir_left = Stream("nir_left_stereo", f).adjust(color)
>>> nir_right = Stream("nir_right_stereo", f).adjust(color)
>>> # Define the reprojection operation through the stereo filters
>>> map_3d = nir_left.stereo(nir_right)
>>> depth = map_3d.select(channel=2).colormap(colormap="jet")
>>> rep_color = color.reproject(nir_left, nir_right, map_3d)
>>> rep_color[0] # Loads data and apply processing to provide the first frame of the reprojected stream.
>>> swir_dark = Stream("swir", f)
>>> swir_940 = Stream("swir_940nm", f)
>>> # Define pipelines using filters
>>> swir_dark = swir_dark.adjust(color)
>>> swir_940 = swir_940.adjust(color).subtract(swir_dark).clean()
>>> swir_940.load(0) # Loads data and apply processing for the first frame.
"""
......@@ -41,8 +38,6 @@ from builtins import str
import numpy as np
from scipy.spatial import cKDTree
from bob.ip.stereo import Camera
from .utils import StreamArray, get_index_list, get_axis_size
from .stream_file import StreamFile
......@@ -251,24 +246,6 @@ class Stream:
def timestamps(self, value):
raise NotImplementedError
@property
def camera(self):
"""Camera object corresponding to this stream's data.
Returns
-------
:obj:`bob.ip.stereo.Camera`
Camera.
"""
if isinstance(self.parent, StreamFile):
return self.parent.get_stream_camera(self.name)
else:
return self.parent.camera
@camera.setter
def camera(self, value):
raise NotImplementedError
@property
def bounding_box(self):
"""Bounding box at each frame in the stream.
......
......@@ -11,7 +11,6 @@ import json
import numpy as np
from bob.io.base import HDF5File
from bob.ip.stereo import load_camera_config
from .config import load_data_config
......@@ -31,18 +30,14 @@ class StreamFile:
HDF5 file containing the streams data.
data_format_config : str
Path to configuration json with the streams data meta-data (names, shape, etc...)
camera_config : str
Path to json file with the camera information (camera_matrix, distortion coefficients, etc...)
during streams recording
"""
def __init__(self, hdf5_file=None, data_format_config_file_path=None, camera_config_file_path=None, mode="r"):
"""Open the HDF5 and register the data and camera configuration via :meth:`bob.io.stream.StreamFile.set_source`.
def __init__(self, hdf5_file=None, data_format_config_file_path=None, mode="r"):
"""Open the HDF5 and register the data configuration via :meth:`bob.io.stream.StreamFile.set_source`.
"""
self.hdf5_file = None
self.data_format_config = None
self.camera_config = None
self.set_source(hdf5_file, data_format_config_file_path, camera_config_file_path, mode)
self.set_source(hdf5_file, data_format_config_file_path, mode)
def __enter__(self):
return self
......@@ -51,8 +46,8 @@ class StreamFile:
if isinstance(self.hdf5_file, HDF5File):
self.hdf5_file.close()
def set_source(self, hdf5_file=None, data_format_config_file_path=None, camera_config_file_path=None, mode="r"):
"""Open the HDF5 file and load data and camera config.
def set_source(self, hdf5_file=None, data_format_config_file_path=None, mode="r"):
"""Open the HDF5 file and load data config.
Parameters
----------
......@@ -60,8 +55,6 @@ class StreamFile:
File handle or path to the streams HDF5 File, by default None.
data_format_config_file_path : str or None
Path to the data config file, by default None.
camera_config_file_path : str or None
Path to the camera config file, by default None.
mode : str
File opening mode, by default "r".
"""
......@@ -75,10 +68,6 @@ class StreamFile:
self.data_format_config = load_data_config(data_format_config_file_path)
else:
self.data_format_config = None
if camera_config_file_path is not None:
self.camera_config = load_camera_config(camera_config_file_path)
else:
self.camera_config = None
def get_available_streams(self):
""":obj:`list` of :obj:`str`: Get the names of the streams in the HDF5 File."""
......@@ -157,39 +146,6 @@ class StreamFile:
return timestamps
def get_stream_camera(self, stream_name):
"""Get the camera config of a stream.
Returns None if no camera is associated with the data in the stream.
Parameters
----------
stream_name : str
Name of the stream which camera configuration is requested.
Returns
-------
dict or None
Stream's camera config.
Raises
------
ValueError
If the stream's camera exists, but it's configuration is missing from the stream's data config (likely a
name missmatch).
"""
data_config = self.get_stream_config(stream_name)
if "use_config_from" in data_config:
data_config = self.get_stream_config(data_config["use_config_from"])
if "camera" in data_config:
camera_name = data_config["camera"]
if camera_name in self.camera_config:
return self.camera_config[camera_name]
else:
raise ValueError("invalid camera name")
else:
return None
def load_stream_data(self, stream_name, index):
"""Load the `index` frame(s) of data from `stream_name`.
......
This diff is collapsed.
......@@ -11,8 +11,6 @@ import numpy as np
from bob.io.base import load, HDF5File
from pkg_resources import resource_filename
from bob.ip.stereo import StereoParameters
from bob.ip.stereo.test.test import is_close_enough
from bob.io.stream import StreamFile, Stream
......@@ -72,15 +70,10 @@ def test_stream():
del f
# Streams attributes when config is specified
f = StreamFile(
resource_path("test/data/input_example.h5"),
resource_path("config/idiap_face_streams.json"),
resource_path("config/idiap_face_calibration.json", "bob.ip.stereo"),
)
f = StreamFile(resource_path("test/data/input_example.h5"), resource_path("config/idiap_face_streams.json"))
color = Stream("color", f)
assert color.shape == (1, 3, 1920, 1200)
assert color.timestamps[0] == 46399548
assert color.camera is not None
# Streams attributes when not specified.
f = StreamFile(resource_path("test/data/stream_test.h5"))
......@@ -90,8 +83,6 @@ def test_stream():
assert stream_b.shape == data_b.shape
assert stream_a.timestamps == None
assert stream_b.timestamps == None
assert stream_a.camera == None
assert stream_b.camera == None
# Test loading entire datasets
ld_a = stream_a.load()
......@@ -140,79 +131,56 @@ def test_stream():
def test_filters():
"""Test that a few filters provide a similar result to saved groundtruth."""
gt_color = load(resource_path("test/data/reprojection_color.png"))
gt_depth = load(resource_path("test/data/reprojection_depth.png"))
gt_warp_thermal = load(resource_path("test/data/warp_thermal.png"))
gt_warp_swir = load(resource_path("test/data/warp_swir_norm.png"))
# load groundtruth for images
gt_swir_940_dark_subtract = load(resource_path("test/data/swir_940_dark_subtract.png"))
gt_colormap_gray = load(resource_path("test/data/gt_colormap_gray.png"))
gt_colormap_bone = load(resource_path("test/data/gt_colormap_bone.png"))
gt_thermal_clean = load(resource_path("test/data/gt_thermal_clean.png"))
gt_swir_norm = load(resource_path("test/data/gt_swir_norm.png"))
landmarks = np.load(resource_path("test/data/landmarks.npy"))
bounding_box = np.load(resource_path("test/data/bounding_box.npy"))
gt_landmarks = np.load(resource_path("test/data/projected_landmarks.npy"))
gt_bounding_box = np.load(resource_path("test/data/projected_bounding_box.npy"))
f = StreamFile(resource_path("test/data/input_example.h5"), resource_path("config/idiap_face_streams.json"))
f = StreamFile(
resource_path("test/data/input_example.h5"),
resource_path("config/idiap_face_streams.json"),
resource_path("config/idiap_face_calibration.json", "bob.ip.stereo"),
)
# stream for stereo and projection tests
# define stream
color = Stream("color", f)
nir_left = Stream("nir_left_stereo").adjust(color)
nir_right = Stream("nir_right_stereo", f).adjust(color)
# streams for subtract tests
nir_left = Stream("nir_left_stereo") # set source later
swir_dark = Stream("swir", f)
swir_940 = Stream("swir_940nm", f)
# streams for stack, normalize and warp tests
swir_1050 = Stream("swir_1050nm", f)
swir_1300 = Stream("swir_1300nm", f)
swir_1550 = Stream("swir_1550nm", f)
thermal = Stream("thermal", f)
# reproject operations
map_3d = nir_left.stereo(nir_right)
depth = map_3d.select(channel=2).colormap(colormap="jet")
rep_color = color.reproject(nir_left, nir_right, map_3d)
nir_left.set_source(f)
# subtract operations
swir_dark = swir_dark.adjust(color)
swir_940 = swir_940.adjust(color).subtract(swir_dark)
# astype
nir_left_unit16 = nir_left.astype(dtype=np.int16)
assert np.array_equal(nir_left_unit16[0], nir_left[0].astype(np.int16))
# warp operations
swir_norm = swir_1550.normalize().stack(swir_1300.normalize()).stack(swir_1550.normalize())
warp_swir_norm = swir_norm.warp(color)
warp_thermal = thermal.normalize().warp(color)
# adjust
nir_left = nir_left.adjust(color)
assert swir_1050.timestamps.shape != color.timestamps.shape
assert np.allclose(swir_1050.adjust(color).timestamps, color.timestamps)
# User defined operations through "filter": eg clipping values bellow average
test_func = lambda data: np.where(data > data.mean(), data - data.mean(), data.mean())
user_filter = color.filter(process_frame=test_func)
assert np.array_equal(user_filter[0], test_func(color[0]))
# landmarks and bounding box
color.bounding_box[0] = bounding_box
color.image_points[0] = landmarks
# select
assert np.array_equal(color[0][1], color.select(channel=1)[0][0])
# these streams have different timestamps before adjust
assert swir_1050.timestamps.shape != color.timestamps.shape
assert np.allclose(swir_1050.adjust(color).timestamps, color.timestamps)
# colormap
assert np.allclose(thermal.colormap(colormap="gray")[0], gt_colormap_gray)
assert np.allclose(thermal.colormap(colormap="bone")[0], gt_colormap_bone)
# Compare stereo and projection results
assert gt_depth.shape == depth[0].shape # groundtruth correspond to first frame of stream
assert gt_color.shape == rep_color[0].shape
# clean
assert np.allclose(thermal.clean()[0], gt_thermal_clean)
assert is_close_enough(gt_depth, depth[0])
assert is_close_enough(gt_color, rep_color[0])
# stack and norm
swir_norm = swir_1550.normalize().stack(swir_1300.normalize()).stack(swir_1550.normalize())
assert np.allclose(swir_norm[0], gt_swir_norm)
# compare subtract results
# subtract
swir_dark = swir_dark.adjust(color)
swir_940 = swir_940.adjust(color).subtract(swir_dark)
assert np.array_equal(swir_940[0][0], gt_swir_940_dark_subtract)
# Compare warp results
assert is_close_enough(warp_swir_norm[0][0], gt_warp_swir)
assert is_close_enough(warp_thermal[0][0], gt_warp_thermal)
assert np.array_equal(rep_color.bounding_box[0], gt_bounding_box)
assert np.allclose(rep_color.image_points[0], gt_landmarks)
# user filter results
assert np.array_equal(user_filter[0], test_func(color[0]))
......@@ -32,7 +32,6 @@ requirements:
- bob.extension
- bob.io.base
- bob.io.image
- bob.ip.stereo
# place your other host dependencies here
run:
- {{ pin_compatible('python') }}
......
......@@ -5,4 +5,3 @@ scikit-image
# opencv We need opencv, but the opencv package is broken and can't be installed with pip. Install it with conda.
bob.io.base
bob.io.image
bob.ip.stereo
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment