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

版权声明:如需转载请标注 https://blog.csdn.net/weixin_40973138/article/details/84487681

通道分离

#--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()

在这里插入图片描述

通道合并

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

#--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()

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_40973138/article/details/84487681