当前位置:网站首页>2. 改变颜色空间及颜色检测
2. 改变颜色空间及颜色检测
2022-07-27 16:08:00 【追逐梦想的阿光】
1.导入相应的包
import cv2 as cv
import numpy as np
2.使用摄像头实时识别
cap = cv.VideoCapture(0)
#填入0表示使用第一个摄像头,也可以填入本地视频的地址
3.使用循环对视频逐帧识别
while 1:
_, frame = cap.read() # ret接收是否被正确读取,被正确读取为true,否则为false,此处用_代替
# if not ret:
# print("fail to read this video")
# break
hsv = cv.cvtColor(frame, cv.COLOR_BGR2HSV)#将获取的每一帧由BGR转换成HSV格式
# 一般将 [H-10、100,100] 和 [H+10、255、255] 作为下界和上界
lower_green = np.array([35, 50, 50])
upper_green = np.array([80, 255, 255])
#确认掩膜的颜色范围
mask = cv.inRange(hsv, lower_green, upper_green)
#将结果图片进行位与操作
res = cv.bitwise_and(frame, frame, mask=mask)
cv.imshow('frame', frame)
cv.imshow('mask', mask)
cv.imshow('res', res)
k = cv.waitKey(5) & 0xFF #当按ESC键时停止程序
if k == 27:
break
有关位操作和掩膜参考这篇文章
OpenCV之bitwise_and、bitwise_not等图像基本运算及掩膜
运行结果

4.获取某种颜色的HSV值,下面以绿色为例
可以用以下代码获取某种颜色的HSV值
H(色度)范围[0,179],S(饱和度)范围[0,255],V(亮度)范围[0,255]
green = np.uint8([[[183, 213, 244]]])
hsv_green = cv.cvtColor(green, cv.COLOR_BGR2HSV)
print(hsv_green)
边栏推荐
- 小米CC9 Pro拆解:后置五摄成本是骁龙855数倍!
- Golang customize once. When error occurs, reset it for the second time
- Buffer的只读模式
- With the right tools, CI achieves twice the result with half the effort
- ES查询限制10000条数据解决方法
- On recommend mechanism in distributed training
- What every Salesforce developer should know about Dates and Times in Apex
- 深度学习:GCN(图卷积神经网络)理论学习总结
- After being "expelled" from bitland, the Jank group said for the first time: it will return as soon as possible through legal channels!
- 同心向前,Google Play 十周年啦!
猜你喜欢

美团二面:为什么Redis会有哨兵?

Telecommuting can be easily realized in only three steps

Resolve merge fields in salesforce

动态链表2栈的链表存储结构(LinkedStack实现)

LootCode动态数组练习(724,118,766)

Local development using LWC in salesforce

数据库的常用命令1
![[user article] examples of P4 consolidation practice guide disassemble resolve](/img/84/503fc057ce642038f693b38be69bc0.png)
[user article] examples of P4 consolidation practice guide disassemble resolve

Class not found: “com.parkManagement.dao.DaoTest 测试找不到测试类

What's the use of games| Game application value research case collection
随机推荐
ts学习笔记-interface
Multi thread implementation loop
携手三星,vivo将推Exynos980双模5G手机!
Code compliance: five reasons why developers use helix QAC
MySQL solves the problem of insert failure caused by duplicate unique indexes
XStream reports an error abstractreflectionconverter$unknownfield exception when parsing XML
Es query limit 10000 data solutions
深度学习:GCN(图卷积神经网络)理论学习总结
动态链表2栈的链表存储结构(LinkedStack实现)
[learning notes] classification of locks in the database
golang chan实现互斥锁
Golang customize once. When error occurs, reset it for the second time
Redis网红高频面试题三连:缓存穿透?缓存击穿?缓存雪崩?
Localization within Communities
org.apache.catalina.core.StandardContext.startInternal Context [] startup failed due to previous err
MySQL 中 You can‘t specify target table ‘表名‘ for update in FROM clause错误解决办法
Multi thread import data and generate error files for redis storage
GIS数据漫谈(五)— 地理坐标系统
About the problem of abnormal C printing
Please ask the great God a question, flinkcdc, the datetime field in synchronous MySQL will become a timestamp. Has anyone ever encountered it