import cv2
import numpy as np
def extract_object_demo():
capture = cv2.VideoCapture(0)
while(True):
ret, frame = capture.read()
if ret == False:
break
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
low_hsv = np.array([100,43,46]) #查看下表得到蓝色的最小值
high_hsv = np.array([124,255,255]) #查看下表得到蓝色的最大值
mask = cv2.inRange(hsv,lowerb=low_hsv,upperb=high_hsv)#识别出蓝色物体
cv2.imshow("video",mask)
c = cv2.waitKey(40)
if c == 27:
break
def color_space_demo(image):
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
cv2.imshow("gray",gray)
hsv = cv2.cvtColor(image,cv2.COLOR_GBR2HSV)
cv2.imshow("hsv",hsv)
yuv = cv2.cvtColor(image, cv2.COLOR_GBR2YUV)
cv2.imshow("yuv",yuv)
src = cv2.imread("woman.jpg")
cv2.namedWindow("input image",cv2.WINDOW_AUTOSIZE)
cv2.imshow('input image',src)
extract_object_demo()
cv2.waitKey(0)
cv2.destroyAllWindows()