HSV色彩空间: 做颜色物体跟踪非常有用。
实例:
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()