Reputation: 61
using open cv python i am trying to convert an rgb image to ycbcr using cv2.cvtclor.
the error is name 'CV_BGR2YCrCb' is not defined
Can anyone suggest few ideas.
Upvotes: 6
Views: 27109
Reputation:
OpenCV reads image as BGR so if you need RGB image then you have to convert image into its RGB form then you can perform your tasks You can use these as below
YCrCb = cv2.cvtColor(img, cv2.COLOR_BGR2YCR_CB) (# if input image is BGR)
YCrCb = cv2.cvtColor(img, cv2.COLOR_RGB2YCrCb) (# if input image is RGB)
Upvotes: 1
Reputation: 3506
You need to do this:
imgYCC = cv2.cvtColor(img, cv2.COLOR_BGR2YCR_CB)
The attribute name is COLOR_BGR2YCR_CB
not CV_BGR2YCrCb
Upvotes: 15
Reputation: 11359
OpenCV's Python bindings don't use the same flag values as the C++ constants (See this other answer for a little more detail. The correct flag value to pass is cv2.COLOR_BGR2YCR_CB
. You would call cvtColor
like this:
im = cv2.cvtColor(bgr, cv2.COLOR_BGR2YCR_CB)
Upvotes: 5