【OpenCV + Python】色彩空间&通道分离与合并

HSV色彩空间: 做颜色物体跟踪非常有用。
【OpenCV + Python】色彩空间&通道分离与合并_第1张图片
实例:

import cv2
import numpy as np
def find_obj(img):
    hsv = cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
    lower_hsv = np.array([0,43,46])
    upper_hsv = np.array([10, 255, 255])
    mask = cv2.inRange(hsv,lower_hsv,upper_hsv)
    cv2.imshow("mask_image",mask)

def change_image(img):
    b, g, r = cv2.split(img)
    cv2.imshow("blue",b)
    cv2.imshow("green", g)
    cv2.imshow("red", r)
    img[:,:,2] = 0
    scr = cv2.merge([b,g, r])   #此处要写成数组形式
    cv2.imshow("scr", scr)

img = cv2.imread('opencv.jpg',1)
cv2.imshow('img', img)

find_obj(img)
change_image(img)
cv2.waitKey(0)
cv2.destroyAllWindows()

【OpenCV + Python】色彩空间&通道分离与合并_第2张图片

你可能感兴趣的:(opencv,图像处理,python)