Skip to content
Snippets Groups Projects
Commit 1ff17081 authored by Sebastian's avatar Sebastian
Browse files

OpenCV color conversion

parent 2ff8c152
No related branches found
No related tags found
2 merge requests!155Feature/python,!141Python module for reading .ftl files
Pipeline #15873 passed
......@@ -8,20 +8,29 @@ from . libde265 import Decoder
try:
import cv2 as cv
def ycbcr2rgb(img):
raise NotImplementedError("TODO")
def _ycrcb2rgb(img):
return cv.cvtColor(img, cv.COLOR_YCrCb2RGB)
except ImportError:
import skimage.color
def ycbcr2rgb(img):
res = skimage.color.ycbcr2rgb(img.astype(np.float))
def _ycrcb2rgb(img):
''' YCrCb to RGB, based on OpenCV documentation definition.
Note: It seems this implementation is not perfectly equivalent to OpenCV's
'''
rgb = np.zeros(img.shape, np.float)
Y = img[:,:,0].astype(np.float)
Cr = img[:,:,1].astype(np.float)
Cb = img[:,:,2].astype(np.float)
delta = 128.0
# clip
res[res > 1.0] = 1.0
res[res < 0.0] = 0.0
rgb[:,:,0] = Y + 1.403 * (Cr - delta)
rgb[:,:,1] = Y - 0.714 * (Cr - delta) - 0.344 * (Cb - delta)
rgb[:,:,2] = Y + 1.773 * (Cb - delta)
# skimage ycbcr2rgb() returns dtype float64, convert to uint8
return (res * 255).astype(np.uint8)
return rgb.round().astype(np.uint8)
# FTL definitions
......@@ -172,7 +181,7 @@ class FTLStream:
img = decoder.get_next_picture()
if img is not None:
self._frames[k] = ycbcr2rgb(img[:,:,(0,2,1)]) # note: channels BGR
self._frames[k] = _ycrcb2rgb(img)
def _flush_decoders(self):
for decoder in self._decoders.values():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment