当前位置:网站首页>1. opencv realizes simple color recognition
1. opencv realizes simple color recognition
2022-06-29 12:37:00 【I am handsome zvz】
Reference resources
step
One 、 BGR and HSV Color model
BGR Model
BGR The model represents three color channels : red 、 green 、 blue , use BGR The color of the image of the model is weighted and mixed by red, green and blue .
The disadvantages of such models are obvious , It is difficult to express a color . For example, you modified the following BGR Medium B value , Indirectly , G and R The color of the channel will also be changed .

HSV Model
H Express Hue Color ;S Express Saturation saturation ;V Express Value Lightness .
The simple understanding is
H Specify a color , from 0 To 360;
S Is the extent of white light , from 0 To 1, 0 Indicates highest saturation , Is the most white light ;
V Express lightness , from 0 To 1, 0 The darkest 
Two 、 Using the camera , utilize HSV Realize color recognition
1. Ideas
Read camera video stream , Take the middle of the window , Change its pixel value (BGR) Convert to HSV, And then according to Hue To simply judge the color . Then it will be displayed on the window .
2. Code
import cv2
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH,1080) #set window's width and height
cap.set(cv2.CAP_PROP_FRAME_HEIGHT,780)
while True:
_, frame = cap.read()
hsv_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
height,width,_ = hsv_frame.shape
wx = int(width/2) # center
wy = int(height/2)
center_color = hsv_frame[wy,wx] # Center point HSV Pixel values
hue_value = center_color[0] # take Hue
if hue_value < 5:
color = 'RED'
elif hue_value < 22:
color = 'ORANGE'
elif hue_value < 33:
color = 'YELLOW'
elif hue_value < 78:
color = 'GREEN'
elif hue_value <131:
color = 'BLUE'
elif hue_value < 167:
color = 'VIOLET'
else:
color ='RED'
bgr_color = frame[wy,wx]
b,g,r = int(bgr_color[0]),int(bgr_color[1]),int(bgr_color[2])
cv2.circle(frame,(wx,wy),5,(0,255,0),3) # center (x,y)
cv2.putText(frame,color,(10,50),0,1,(b,g,r),2)
cv2.imshow('frame',frame)
key = cv2.waitKey(1)
if key ==27:
break
cap.release()
cv2.destroyAllWindows()
3. effect 


边栏推荐
- Gbase8s database sorts standard or raw result tables
- 面试突击61:说一下MySQL事务隔离级别?
- MySQL主从同步之 异步复制 半同步复制 全同步复制
- 论文复现——AC-FPN:Attention-guided Context Feature Pyramid Network for Object Detection.
- GBase8s数据库select有HAVING 子句
- 推荐模型复现(三):召回模型YoutubeDNN、DSSM
- nvtmpp
- Is it safe for Orient Fortune Securities to open an account? Handling of securities account opening
- MIT线性代数中文笔记
- NvtBack
猜你喜欢

After class assignment of module 5 of the construction practice camp
Some printer driver PPD files of Lenovo Lingxiang lenovoimage

在印度与软件相关的发明可不可以申请专利?

Introduction to multi project development - business scenario Association basic introduction test payroll

智能指标驱动的管理和决策平台 Kyligence Zen 全新上线,限量内测中

参加2022年杭州站Cocos Star Meetings

多项目开发入门-业务场景关联基础入门测试 工资表

Unexpected ‘debugger‘ statement no-debugger

go 学习-搭建开发环境vscode开发环境golang

Interpolated scatter data
随机推荐
Gbase8s database select has order by Clause 3
Engineering practice behind dall-e 2: ensure that the output of the model complies with the content policy
地球观测卫星数据
二十三、1-Bit数据的存储(延迟线/磁芯/DRAM/SRAM/磁带/磁盘/光盘/Flash SSD)
【云原生】2.4 Kubernetes 核心实战(中)
Pro test! Centos7 deploy PHP + spool
GBase8s数据库INTO TEMP 子句创建临时表来保存查询结果。
缓存一致性,删除缓存,写入缓存,缓存击穿,缓存穿透,缓存雪崩
MIT linear algebra Chinese Notes
Gbase8s database select has order by Clause 4
nacos启动报错
求大数的阶乘 ← C语言
GBase8s数据库FOR UPDATE 子句
Factorization of large numbers ← C language
An interpretable geometric depth learning model for structure based protein binding site prediction
如何查看网站已经保存的密码
Gbase8s database into standard and into raw clauses
力扣每日一题-第31天-1779.找到最近的有相同x或y坐标的点
Li Kou daily question - day 31 -1779 Find the nearest point with the same X or Y coordinate
Li Kou daily question - day 31 -13 Maximum perimeter of triangle