当前位置:网站首页>Opencv learning color detection
Opencv learning color detection
2022-07-26 07:08:00 【Heihei_ study】
Catalog
Two 、 Color detection (inRange function )
One 、HSV Color space
H( tonal ):0~180
S( saturation ):0~255
V( brightness ):0~255
Two 、 Color detection (inRange function )
inRange(imgHSV, Scalar(iLowH, iLowS, iLowV), Scalar(iHighH, iHighS, iHighV), imgThresholded); //Threshold the imageFunction for color detection , This function is used to detect src Each of the images Pixels Is it in lowerb and upperb Between , If it is , This pixel is set to 255( white ), And keep it in dst Image , Otherwise 0( black ).

int main() {
string path = "C:\\Users\\Rong\\Desktop\\Resources\\lambo.png";
Mat img = imread(path);
Mat imgHSV, mask;
int hmin = 0, smin = 110, vmin = 153;
int hmax = 19, smax = 240, vmax = 255;
cvtColor(img, imgHSV, COLOR_BGR2HSV);
Scalar lower(hmin, smin, vmin); // Lower color value
Scalar upper(hmax, smax, vmax); // The color value of the line
inRange(imgHSV, lower, upper, mask);
imshow("Image", img);
imshow("Image HSV", imgHSV);
imshow("Image Mask", mask);
waitKey(0);
return 0;
}3、 ... and 、 Track bar
int createTrackbar(conststring& trackbarname, conststring& winname, int* value, int count, TrackbarCallback onChange=0,void* userdata=0);The first parameter : Name of track bar
The second parameter : The name of the window
The third parameter : An integer pointing The pointer , Indicates the position of the slider .
Fourth parameter : A value that represents the maximum position the slider can reach .PS: The value of the slider is always at the minimum position 0.
int hmin=0, smin=0, vmin=0, hmax=0, smax=0, vmax=0;
int main() {
string path = "C:\\Users\\Rong\\Desktop\\Resources\\shapes.png";
Mat Img = imread(path);
Mat src, dst;
cvtColor(Img, src, COLOR_BGR2HSV);
// Every time on the track bar What changes is the value of the variable pointed to by the pointer
namedWindow("TrackBar",(700,700));
createTrackbar("Hmin", "TrackBar", &hmin, 180);
createTrackbar("Hmax", "TrackBar", &hmax, 180);
createTrackbar("Smin", "TrackBar", &smin, 255);
createTrackbar("Smax", "TrackBar", &smax, 255);
createTrackbar("Vmin", "TrackBar", &vmin, 255);
createTrackbar("Vmax", "TrackBar", &vmax, 255);
while (true) {
// So we can detect when the variables on those track bars change What does the image look like
Scalar lower(hmin, smin, vmin);
Scalar upper(hmax, smax, vmax);
inRange(src, lower, upper, dst);
imshow("Image src", src);
imshow("Image dst", dst);
// notes : Here is 1
waitKey(1);
}
return 0;
}边栏推荐
- NPM command
- "XXXX" is running, which may cause the system to jam, reduce the standby time, and click Close "
- 字符串和内存函数
- [today in history] July 18: Intel was founded; The first photo was posted on the world wide web; EBay spins off PayPal
- Solve the problem that Chrome browser is tampered with by drug bullies
- A guide for you to fully use TS
- Idea -- use @slf4j to print logs
- Is it safe to invest in treasury bonds in 2022? How do individuals buy treasury bonds?
- Can you learn fast and well with dual stream network? Harbin Institute of Technology & Microsoft proposed a distillation dual encoder model for visual language understanding, which can achieve fast an
- DaemonSet
猜你喜欢

【数据库】CTE(Common Table Expression(公共表表达式))

Realize the full link grayscale based on Apache APIs IX through MSE

XSS labs (1-10) break through details

Getting started with kernel PWN (5)

opengauss简易版安装报错

文件服务器FastDFS

【硬十宝典】——7.2【动态RAM】DDR4与DDR3区别解析

Delete ^m from VIM

LeetCode刷题1:题目分类

Contents mismatch at: 08000000H (Flash=FFH Required=00H) ! Too many errors to display !
随机推荐
Leetcode question brushing 1: topic classification
Flame diagram analysis Flink backpressure
MySQL read / write lock
[QT] detailed explanation of *.pro, *.pri, *.prf, *.prl files
NiO implementation
NIO实现
怎样在win10家庭版中使用Hyper-V
【无标题】转载
哈夫曼编码原理
Drools (2): drools quick start
Drools(3):Drools基础语法(1)
Drools (4): drools basic syntax (2)
Weekly tip 142: multi parameter constructors and explicit
Yolov5 improvements: add attention mechanism (video tutorial)
Kernel pwn 入门 (5)
Rust language - slice type (&[u8])
Contents mismatch at: 08000000H (Flash=FFH Required=00H) ! Too many errors to display !
Precious metal knowledge: lethal short-term secret script
Docker modifying the MySQL configuration file attached to the host does not take effect?
Analysis of strong tennis cup 2021 PWN competition -- baby_ diary