当前位置:网站首页>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 .
边栏推荐
- Research Report on surgical fluid treatment industry - market status analysis and development prospect prediction
- Auto.js入门
- E. Breaking the Wall
- Hdu-6025-prime sequence (girls' competition)
- China exterior wall cladding (EWC) market trend report, technical dynamic innovation and market forecast
- Opencv learning log 14 - count the number of coins in the picture (regardless of overlap)
- 信息安全-安全专业名称|CVE|RCE|POC|VUL|0DAY
- The most complete programming language online API document
- Penetration testing (5) -- a collection of practical skills of scanning King nmap and penetration testing tools
- 最全编程语言在线 API 文档
猜你喜欢
7-1 understand everything (20 points)
洛谷P1102 A-B数对(二分,map,双指针)
Borg Maze (BFS+最小生成树)(解题报告)
X-Forwarded-For详解、如何获取到客户端IP
渗透测试 ( 2 ) --- 渗透测试系统、靶机、GoogleHacking、kali工具
Data storage in memory & loading into memory to make the program run
Nodejs+vue online fresh flower shop sales information system express+mysql
渗透测试 2 --- XSS、CSRF、文件上传、文件包含、反序列化漏洞
Borg maze (bfs+ minimum spanning tree) (problem solving report)
Penetration testing (5) -- a collection of practical skills of scanning King nmap and penetration testing tools
随机推荐
【练习-1】(Uva 673) Parentheses Balance/平衡的括号 (栈stack)
China's peripheral catheter market trend report, technological innovation and market forecast
区间和------离散化
Gartner:关于零信任网络访问最佳实践的五个建议
渗透测试 ( 4 ) --- Meterpreter 命令详解
Penetration test (8) -- official document of burp Suite Pro
Ball Dropping
Shell脚本编程
[exercise-7] crossover answers
Research Report of peripheral venous catheter (pivc) industry - market status analysis and development prospect prediction
信息安全-威胁检测-NAT日志接入威胁检测平台详细设计
Record of brushing questions with force deduction -- complete knapsack problem (I)
Essai de pénétration (1) - - outils nécessaires, navigation
【练习-8】(Uva 246)10-20-30==模拟
Analyse du format protobuf du rideau en temps réel et du rideau historique de la station B
Information security - threat detection - Flink broadcast stream broadcaststate dual stream merging application in filtering security logs
初入Redis
Shell Scripting
Luogu P1102 A-B number pair (dichotomy, map, double pointer)
Information security - security professional name | CVE | rce | POC | Vul | 0day