OpenCV-python基础操作之图像在不同色彩空间之间的转换
代码:
import cv2
as cv
def color_space_demo(image
):
gray
= cv
.cvtColor
(src
, cv
.COLOR_BGR2GRAY
)
cv
.imshow
("gray", gray
)
hsv
= cv
.cvtColor
(image
, cv
.COLOR_BGR2HSV
)
cv
.imshow
("hsv", hsv
)
yuv
= cv
.cvtColor
(image
, cv
.COLOR_BGR2YUV
)
cv
.imshow
("yuv", yuv
)
ycrcb
= cv
.cvtColor
(image
, cv
.COLOR_BGR2YCrCb
)
cv
.imshow
("ycrcb", ycrcb
)
src
= cv
.imread
("../OpenCV_Files/pictures_for_OpenCV/15.jpg")
cv
.namedWindow
("input image", cv
.WINDOW_AUTOSIZE
)
cv
.imshow
("input image", src
)
color_space_demo
(src
)
cv
.waitKey
(0)
cv
.destroyWindow
('all')
运行效果:
注意:
读入的图片,本地路径要正确,并且图片不要出现中文命名,可能会报错。
error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow’
如下图: