作业五:
显示摄像头Rgb三通道
参考链接:
https://www.cnblogs.com/zengjixiang/p/10195669.html
https://blog.csdn.net/m0_38001731/article/details/88664640
import cv2
import numpy as np
cap=cv2.VideoCapture(0) #打开默认摄像头
while(1):
ret,frame = cap.read() #读取实时图像
cv2.imshow("capture",frame) #显示读取出来的图像
def get_red(frame):
redframe = frame[:,:,2]
return redframe
def get_green(frame):
greenframe = frame[:, :, 1]
return greenframe
def get_blue(frame):
blueframe = frame[:, :, 0]
return blueframe
r = get_red(frame)
b = get_blue(frame)
g = get_green(frame)
#hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) #把RGB模型转换成HSV模型
#cv2.imshow("HSV",hsv) #显示转换后的图像
cv2.imshow('red2',r)
cv2.imshow("Blue 2", b)
cv2.imshow("Green 2", g)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destoryAllwindows()