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函数

posted @ 2020-02-07 00:52  地球上最后一个直男  阅读(159)  评论(0编辑  收藏  举报