当前位置:网站首页>Opencv learning log 28 -- detect the red cup cover
Opencv learning log 28 -- detect the red cup cover
2022-07-06 16:07:00 【@Spring sauce】
Preface
This article is mainly about opencv Detection of medium red cup cover .
One 、 Detect the red cup cover
// Third question Detect the red cup cover
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
// VideoCapture cap(0);
double scale = 0.5;
//0-188
// Skin colour
double i_minH = 150;
double i_maxH = 255;
//0-255
double i_minS = 150;
double i_maxS = 255;
//0-255
double i_minV = 150;
double i_maxV = 255;
while (1)
{
Mat frame;
Mat hsvMat;
Mat detectMat;
frame= imread("C://Users//john//Desktop//2.jpg");;
Size ResImgSiz = Size(frame.cols*scale, frame.rows*scale);
Mat rFrame = Mat(ResImgSiz, frame.type());
resize(frame, rFrame, ResImgSiz, INTER_LINEAR);
cvtColor(rFrame, hsvMat, COLOR_BGR2HSV);
rFrame.copyTo(detectMat);
cv::inRange(hsvMat, Scalar(i_minH, i_minS, i_minV), Scalar(i_maxH, i_maxS, i_maxV), detectMat);
vector<vector<Point>> contours;
vector<Vec4i> hirearchy;
findContours(detectMat, contours, CV_RETR_LIST, CV_CHAIN_APPROX_NONE);
int num = contours.size();
Point2f rect[4];
for (int i = 0; i < num; i++)
{
RotatedRect rbox = minAreaRect(contours[i]);
///cout << rbox << endl;
int area = contourArea(contours[i]);// Calculate the contour area
rbox.points(rect); // Copy the four ends of the smallest circumscribed rectangle to rect Array
if (area >= 40)
{
drawContours(detectMat, contours, i, Scalar(255, 0, 0), -1, 8);
for (int j = 0; j < 4; j++)
{
line(rFrame, rect[j], rect[(j + 1) % 4], Scalar(255, 255, 255), 2, 8); // Draw the smallest outer edge of each rectangle
}
}
}
imshow("while: in the range ", detectMat);
imshow("frame", rFrame);
waitKey(30);
}
}
summary
1. The code can run directly , If you don't understand, please leave a message .
边栏推荐
- Borg maze (bfs+ minimum spanning tree) (problem solving report)
- b站 實時彈幕和曆史彈幕 Protobuf 格式解析
- 信息安全-威胁检测-NAT日志接入威胁检测平台详细设计
- Opencv learning log 12 binarization of Otsu method
- 渗透测试 ( 7 ) --- 漏洞扫描工具 Nessus
- 信息安全-安全专业名称|CVE|RCE|POC|VUL|0DAY
- Alice and Bob (2021 Niuke summer multi school training camp 1)
- Interval sum ----- discretization
- Penetration test (8) -- official document of burp Suite Pro
- Truck History
猜你喜欢

Determine the Photo Position

Gartner:关于零信任网络访问最佳实践的五个建议

Programmers, what are your skills in code writing?

7-1 懂的都懂 (20 分)

Essai de pénétration (1) - - outils nécessaires, navigation
![[exercise-7] crossover answers](/img/66/3dcba2e70a4cd899fbd78ce4d5bea2.png)
[exercise-7] crossover answers

差分(一维,二维,三维) 蓝桥杯三体攻击

Borg maze (bfs+ minimum spanning tree) (problem solving report)

Penetration test (3) -- Metasploit framework (MSF)
![MySQL import database error [err] 1273 - unknown collation: 'utf8mb4_ 0900_ ai_ ci’](/img/e6/f4a696179282fe1f4193410c5a493a.png)
MySQL import database error [err] 1273 - unknown collation: 'utf8mb4_ 0900_ ai_ ci’
随机推荐
【练习-10】 Unread Messages(未读消息)
Essai de pénétration (1) - - outils nécessaires, navigation
C language must memorize code Encyclopedia
Information security - Analysis of security orchestration automation and response (soar) technology
Path problem before dynamic planning
MySQL import database error [err] 1273 - unknown collation: 'utf8mb4_ 0900_ ai_ ci’
D - Function(HDU - 6546)女生赛
Research Report of peripheral venous catheter (pivc) industry - market status analysis and development prospect prediction
Interesting drink
China earth moving machinery market trend report, technical dynamic innovation and market forecast
Opencv learning log 32 edge extraction
渗透测试 ( 1 ) --- 必备 工具、导航
Gartner: five suggestions on best practices for zero trust network access
SSM框架常用配置文件
Interesting drink
Truck History
D - function (HDU - 6546) girls' competition
mysql导入数据库报错 [Err] 1273 – Unknown collation: ‘utf8mb4_0900_ai_ci’
E. Breaking the Wall
Analysis of protobuf format of real-time barrage and historical barrage at station B