当前位置:网站首页>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 .
边栏推荐
- [exercise-7] crossover answers
- Determine the Photo Position
- F - birthday cake (Shandong race)
- Opencv learning log 13 corrosion, expansion, opening and closing operations
- [exercise -11] 4 values why sum is 0 (and 4 values of 0)
- 入门C语言基础问答
- [exercise-2] (UVA 712) s-trees
- 【练习-9】Zombie’s Treasure Chest
- Optimization method of path problem before dynamic planning
- 想应聘程序员,您的简历就该这样写【精华总结】
猜你喜欢
渗透测试 ( 4 ) --- Meterpreter 命令详解
Pyside6 signal, slot
信息安全-威胁检测引擎-常见规则引擎底座性能比较
【练习-5】(Uva 839)Not so Mobile(天平)
Determine the Photo Position
[exercise-5] (UVA 839) not so mobile (balance)
C language must memorize code Encyclopedia
Penetration test (8) -- official document of burp Suite Pro
Gartner: five suggestions on best practices for zero trust network access
Nodejs+vue online fresh flower shop sales information system express+mysql
随机推荐
【练习-4】(Uva 11988)Broken Keyboard(破损的键盘) ==(链表)
Research Report of peripheral venous catheter (pivc) industry - market status analysis and development prospect prediction
b站 實時彈幕和曆史彈幕 Protobuf 格式解析
Information security - Analysis of security orchestration automation and response (soar) technology
渗透测试 ( 4 ) --- Meterpreter 命令详解
Information security - Epic vulnerability log4j vulnerability mechanism and preventive measures
信息安全-安全编排自动化与响应 (SOAR) 技术解析
D - Function(HDU - 6546)女生赛
[exercise-6] (UVA 725) division = = violence
C language learning notes
C basic grammar
【练习-9】Zombie’s Treasure Chest
X-Forwarded-For详解、如何获取到客户端IP
基于web的照片数码冲印网站
CS zero foundation introductory learning record
Matlab comprehensive exercise: application in signal and system
C 基本语法
Opencv learning log 31 -- background difference
Research Report on surgical fluid treatment industry - market status analysis and development prospect prediction
F - birthday cake (Shandong race)