python rgb转yuv_在Opencv Python中将RGB图像转换为YUV和YCbCr颜色空间图像

Can anyone help me to convert an RGB colour space image to YUV colour space image and to YCbCr colour space image using opencv Python?

解决方案

Use cv2.cvtColor(src, code) to convert Color-Space, the code starts with COLOR_.

You can use this to look for the color code.

import cv2

## get all color codes

codes = [x for x in dir(cv2) if x.startswith("COLOR_")]

## print first three color codes

print(codes[:3])

# ['COLOR_BAYER_BG2BGR', 'COLOR_BAYER_BG2BGRA', 'COLOR_BAYER_BG2BGR_EA']

## print all color codes

print(codes)

If you read the image into BGR space, then use cv2.COLOR_BGR2YUV and cv2.COLOR_BGR2YCrCb:

#cv2.COLOR_BGR2YUV

#cv2.COLOR_BGR2YCrCb

img = cv2.imread("test.png")

yuv = cv2.cvtColor(img, cv2.COLOR_BGR2YUV)

cv2.imwrite("yuv.png", yuv)

If you read the image into RGB space, then use cv2.COLOR_RGB2YUV and cv2.COLOR_RGB2YCrCb.

Here is an example image(in BGR-HSV-YUV-YCRCB color spaces):

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值