当前位置:网站首页>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 .
边栏推荐
- Ball Dropping
- [exercise -11] 4 values why sum is 0 (and 4 values of 0)
- If you want to apply for a programmer, your resume should be written like this [essence summary]
- E. Breaking the Wall
- Opencv learning log 30 -- histogram equalization
- Programmers, what are your skills in code writing?
- 信息安全-威胁检测引擎-常见规则引擎底座性能比较
- 0-1背包問題(一)
- 【练习-10】 Unread Messages(未读消息)
- Find 3-friendly Integers
猜你喜欢
Web based photo digital printing website
Penetration test (1) -- necessary tools, navigation
STM32 learning record: LED light flashes (register version)
D - function (HDU - 6546) girls' competition
C language must memorize code Encyclopedia
渗透测试 ( 1 ) --- 必备 工具、导航
B - Code Party (girls' competition)
[analysis of teacher Gao's software needs] collection of exercises and answers for level 20 cloud class
[exercise-7] crossover answers
Penetration test (8) -- official document of burp Suite Pro
随机推荐
Alice and Bob (2021牛客暑期多校训练营1)
【练习4-1】Cake Distribution(分配蛋糕)
C language is the watershed between low-level and high-level
0-1 knapsack problem (I)
Gartner:关于零信任网络访问最佳实践的五个建议
Penetration test (4) -- detailed explanation of meterpreter command
渗透测试 ( 7 ) --- 漏洞扫描工具 Nessus
Information security - threat detection engine - common rule engine base performance comparison
基于web的照片数码冲印网站
[exercise-6] (PTA) divide and conquer
Understand what is a programming language in a popular way
[exercise-1] (UVA 673) parentheses balance/ balanced brackets (stack)
Opencv learning log 31 -- background difference
Research Report of peripheral venous catheter (pivc) industry - market status analysis and development prospect prediction
X-Forwarded-For详解、如何获取到客户端IP
Penetration test 2 --- XSS, CSRF, file upload, file inclusion, deserialization vulnerability
Research Report on shell heater industry - market status analysis and development prospect forecast
C basic grammar
想应聘程序员,您的简历就该这样写【精华总结】
STM32 how to use stlink download program: light LED running light (Library version)