编程语言
首页 > 编程语言> > 以代码为基础的opencv-python学习 颜色识别

以代码为基础的opencv-python学习 颜色识别

作者:互联网

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()

 


 

 

标签:COLOR,python,image,imshow,cv2,opencv,hsv,cvtColor,识别
来源: https://www.cnblogs.com/August2019/p/12547943.html