import cv2 as cv
import numpy as np
def extrace_object_demo():
capture = cv.VideoCapture("C:/Users/weiqiangwen/Desktop/sest/QQ视频_2703CD4E8BBCC4F5B071A7A61FA35AB7.mp4") #在读取时有可能出现ret=false用播放器打开一次视频就好了。应该是转码问题
while(True):
ret,frame = capture.read()
print (ret)
print (frame)
if ret == False:
break;
hsv = cv.cvtColor(frame, cv.COLOR_BGR2HSV) ##转成hsv码
lower_hsv = np.array([37, 43, 46]) ##绿色最低值
upper_hsv = np.array([77, 255, 255]) ##绿色最高值
mask=cv.inRange(hsv,lowerb=lower_hsv,upperb=upper_hsv) ##得到二值图像
cv.imshow("video",frame)
cv.imshow("masl",mask)
c = cv.waitKey(40)
if c ==27: ##27位退出
break;
def color_space_demo(image):
gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
cv.imshow("gray", gray)
hsv = cv.cvtColor(image, cv.COLOR_BGR2HSV)
cv.imshow("hsv", hsv)
yuv = cv.cvtColor(image, cv.COLOR_BGR2YUV)
cv.imshow("yuv", yuv)
Ycrcb = cv.cvtColor(image, cv.COLOR_BGR2YCrCb)
cv.imshow("ycrcb", Ycrcb)
print("--------- Hello Python ---------")
src = cv.imread("C:/Users/weiqiangwen/Desktop/sest/morph02.png")
cv.namedWindow("input image", cv.WINDOW_AUTOSIZE)
cv.imshow("input image", src)
color_space_demo(src)
b,g,r =cv.split(src) ##rgb分离
cv.imshow("blue",b)
cv.imshow("green",g)
cv.imshow("red",r)
src= cv.merge([b,g,r]) ##3通道合并
cv.imshow("merg",src)
extrace_object_demo()
cv.waitKey(0)
cv.destroyAllWindows()
opencv第二天视频文件打开及色彩分离合并
最新推荐文章于 2021-01-21 15:23:39 发布