Commit 6f280047 authored by Vincent POLLET's avatar Vincent POLLET
Browse files

Merge branch 'improvements' of gitlab.idiap.ch:bob/bob.io.stream into improvements

parents a79df6b1 47d808d1
Pipeline #41830 passed with stage
in 15 minutes and 15 seconds
include README.rst buildout.cfg COPYING version.txt requirements.txt
recursive-include doc *.rst *.png *.ico *.txt
\ No newline at end of file
recursive-include doc *.py *.rst *.png *.ico *.txt
recursive-include bob/io/stream *.h5 *.png *.json
......@@ -20,12 +20,6 @@
This package is part of the signal-processing and machine learning toolbox Bob_.
.. todo::
**Complete the sentence above to include one phrase about your
package! Once this is done, delete this to-do!**
Installation
------------
......@@ -45,4 +39,4 @@ development `mailing list`_.
.. Place your references here:
.. _bob: https://www.idiap.ch/software/bob
.. _installation: https://www.idiap.ch/software/bob/install
.. _mailing list: https://www.idiap.ch/software/bob/discuss
\ No newline at end of file
.. _mailing list: https://www.idiap.ch/software/bob/discuss
......@@ -435,7 +435,7 @@ class StreamWarp(StreamFilter):
output.append(transform.warp( data[c],
self.warp_transform,
output_shape=self.output_shape,
preserve_range=True))
preserve_range=True).astype(data.dtype))
output = np.stack(output)
return output
......
import bob.io.stream
from bob.ip.viewer import View
import numpy as np
import bob.io.base
import bob.io.image
import cv2 as cv
import pyqtgraph.exporters
###
v = View()
img,plt = v.setImageMatrix(rows=2, cols=5)
def plot(i, row, col):
v.setImageData(i, row, col)
###
#f = bob.io.stream.StreamFile( '/Users/david/Desktop/idiap/data/1_01_0004_0000_00_00_000-dceb260e.h5',
# '/Users/david/Desktop/idiap/bob.io.stream/bob/io/stream/config/batl2_idiap_config.json')
f = bob.io.stream.StreamFile( '/Users/david/Desktop/idiap/data/1_01_0064_0000_00_00_000-b112ebe7.h5',
'/Users/david/Desktop/idiap/bob.io.stream/bob/io/stream/config/batl2_idiap_config.json')
#print('available streams:')
#for k in f.get_available_streams():
# print(k)
#print()
#print('available filters:')
#for k in color.get_available_filters():
# print(k)
#print()
# define streams
color = f.stream('color')
depth = f.stream('depth').clean()
nir_left = f.stream('nir_left_stereo')
nir_right = f.stream('nir_right_stereo')
nir_left_735nm = f.stream('nir_left_735nm')
nir_left_850nm = f.stream('nir_left_850nm')
nir_left_940nm = f.stream('nir_left_940nm')
nir_left_1050nm = f.stream('nir_left_1050nm')
swir_940nm = f.stream('swir_940nm').clean()
swir_1050nm = f.stream('swir_1050nm').clean()
swir_1200nm = f.stream('swir_1200nm').clean()
swir_1300nm = f.stream('swir_1300nm').clean()
swir_1450nm = f.stream('swir_1450nm').clean()
swir_1550nm = f.stream('swir_1550nm').clean()
swir_1650nm = f.stream('swir_1650nm').clean()
thermal = f.stream('thermal')
swir_norm = swir_1050nm.normalize().stack(swir_1300nm.normalize()).stack(swir_1550nm.normalize())
nir = nir_left_940nm.stack(nir_left_850nm).stack(nir_left_735nm)
nir_norm = nir_left_940nm.normalize().stack(nir_left_850nm.normalize()).stack(nir_left_735nm.normalize())
nir_left_gray = nir_left.to_rgb(mode='gray')
map_3d = nir_left.stereo(nir_right)
rep_color = color.reproject(nir_left, nir_right, map_3d)
rep_nir_left = nir_left.reproject(nir_left, nir_right, map_3d)
rep_nir_right = nir_right.reproject(nir_left, nir_right, map_3d)
#rep_swir = swir.reproject(nir_left, nir_right, map_3d)
rep_swir_norm = swir_norm.reproject(nir_left, nir_right, map_3d)
rep_thermal = thermal.normalize().reproject(nir_left, nir_right, map_3d)
rep_nir = nir.reproject(nir_left, nir_right, map_3d)
rep_nir_norm = nir_norm.reproject(nir_left, nir_right, map_3d)
#rep_swir_1300 = swir_1300.normalize().reproject(nir_left, nir_right, map_3d)
warp_depth = depth.warp(nir_left).normalize(tmin=450, tmax=750)
# load
data_map_3d = map_3d[0][:,100:1500,400:1200]
data_map_3d_dep = data_map_3d[0]
data_rep_thermal = rep_thermal[0][:,100:1500,400:1200]
data_rep_nir_left = rep_nir_left[0][:,100:1500,400:1200]
data_rep_color = rep_color[0][:,100:1500,400:1200]
data_rep_nir_right = rep_nir_right[0][:,100:1500,400:1200]
data_rep_swir_norm = rep_swir_norm[0][:,100:1500,400:1200]
data_rep_nir = rep_nir[0][:,100:1500,400:1200]
data_rep_nir_norm = rep_nir_norm[0][:,100:1500,400:1200]
data_depth = warp_depth[0][:,100:1500,400:1200]
print(data_depth.shape, data_depth.dtype)
print(np.amin(data_depth), np.amax(data_depth))
print('depth', np.amin(depth[0]), np.amax(depth[0]))
#print('swir', np.amin(swir_1050[0]), np.amax(swir_1050[0]))
#print('swir', np.amin(swir_1300[0]), np.amax(swir_1300[0]))
#print('swir', np.amin(swir_1550[0]), np.amax(swir_1550[0]))
#tmin = 300.0
#tmax = 700.0
#data_depth = (data_depth - tmin)
#data_depth = (data_depth * 255.0 / float(tmax - tmin)).astype('uint8')
# export
tmin = np.amin(data_map_3d_dep)
tmax = np.amax(data_map_3d_dep)
exp_map_depth = (data_map_3d_dep - tmin).astype('float')
exp_map_depth = (exp_map_depth * 255.0 / float(tmax - tmin)).astype('uint8')
exp_map_depth= cv.applyColorMap(exp_map_depth, cv.COLORMAP_JET)
exp_map_depth = np.moveaxis(exp_map_depth, 2, 0)
exp_intel_depth = cv.applyColorMap(data_depth[0], cv.COLORMAP_JET)
exp_intel_depth = np.moveaxis(exp_intel_depth, 2, 0)
print('fin', exp_intel_depth.shape)
exp_thermal = data_rep_thermal[0].astype('uint8')
exp_thermal = cv.applyColorMap(exp_thermal, cv.COLORMAP_JET)
exp_thermal = np.moveaxis(exp_thermal, 2, 0)
exp_color = np.flip(data_rep_color, axis=0)
exp_nir_l = data_rep_nir_left[0]
tmin = np.amin(exp_nir_l)
tmax = np.amax(exp_nir_l)
exp_nir_l = (exp_nir_l - tmin).astype('float')
exp_nir_l = (exp_nir_l * 255.0 / float(tmax - tmin)).astype('uint8')
exp_nir_r = data_rep_nir_right[0]
tmin = np.amin(exp_nir_r)
tmax = np.amax(exp_nir_r)
exp_nir_r = (exp_nir_r - tmin).astype('float')
exp_nir_r = (exp_nir_r * 255.0 / float(tmax - tmin)).astype('uint8')
exp_nir_rl = np.stack([exp_nir_l, exp_nir_l/2 + exp_nir_r/2 , exp_nir_r]).astype('uint8')
exp_rep_nir_norm = data_rep_nir_norm.astype('uint8')
exp_rep_swir_norm = data_rep_swir_norm.astype('uint8')
print(exp_map_depth.shape, exp_color.shape, exp_rep_swir_norm.shape)
print(exp_intel_depth.shape, exp_rep_nir_norm.shape, exp_thermal.shape)
exp_top = np.concatenate((exp_map_depth, exp_color, exp_rep_swir_norm), axis=2)
exp_bot = np.concatenate((exp_intel_depth, exp_rep_nir_norm, exp_thermal), axis=2)
print(exp_top.shape, exp_bot.shape)
exp = np.concatenate((exp_top, exp_bot), axis=1)
bob.io.base.save(exp, 'test.png')
# plot
plot(data_depth, 0, 0)
plot(data_map_3d_dep, 1, 0)
plot(data_rep_thermal, 0, 1)
plot(data_rep_nir_left, 1, 1)
plot(data_rep_color, 0, 2)
plot(data_rep_nir_right, 1, 2)
#plot(data_rep_swir, 0, 3)
plot(data_rep_swir_norm, 1, 3)
plot(data_rep_nir, 0, 4)
plot(data_rep_nir_norm, 1, 4)
v.resize(1400,1100)
plt[0][0].autoRange()
v.show()
quit()
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
"""
Test Units
"""
# ==============================================================================
from bob.io.stream import StreamFile, Stream
from bob.ip.stereo import StereoParameters
from bob.ip.stereo.test.test import is_close_enough
from bob.io.base import load
from pkg_resources import resource_filename
import numpy as np
# ==============================================================================
def resource_path(relative_path, package="bob.io.stream"):
"""Wrapper around pkg_resources to get the paths.
Args:
package (str): package name
relative_path (str): Location of the resource in the package
"""
return resource_filename(package, relative_path)
def test_stream():
"""
Test that a few transforms (stereo, reproject, adjust, colormap, select, warp) applied with streams 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"))
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"),
)
color = f.stream("color")
nir_left = Stream("nir_left_stereo").adjust(color)
nir_right = f.stream("nir_right_stereo").adjust(color)
swir_1050 = f.stream("swir_1050nm")
swir_1300 = f.stream("swir_1300nm")
swir_1550 = f.stream("swir_1550nm")
thermal = f.stream("thermal")
# 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)
# 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)
# 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)
# 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
assert is_close_enough(gt_depth, depth[0])
assert is_close_enough(gt_color, rep_color[0])
# 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)
import bob.io.stream
import numpy as np
import bob.io.base
import bob.io.image
import cv2 as cv
#f = bob.io.stream.StreamFile( '/Users/david/Desktop/idiap/data/1_01_0004_0000_00_00_000-dceb260e.h5',
# '/Users/david/Desktop/idiap/bob.io.stream/bob/io/stream/config/batl2_idiap_config.json')
f = bob.io.stream.StreamFile( '/Users/david/Desktop/idiap/data/1_01_0064_0000_00_00_000-b112ebe7.h5',
'/Users/david/Desktop/idiap/bob.io.stream/bob/io/stream/config/batl2_idiap_config.json')
# define streams
color = f.stream('color')
swir = f.stream('swir_1050nm')
swir_adj = swir.adjust(color)
print(color.shape)
print(swir.shape)
print(swir_adj.shape)
print(color.timestamps)
print(swir.timestamps)
print(swir_adj.timestamps)
x = swir_adj[0:60:4]
\ No newline at end of file
import bob.io.stream
from bob.ip.viewer import View
import numpy as np
###
v = View()
img,plt = v.setImageMatrix(rows=2, cols=5)
def plot(i, row, col):
v.setImageData(i, row, col)
###
f = bob.io.stream.StreamFile( '/Users/david/Desktop/idiap/data/1_01_0004_0000_00_00_000-dceb260e.h5',
'/Users/david/Desktop/idiap/bob.io.stream/bob/io/stream/config/batl2_idiap_config.json')
#f = bob.io.stream.StreamFile( '/Users/david/Desktop/idiap/data/1_01_0064_0000_00_00_000-b112ebe7.h5',
# '/Users/david/Desktop/idiap/bob.io.stream/bob/io/stream/config/batl2_idiap_config.json')
print('available streams:')
for k in f.get_available_streams():
print(k)
print()
###
color = f.stream('color')
print('available filters:')
for k in color.get_available_filters():
print(k)
print()
# define pipelines
nir_left = f.stream('nir_left_stereo')
nir_right = f.stream('nir_right_stereo')
nir_735 = f.stream('nir_left_735nm')
nir_850 = f.stream('nir_left_850nm')
nir_940 = f.stream('nir_left_940nm')
swir_1050 = f.stream('swir_1050nm')
swir_1300 = f.stream('swir_1300nm')
swir_1550 = f.stream('swir_1550nm')
thermal = f.stream('thermal')
swir = swir_1550.stack(swir_1300).stack(swir_1050)
swir_norm = swir_1550.normalize().stack(swir_1300.normalize()).stack(swir_1550.normalize())
nir = nir_940.stack(nir_850).stack(nir_735)
nir_norm = nir_940.normalize().stack(nir_850.normalize()).stack(nir_735.normalize())
nir_left_gray = nir_left.to_rgb(mode='gray')
map_3d = nir_left.stereo(nir_right)
warp_map_3d = map_3d.warp(color)
warp_color = color.warp(color)
warp_nir_left = nir_left.warp(color)
warp_nir_right = nir_right.warp(color)
warp_swir = swir.warp(color)
warp_swir_norm = swir_norm.warp(color)
warp_thermal = thermal.normalize().warp(color)
warp_nir = nir.warp(color)
warp_nir_norm = nir_norm.warp(color)
warp_swir_1300 = swir_1300.normalize().warp(color)
warp_nirl = nir_left.warp(color)
# load and plot first frame
plot(nir_left[0], 0, 0)
plot(warp_map_3d[0], 1, 0)
plot(warp_thermal[0], 0, 1)
plot(warp_nir_left[0], 1, 1)
plot(warp_color[0], 0, 2)
plot(warp_nir_right[0], 1, 2)
plot(warp_swir[0], 0, 3)
plot(warp_swir_norm[0], 1, 3)
plot(warp_nir[0], 0, 4)
plot(warp_nir_norm[0], 1, 4)
v.show()
......@@ -30,6 +30,7 @@ requirements:
- future
- scikit-image
- scipy
- opencv
# place your other host dependencies here
run:
- python
......@@ -39,6 +40,7 @@ requirements:
- future
- scikit-image
- scipy
- opencv
# place other runtime dependencies here (same as requirements.txt)
test:
......@@ -64,4 +66,4 @@ about:
home: https://www.idiap.ch/software/bob/
license: GNU General Public License v3 (GPLv3)
license_family: GPL
license_file: ../COPYING
\ No newline at end of file
license_file: ../COPYING
.. vim: set fileencoding=utf-8 :
.. Tue 09 Jun 2020 13:16:45 CET
============
Python API
============
Package Documentation
---------------------
.. automodule:: bob.io.stream
......@@ -5,4 +5,4 @@ bob.ip.stereo
future
matplotlib
scikit-image
scipy
\ No newline at end of file
scipy
Supports Markdown
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