100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > -01-07 Python Opencv转换颜色空间 RGB转为HSV

-01-07 Python Opencv转换颜色空间 RGB转为HSV

时间:2023-09-19 17:32:15

相关推荐

-01-07 Python Opencv转换颜色空间 RGB转为HSV

Python Opencv转换颜色空间 RGB转为HSV

举个例子,通过摄像头把视频中的蓝色区域凸显出来,剩余的颜色均为黑色

import numpy as npcap = cv2.VideoCapture(0)while(1):# Take each frame_, frame = cap.read()# Convert BGR to HSVhsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)# define range of blue color in HSVlower_blue = np.array([110,50,50])upper_blue = np.array([130,255,255])# Threshold the HSV image to get only blue colorsmask = cv2.inRange(hsv, lower_blue, upper_blue)# Bitwise-AND mask and original imageres = cv2.bitwise_and(frame,frame, mask= mask)cv2.imshow('frame',frame)cv2.imshow('mask',mask)cv2.imshow('res',res)k = cv2.waitKey(5) & 0xFFif k == 27:breakcv2.destroyAllWindows()

效果

任意RGB颜色转为HSV例子

green = np.uint8([[[0,255,0 ]]])hsv_green = cv2.cvtColor(green,cv2.COLOR_BGR2HSV)print hsv_green[[[ 60 255 255]]]

则绿色范围为[H-10, 100,100] 到 [H+10, 255, 255]

H为60

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。