OpenCV學(xué)習(xí)筆記2:讀取視頻文件并顯示相應(yīng)顏色通道視頻
import matplotlib.pyplot as plt
import CV2
import numpy as np
vc=CV2.VideoCapture('3d video.wmv')#讀取視頻
if vc.isOpened():
? ?open,frame=vc.read()#讀取一幀圖像,重復(fù)執(zhí)行vc.read就可以不斷往下讀取
else:
? ?open=False
while open:
? ?ret,frame=vc.read()
? ?if frame is None:#frame為none表示讀取到視頻結(jié)尾
? ? ? ?break
? ?if ret == True:
? ? ? ?b, g, r = CV2.split(frame) ?# 把bgr通道提提取出來
? ? ? ?CV2.imshow('video_b',b)#只顯示blue通道圖像
? ? ? ?#CV2.imshow('video_g',g)#只顯示green通道圖像
? ? ? ?#CV2.imshow('video_r',r)#只顯示red通道圖像
? ? ? ?if CV2.waitKey(10) & 0xff == 27:#wait key設(shè)置兩幀之間的延時(shí)
? ? ? ? ? ?break
vc.release()
CV2.destroyAllWindows()
標(biāo)簽: