[英]Python OpenCV: How to convert YCbCr back to RGB?
In OpenCV (Python), to convert RGB to YCbCr we use: 在OpenCV(Python)中,要将RGB转换为YCbCr,我们使用:
imgYCC = cv2.cvtColor(img, cv2.COLOR_BGR2YCR_CB)
What if i want to come back to RGB? 如果我想回到RGB怎么办?
Check the docs for color conversions . 检查文档是否有颜色转换 。 You can see all of the available color conversion codes here: Conversion Color Codes .
您可以在此处查看所有可用的颜色转换代码: 转换颜色代码 。
For the colorspaces available, you can generally transform both ways--- COLOR_BGR2YCrCb
(ie BGR-to-YCrCb) and COLOR_YCrCb2BGR
(ie YCrCb-to-BGR). 对于可用的色彩空间,通常可以两种方式进行转换:
COLOR_BGR2YCrCb
(即BGR到YCrCb)和COLOR_YCrCb2BGR
(即YCrCb到BGR)。 Also, OpenCV uses BGR ordering, not RGB ordering. 另外,OpenCV使用BGR排序,而不是RGB排序。 Regardless, to answer the specific question at hand, simply convert back using the opposite order of the colorspaces:
无论如何,要回答眼前的特定问题,只需使用相反的颜色空间顺序将其转换回来:
img_bgr = cv2.cvtColor(imgYCC, cv2.COLOR_YCrCb2BGR)
Note: cv2.COLOR_YCrCb2BGR
is equivalent to cv2.COLOR_YCR_CB2BGR
, I just find the first variant easier to read. 注意:
cv2.COLOR_YCrCb2BGR
等效于cv2.COLOR_YCR_CB2BGR
,我发现第一个变体更易于阅读。 Since these transformations (on uint8
images especially), there's some rounding going on so you won't necessarily get the exact same image going back and fourth. 由于进行了这些转换(尤其是在
uint8
图像上),因此进行了一些舍入操作,因此您不一定会获得完全相同的图像。 But you shouldn't be more than like 1 off at a few of the locations. 但是,您不应该只希望在一些地点享受1折优惠。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.