当前位置:网站首页>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)
边栏推荐
- js工具-cookie简单封装
- You can't specify target table 'table name' for update in from clause error resolution in MySQL
- JRS-303用法
- org.gradle.api.UncheckedIOException: Could not load properties for module ‘gradle-kotlin-dsl‘ from C
- 解决Reids不能被其他IP访问
- MySQL 中 You can‘t specify target table ‘表名‘ for update in FROM clause错误解决办法
- canvas根据坐标点绘制图形
- Hackers use lasers to attack, and voice assistants can be activated from a distance of 100 meters
- 深度学习:STGCN学习笔记
- @Scheduled and quartz
猜你喜欢

Getting started with typora: the most complete tutorial in the whole network

解决Reids不能被其他IP访问

Salesforce runs all test classes and gets coverage reports

【学习笔记】MySQL数据库高级版 - 索引优化、慢查询、锁机制等

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

Redis网红高频面试题三连:缓存穿透?缓存击穿?缓存雪崩?

最新大厂高级面试题 必备

深度学习-论文阅读:动作结构性图卷积网络AS-GCN
![[Southwest University] information sharing of postgraduate entrance examination and re examination](/img/15/298ea6f7367741e1e085007c498e51.jpg)
[Southwest University] information sharing of postgraduate entrance examination and re examination

VSS tip: search all checked out files (search checked out files according to users)
随机推荐
Is it difficult to operate email safely? COREMAIL joins hands with cloud store to create a new ecosystem of corporate email office!
org.apache.catalina.core.StandardContext.startInternal Context [] startup failed due to previous err
江苏华存首发PCIe 5.0 SSD主控:台积电12nm工艺,2020年量产
Detailed explanation of browser caching mechanism
Together with Samsung, vivo will promote exynos980 dual-mode 5g mobile phone!
Dbeaver connection MySQL error: the server time zone value 'Ö Ð¹ ú±ê ×¼ ʱ ¼ ä‘ is unrecognized or represents more than
数据库的常用命令2
查看端口PID及结束进程
Getting started with typora: the most complete tutorial in the whole network
深度学习:安装包记录
[learning notes] solutions to hot account problems
CPU introduction
golang 并发缓存击穿或合并请求
IDEA打包war包与war包位置
查找表中多余重复记录并删除保留最小一个
携手三星,vivo将推Exynos980双模5G手机!
Knowledge dry goods: basic storage service novice Experience Camp
Hutool string utility class
Press Google and NVIDIA! Alibaba optical 800 chip won the world's first authoritative test again
登录页面tableLayout(表格布局)