OpenCV + Python 实现视频通道分离与合并

通道分离

#--coding: utf-8--
import cv2 as cv
import numpy as np


def channels_split():
        capture = cv.VideoCapture('/home/pi/Desktop/白衣黑裤.mp4')
        while True:
                ret, frame = capture.read()
                b, g, r = cv.split(frame)
                cv.imshow('video', frame)
                cv.imshow('Red', r)
                c = cv.waitKey(40)
                if cv.waitKey(50) & 0xFF == ord('q'):
                        break


channels_split()
cv.waitKey(0)
cv.destoryAllWindows()

OpenCV + Python 实现视频通道分离与合并_第1张图片

通道合并

注意:合并的通道可以任意组合,且合成顺序与合成效果有关

#--coding: utf-8--
import cv2 as cv
import numpy as np


def channels_split():
        capture = cv.VideoCapture('/home/pi/Desktop/白衣黑裤.mp4')
        while True:
                ret, frame = capture.read()
                b, g, r = cv.split(frame)
                src = cv.merge([b, b, r])
                cv.imshow('video', frame)
                cv.imshow('complex', src)
                c = cv.waitKey(40)
                if cv.waitKey(50) & 0xFF == ord('q'):
                        break


channels_split()
cv.waitKey(0)
cv.destoryAllWindows()

OpenCV + Python 实现视频通道分离与合并_第2张图片

你可能感兴趣的:(Python,OpenCV,树莓派与计算机视觉)