分屏
- Opencv
- UVC
- 代码
- 验证
- 后话
用OpenCV实现UVC摄像头的视频分屏。
Opencv
opencv里有很多视频图像的处理功能。
UVC
Usb 视频类,免驱动的。视频流格式有MJPG和YUY2。MJPG是RGB三色通道的。要对三通道进行分屏显示。
代码
python
import cv2
import numpy as np
video = cv2.VideoCapture(0)
fps = video.get(cv2.CAP_PROP_FPS)
#print(fps)
size = (int(video.get(cv2.CAP_PROP_FRAME_WIDTH)), int(video.get(cv2.CAP_PROP_FRAME_HEIGHT)))
#print(size)
while True:
ret, frame = video.read()
channel0 = np.copy(frame)
channel0[:,:,1] = 0
channel0[:,:,2] = 0
channel1 = np.copy(frame)
channel1[:,:,0] = 0
channel1[:,:,2] = 0
channel2 = np.copy(frame)
channel2[:,:,0] = 0#修改一列的值
channel2[:,:,1] = 0
vs1 = np.hstack([frame,channel0]) # 水平堆叠
vs2 = np.hstack([channel1,channel2]) # 水平堆叠
imgs = np.vstack((vs1, vs2)) # 竖直堆叠
cv2.namedWindow("split screen",cv2.WINDOW_NORMAL)
cv2.imshow("split screen", imgs)
c = cv2.waitKey(1)#每隔1毫秒刷新一次
if c == 27:#ESC
break
video.release()
cv2.destroyAllWindows()
验证
视频流通道分屏的截屏 |
---|
可以看到红色衣服在channel2红色通道里显示是清晰的。
后话
YUY2格式分屏。