当前位置:网站首页>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;
}边栏推荐
- Difference between shape and size ()
- QT listens for socket events and uses qsocketnotifier class
- one hundred and twenty-three million one hundred and twenty-three thousand one hundred and twenty-three
- Drools(4):Drools基础语法(2)
- NPM command
- How to delete a statement audit log?
- [QT] detailed explanation of *.pro, *.pri, *.prf, *.prl files
- Contents mismatch at: 08000000H (Flash=FFH Required=00H) ! Too many errors to display !
- Queue assistant | product update log in June 2022
- 【硬十宝典】——7.2【动态RAM】DDR4与DDR3区别解析
猜你喜欢

Curl post request on the server, using postman tool for parameter conversion

【硬十宝典】——7.1【动态RAM】DDR硬件设计要点

Realization of LED water lamp based on C51
![[today in history] July 18: Intel was founded; The first photo was posted on the world wide web; EBay spins off PayPal](/img/7d/7a01c8c6923077d6c201bf1ae02c8c.png)
[today in history] July 18: Intel was founded; The first photo was posted on the world wide web; EBay spins off PayPal

Analysis of strong tennis cup 2021 PWN competition -- baby_ diary

IDEA——使用@Slf4j打印日志

File server fastdfs

解决 Chrome 浏览器被毒霸篡改问题

针对前面文章的整改思路

XSS-labs(1-10)闯关详解
随机推荐
Benefits of the builder model
Precious metal knowledge: lethal short-term secret script
Manifest merger failed with multiple errors, see logs
docker修改挂载到宿主机上的mysql配置文件不生效?
【QT】怎样获得QTableView和QTableWidget的行数和列数
[Star Project] small hat aircraft War (IV)
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
An album has been released, from introductory practical demonstration to advanced live Q & A, playing with container service so easy~
Celery takes up large memory - memory leak
LTS(Light-Task-Scheduler)
NPM command
Shell programming
Overview of new features of es11, ES12 and es13
C # use log4net plug-in to output logs to files
Drools (4): drools basic syntax (2)
怎样在win10家庭版中使用Hyper-V
Leetcode question brushing 1: topic classification
MySql 执行计划
Kubernetes scheduling concept and workflow
LeetCode刷题1:题目分类