diff --git a/python/ftl/ftlstream.py b/python/ftl/ftlstream.py index 103a53c967bff23260fb24f53ce51888ec514817..75aa4406dd2197e5589d4a02a3534bbc526187b0 100644 --- a/python/ftl/ftlstream.py +++ b/python/ftl/ftlstream.py @@ -25,7 +25,7 @@ except ImportError: ''' YCrCb to RGB, based on OpenCV documentation definition. Note: It seems this implementation is not perfectly equivalent to - OpenCV's + OpenCV's (results not exactly same, why?) ''' rgb = np.zeros(img.shape, np.float) @@ -41,6 +41,20 @@ except ImportError: return rgb.round().astype(np.uint8) +def _ycbcr2rgb(img): + rgb = np.zeros(img.shape, np.float) + + Y = img[:,:,0].astype(np.float) + Cr = img[:,:,2].astype(np.float) + Cb = img[:,:,1].astype(np.float) + delta = 128.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) + + return rgb.round().astype(np.uint8) + class FTLStreamWriter: def __init__(self, file, version=2): self._file = open(file, "wb") @@ -237,7 +251,7 @@ class FTLStreamReader: if self._version < 3: self._frame = _ycrcb2rgb(img) else: - self._frame = img + self._frame = _ycbcr2rgb(img) def _decode_opencv(self, sp, p): try: