当前位置:网站首页>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 .
边栏推荐
- 渗透测试 2 --- XSS、CSRF、文件上传、文件包含、反序列化漏洞
- China's earthwork equipment market trend report, technical dynamic innovation and market forecast
- Opencv learning log 16 paperclip count
- Opencv learning log 32 edge extraction
- Penetration testing (5) -- a collection of practical skills of scanning King nmap and penetration testing tools
- Information security - Analysis of security orchestration automation and response (soar) technology
- 信息安全-威胁检测引擎-常见规则引擎底座性能比较
- 【练习-6】(Uva 725)Division(除法)== 暴力
- 信息安全-威胁检测-NAT日志接入威胁检测平台详细设计
- China exterior wall cladding (EWC) market trend report, technical dynamic innovation and market forecast
猜你喜欢
STM32 learning record: LED light flashes (register version)
Penetration test (4) -- detailed explanation of meterpreter command
差分(一维,二维,三维) 蓝桥杯三体攻击
入门C语言基础问答
渗透测试 ( 3 ) --- Metasploit Framework ( MSF )
快速转 TypeScript 指南
b站 实时弹幕和历史弹幕 Protobuf 格式解析
Essai de pénétration (1) - - outils nécessaires, navigation
渗透测试 2 --- XSS、CSRF、文件上传、文件包含、反序列化漏洞
Pyside6 signal, slot
随机推荐
Web based photo digital printing website
【练习-9】Zombie’s Treasure Chest
[exercise -10] unread messages
[exercise-1] (UVA 673) parentheses balance/ balanced brackets (stack)
7-1 understand everything (20 points)
Differential (one-dimensional, two-dimensional, three-dimensional) Blue Bridge Cup three body attack
Hdu-6025-prime sequence (girls' competition)
渗透测试 ( 7 ) --- 漏洞扫描工具 Nessus
Gartner:关于零信任网络访问最佳实践的五个建议
MySQL import database error [err] 1273 - unknown collation: 'utf8mb4_ 0900_ ai_ ci’
Information security - Analysis of security orchestration automation and response (soar) technology
Opencv learning log 33 Gaussian mean filtering
socket通讯
China's earthwork tire market trend report, technical dynamic innovation and market forecast
对iptables进行常规操作
MySQL grants the user the operation permission of the specified content
Data storage in memory & loading into memory to make the program run
C language is the watershed between low-level and high-level
E. Breaking the Wall
[teacher Gao UML software modeling foundation] collection of exercises and answers for level 20 cloud class