标签:ssi attr base 作用 erb cloud nload dev tle
3.色彩空间
import cv2 as cv
def color_space_demo(img):
#灰度图
gray=cv.cvtColor(img,cv.COLOR_BGR2GRAY)
cv.imshow("gray",gray)
#hsv色彩空间转换
hsv=cv.cvtColor(img,cv.COLOR_BGR2HSV)
cv.imshow("hsv",hsv)
#yuv色彩空间转换
yuv=cv.cvtColor(img,cv.COLOR_BGR2YUV)
cv.imshow("yuv",yuv)
print("---hello-----")
src=cv.imread("aaa.png",cv.WINDOW_AUTOSIZE)
cv.namedWindow("input img",0)
cv.imshow("input img",src)
color_space_demo(src)
cv.waitKey(0)
cv.destroyAllwindows()
import cv2 as cv
import numpy as np
#通过HSV提取视频中的相应颜色
def extrace_object():
capture=cv.VideoCapture("./video.mp4")
while True:
ret,frame=capture.read()
if ret==False:
break
hsv=cv.cvtColor(frame,cv.COLOR_BGR2HSV)
lower_hsv=np.array([35,43,46])
upper_hsv=np.array([77,255,255])
mask=cv.inRange(hsv,lowerb=lower_hsv,upperb=upper_hsv)
#显示
cv.imshow("video",frame)
# cv.waitKey(100)
#显示筛选后的图片,被选中的地方是白色,其他的是黑色
cv.imshow("mask",mask)
c=cv.waitKey(100)#延时100ms
if c==27:
#esc键退出
break
extrace_object()
cv.waitKey(50)
cv.destroyAllwindows()
输出视频如下:
import cv2 as cv
print("---hello-----")
src=cv.imread("aaa.png",cv.WINDOW_AUTOSIZE)
x,y=src.shape[0:2]
print(src.shape)
cv.namedWindow("input img",0)
cv.imshow("input img",src)
#通道分离
b,g,r=cv.split(src)
#放缩
b=cv.resize(b,(x*3,y*3))
g=cv.resize(g,(x*3,y*3))
r=cv.resize(r,(x*3,y*3))
cv.imshow("blue",b)
cv.imshow("green",g)
cv.imshow("red",r)
#通道分离
src[:,:,1]=0#指定第2个通道全部为0
src=cv.merge([b,g,r])
cv.imshow("change image",src)
cv.waitKey(0)
cv.destroyAllWindows()
分离后:原图和3个通道的图
合并后:原图和修改后的图的区别
标签:ssi attr base 作用 erb cloud nload dev tle
原文地址:https://www.cnblogs.com/AI-robort/p/13377830.html