Commit 17f55eb4 authored by Vincent POLLET's avatar Vincent POLLET

Fix image conversion functions and implement unit test for them.

parent 08e99759
Pipeline #47311 failed with stage
in 1 minute and 15 seconds
......@@ -6,12 +6,26 @@ Test Units of utils functions.
"""
# ==============================================================================
import numpy as np
import cv2
from bob.io.stream.utils import get_axis_size, get_index_list, rotate_data
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.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():
"""Unit tests for :func:`~bob.io.stream.utils.rotate_data`."""
......
......@@ -26,7 +26,7 @@ def convert_bob_to_cv(img):
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.rollaxis(img, 2)
img = np.moveaxis(img, 0, 2)
img = np.flip(img, axis=2)
return img
......@@ -55,7 +55,7 @@ def convert_cv_to_bob(img):
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.rollaxis(img, 2)
img = np.moveaxis(img, 2, 0)
img = np.flip(img, axis=0)
return img
......
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