当前位置:网站首页>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)
边栏推荐
- 多表查询
- Salesforce File Share and Security
- 面试常见问题一二
- Hackers use lasers to attack, and voice assistants can be activated from a distance of 100 meters
- 施耐德电气、欧莱雅等企业巨头如何开放式创新?DEMO WORLD世界创新峰会揭秘
- 浅论分布式训练中的recompute机制
- golang chan实现互斥锁
- Hutool string utility class
- org.gradle.api.UncheckedIOException: Could not load properties for module ‘gradle-kotlin-dsl‘ from C
- 防止sql注入
猜你喜欢

多表查询

深度学习-论文阅读:动作结构性图卷积网络AS-GCN

Understand │ what is cross domain? How to solve cross domain problems?

GIS数据漫谈(五)— 地理坐标系统

浅论分布式训练中的recompute机制

On recommend mechanism in distributed training

Dbeaver connection MySQL error: the server time zone value 'Ö Ð¹ ú±ê ×¼ ʱ ¼ ä‘ is unrecognized or represents more than

zabbix6.0的安装部署

Local development using LWC in salesforce

Salesforce File Share and Security
随机推荐
Multi thread implementation loop
小米CC9 Pro拆解:后置五摄成本是骁龙855数倍!
WPF做登陆界面
vue使用keep-alive实现页面缓存
fragmentTransaction.replace第二个参数报错
GIS数据漫谈(五)— 地理坐标系统
Understand │ what is cross domain? How to solve cross domain problems?
How to solve the error of ora-00955 when Oracle modifies the primary key
深度学习-视频行为识别:论文阅读——双流网络(Two-stream convolutional networks for action recognition in videos)
@Scheduled and quartz
MySQL adds users and grants query only permission
江苏华存首发PCIe 5.0 SSD主控:台积电12nm工艺,2020年量产
golang 等待一组goroutine完成,并带返回值(2)
【学习笔记】热点账户问题的解决方案
Prevent SQL injection
hutool- 数字计算
Dbeaver connection MySQL error: the server time zone value 'Ö Ð¹ ú±ê ×¼ ʱ ¼ ä‘ is unrecognized or represents more than
解决Reids不能被其他IP访问
LootCode动态数组练习(724,118,766)
The global cloud market is growing rapidly, and data security has entered a strong regulatory era of rule of law