Skip to content
Snippets Groups Projects
Commit 64156ad2 authored by Vincent POLLET's avatar Vincent POLLET
Browse files

Merge branch 'image_format_conversion_from_bob_io_image' into 'master'

Remove image conversion from utils and use those from bob.io.image.utils

See merge request !14
parents 53d7d391 78c10e2a
Branches
Tags
1 merge request!14Remove image conversion from utils and use those from bob.io.image.utils
Pipeline #47328 canceled
...@@ -20,10 +20,12 @@ import numpy as np ...@@ -20,10 +20,12 @@ import numpy as np
from skimage import transform from skimage import transform
import cv2 as cv import cv2 as cv
from bob.io.image.utils import opencvbgr_to_bob
from bob.ip.stereo import StereoParameters from bob.ip.stereo import StereoParameters
from bob.ip.stereo import stereo_match, reproject_image, CameraPair from bob.ip.stereo import stereo_match, reproject_image, CameraPair
from .utils import convert_cv_to_bob, StreamArray from .utils import StreamArray
from .stream import stream_filter, StreamFilter from .stream import stream_filter, StreamFilter
...@@ -161,7 +163,7 @@ class StreamColorMap(StreamFilter): ...@@ -161,7 +163,7 @@ class StreamColorMap(StreamFilter):
"hsv": cv.COLORMAP_HSV, "hsv": cv.COLORMAP_HSV,
} }
data = cv.applyColorMap(data, maps[self.colormap]) data = cv.applyColorMap(data, maps[self.colormap])
data = convert_cv_to_bob(data) data = opencvbgr_to_bob(data)
return data return data
else: else:
raise ValueError("Can not convert multi-channel streams. Parent number of channels: " + str(data.shape[0])) raise ValueError("Can not convert multi-channel streams. Parent number of channels: " + str(data.shape[0]))
......
...@@ -10,22 +10,10 @@ import cv2 ...@@ -10,22 +10,10 @@ import cv2
from bob.io.image import load from bob.io.image import load
from bob.io.stream.utils import get_axis_size, get_index_list, rotate_data, convert_bob_to_cv, convert_cv_to_bob from bob.io.stream.utils import get_axis_size, get_index_list, rotate_data
from bob.io.stream.test.test import resource_path
# ============================================================================== # ==============================================================================
def test_image_format_conversion():
"""Unit tests for :func:`~bob.io.stream.utils.convert_bob_to_cv` and :func:`~bob.io.stream.utils.convert_cv_to_bob`."""
bob_im = load(resource_path("test/data/reprojection_color.png"))
ocv_im = cv2.imread(resource_path("test/data/reprojection_color.png"))
assert np.array_equal(ocv_im, convert_bob_to_cv(bob_im))
assert np.array_equal(bob_im, convert_cv_to_bob(ocv_im))
def test_rotate_data(): def test_rotate_data():
"""Unit tests for :func:`~bob.io.stream.utils.rotate_data`.""" """Unit tests for :func:`~bob.io.stream.utils.rotate_data`."""
......
...@@ -2,64 +2,6 @@ import numpy as np ...@@ -2,64 +2,6 @@ import numpy as np
import cv2 as cv import cv2 as cv
def convert_bob_to_cv(img):
"""Convert image from Bob's <RGB, h, w> format to OpenCV's <h, w, BGR> format.
Parameters
----------
img : :obj:`numpy.ndarray`
Image in Bob's format <RGB, h, w>.
Returns
-------
:obj:`numpy.ndarray`
Image in OpenCV's format <h, w, BGR>.
Raises
------
ValueError
If the input image has the wrong number of dimensions. (Must be 3).
ValueError
If the input image does not have 3 channels in first dimension.
"""
if len(img.shape) != 3:
raise ValueError("Expected image to be 3D object, but got shape " + str(img.shape))
if img.shape[0] != 3:
raise ValueError("Expected image to have 3 color channels, but got " + str(img.shape[0]) + " channels.")
img = np.moveaxis(img, 0, 2)
img = np.flip(img, axis=2)
return img
def convert_cv_to_bob(img):
"""Convert image from OpenCV's <h, w, BGR> format to Bob's <RGB, h, w> format.
Parameters
----------
img : :obj:`numpy.ndarray`
Image in OpenCV's <h, w, BGR> format.
Returns
-------
:obj:`numpy.ndarray`
Image in Bob's <RGB, h, w> format.
Raises
------
ValueError
If the input image has the wrong number of dimension. (Must be 3).
ValueError
If the input image does not have 3 channels in the last dimension.
"""
if len(img.shape) != 3:
raise ValueError("Expected image to have 3 dimension, but got shape " + str(img.shape))
if img.shape[2] != 3:
raise ValueError("Expected image to have 3 color channels, but got " + str(img.shape[2]) + " channels.")
img = np.moveaxis(img, 2, 0)
img = np.flip(img, axis=0)
return img
def rotate_data(data, angle): def rotate_data(data, angle):
"""Rotate the `data` array by `angle`, where `angle` is a multiple of a square angle. """Rotate the `data` array by `angle`, where `angle` is a multiple of a square angle.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment