当前位置:网站首页>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
- 屏:框贴、0贴合、全贴合
- Binary tree knowledge summary
- [749. Isolate virus]
- Check the top 10 best graphics software of the year, meet 99% of your chart needs, and collect it quickly
- Benefits of the builder model
- Analysis of strong tennis cup 2021 PWN competition -- baby_ diary
- 常用的cmd指令
- 火焰图分析Flink反压
- <二> objectARX开发:创建和编辑基本图形对象
猜你喜欢

Drools (2): drools quick start

二叉树知识总结

Check the top 10 best graphics software of the year, meet 99% of your chart needs, and collect it quickly

Yolov5 improvements: add attention mechanism (video tutorial)

Contents mismatch at: 08000000H (Flash=FFH Required=00H) ! Too many errors to display !

Drools(3):Drools基础语法(1)

Is the passenger flow always low? There is something wrong with the location of your store!

NPM command

Question: can't download sh shellcheck Please install it manually and some commands of shell script

哈夫曼编码原理
随机推荐
Agile and tidy way
docker修改挂载到宿主机上的mysql配置文件不生效?
Delete ^m from VIM
MySQL execution plan
软考可以查成绩了,2022年上半年软考成绩查询入口已开通
What to pay attention to when using German chicks for the first time
Drools(3):Drools基础语法(1)
[QT] detailed explanation of *.pro, *.pri, *.prf, *.prl files
Summarize and learn STM32 to create project template
强网杯2021 pwn 赛题解析——baby_diary
An album has been released, from introductory practical demonstration to advanced live Q & A, playing with container service so easy~
Yolov6 target detection practice: training your own data set (video tutorial)
Is the passenger flow always low? There is something wrong with the location of your store!
树莓派连接天猫精灵音箱通过蓝牙播放音乐的方法
Kubernetes scheduling concept and workflow
Drools(2):Drools快速入门
替换license是否要重启数据库?
[Star Project] small hat aircraft War (III)
Kernel pwn 入门 (5)
Database performance test (MySQL)