opencv色彩空间
import cv2 as cv import numpy as np def video_demo(): capture = cv.VideoCapture("d:/two.mp4") low_array = np.array([26, 43, 46]) up_array = np.array([34, 255, 255]) while(True): ret, frame = capture.read() if ret == False: break hsv_frame = cv.cvtColor(frame, cv.COLOR_BGR2HSV) mask = cv.inRange(hsv_frame, low_array, up_array) cv.imshow("video", frame) cv.imshow("mask", mask) c = cv.waitKey(20) if c == 27: break video_demo()
使用inRange函数实现图像特征提取,其中mask是二值图像。
import cv2 as cv import numpy as np def video_demo(): capture = cv.VideoCapture("d:/two.mp4") low_array = np.array([26, 43, 46]) up_array = np.array([34, 255, 255]) while(True): ret, frame = capture.read() if ret == False: break hsv_frame = cv.cvtColor(frame, cv.COLOR_BGR2HSV) mask = cv.inRange(hsv_frame, low_array, up_array) cv.imshow("video", frame) cv.imshow("mask", mask) c = cv.waitKey(20) if c == 27: break video_demo()
使用split将图像划分成三通道,其逆过程是merge函数