Python – OpenCV Python: Convert RGB to YCrCb

opencvpython

I can't seem to convert RGB to YCrCb in the new OpenCV python API (cv2). When I run this code:

img = cv2.imread('img1.jpg')
imgYCC = cv2.cvtColor(img, cv2.COLOR_RGB2YCrCb)

, I get this error:

AttributeError: 'module' object has no attribute 'COLOR_RGB2YCrCb'

What am I doing wrong?

Best Solution

The attribute name is COLOR_RGB2YCR_CB for RGB ordering.

Bear in mind that OpenCV natively uses BGR color ordering, not RGB, in which case the attribute is COLOR_BGR2YCR_CB. So, you may want to modify your code:

img = cv2.imread('img1.jpg')
imgYCC = cv2.cvtColor(img, cv2.COLOR_BGR2YCR_CB)