1. 程式人生 > >OpenCV + Python 實現視訊通道分離與合併

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

在這裡插入圖片描述

通道合併

注意:合併的通道可以任意組合,且合成順序與合成效果有關

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

在這裡插入圖片描述