当前位置:网站首页>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 .
边栏推荐
- Information security - security professional name | CVE | rce | POC | Vul | 0day
- Analysis of protobuf format of real-time barrage and historical barrage at station B
- STM32 how to use stlink download program: light LED running light (Library version)
- [exercise-9] Zombie's Treasury test
- China potato slicer market trend report, technical dynamic innovation and market forecast
- CS zero foundation introductory learning record
- Perform general operations on iptables
- Gartner:关于零信任网络访问最佳实践的五个建议
- China's earthwork tire market trend report, technical dynamic innovation and market forecast
- Opencv learning log 30 -- histogram equalization
猜你喜欢

b站 實時彈幕和曆史彈幕 Protobuf 格式解析

Luogu P1102 A-B number pair (dichotomy, map, double pointer)

STM32 learning record: LED light flashes (register version)

渗透测试 ( 7 ) --- 漏洞扫描工具 Nessus

Optimization method of path problem before dynamic planning

Write web games in C language

C language is the watershed between low-level and high-level

滲透測試 ( 1 ) --- 必備 工具、導航

信息安全-安全编排自动化与响应 (SOAR) 技术解析

Penetration test (8) -- official document of burp Suite Pro
随机推荐
Record of force deduction and question brushing
Record of brushing questions with force deduction -- complete knapsack problem (I)
Gartner:关于零信任网络访问最佳实践的五个建议
洛谷P1102 A-B数对(二分,map,双指针)
Gartner: five suggestions on best practices for zero trust network access
渗透测试 ( 5 ) --- 扫描之王 nmap、渗透测试工具实战技巧合集
渗透测试 ( 3 ) --- Metasploit Framework ( MSF )
[exercise -10] unread messages
Data storage in memory & loading into memory to make the program run
【练习-2】(Uva 712) S-Trees (S树)
0-1 knapsack problem (I)
Differential (one-dimensional, two-dimensional, three-dimensional) Blue Bridge Cup three body attack
【练习-6】(Uva 725)Division(除法)== 暴力
C language is the watershed between low-level and high-level
[exercise-4] (UVA 11988) broken keyboard = = (linked list)
Ball Dropping
mysql导入数据库报错 [Err] 1273 – Unknown collation: ‘utf8mb4_0900_ai_ci’
[exercise-8] (UVA 246) 10-20-30== simulation
【练习-7】(Uva 10976)Fractions Again?!(分数拆分)
Perform general operations on iptables