当前位置:网站首页>Opencv learning log 26 -- detect circular holes and mark them
Opencv learning log 26 -- detect circular holes and mark them
2022-07-06 16:07:00 【@Spring sauce】
Preface
This article is mainly about opencv In image processing, circular holes are detected and marked
One 、 Code
// Check the round hole and mark it
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
cv::Mat dst;
cv::Mat dstbin;
cv::Mat dsttemp;
cv::Mat finalpicture;
cv::Mat src = imread("C://Users//john//Desktop//1.jpg");
cv::Mat srcgray = imread("C://Users//john//Desktop//1.jpg", 0);
threshold(srcgray, dstbin, 100, 255, THRESH_OTSU); // Dajin law
src.copyTo(dst);
bitwise_not(dstbin, dsttemp);
vector<vector<Point>> contours;
vector<Vec4i> hirearchy;
findContours(dsttemp, contours, CV_RETR_LIST, CV_CHAIN_APPROX_NONE);
int num = contours.size();
cout << num << endl;
for (int i = 0; i < num; i++)
{
//RotatedRect rbox = minAreaRect(contours[i]);
//cv::Point2f vtx[4];
//rbox.points(vtx);
//cout << vtx << endl;
//if((vtx[0].x-vtx[1].x) + (vtx[0].y - vtx[1].y) ^ 2)
//cout << contours[i] << endl;
float area = contourArea(contours[i]);// Calculate the contour area
float len = arcLength(contours[i], true);// Calculate contour perimeter
float roundness = (4 * CV_PI * area) / (len * len);// Roundness
// cout << area << endl;
if (roundness > 0.5&&area>=100)
{
drawContours(dst, contours, i, Scalar(255, 0, 0), -1, 8);
}
//drawContours(dst,contours, i, Scalar(255, 255, 255),-1,8, InputArray hierarchy = noArray(), int maxLevel = INT_MAX, Point offset = Point())
}
cv::imshow("dsttemp", dsttemp);
cv::imshow("dst", dst);
//cv::imshow("src", src);
//cv::imshow("dsttemp", dsttemp);
waitKey(0);
}
summary
1. The code can run directly , If you don't understand, please leave a message .
2. Missing material pictures , Follow up, thank you .
边栏推荐
- Borg maze (bfs+ minimum spanning tree) (problem solving report)
- 信息安全-安全专业名称|CVE|RCE|POC|VUL|0DAY
- Analyse du format protobuf du rideau en temps réel et du rideau historique de la station B
- 信息安全-史诗级漏洞Log4j的漏洞机理和防范措施
- Ball Dropping
- Shell脚本编程
- F - Birthday Cake(山东省赛)
- Gartner:关于零信任网络访问最佳实践的五个建议
- Gartner: five suggestions on best practices for zero trust network access
- Nodejs+vue online fresh flower shop sales information system express+mysql
猜你喜欢

Information security - threat detection - Flink broadcast stream broadcaststate dual stream merging application in filtering security logs

STM32 how to use stlink download program: light LED running light (Library version)

信息安全-威胁检测-NAT日志接入威胁检测平台详细设计

Penetration test (7) -- vulnerability scanning tool Nessus

用C语言写网页游戏

信息安全-威胁检测-flink广播流BroadcastState双流合并应用在过滤安全日志
![[exercise-7] crossover answers](/img/66/3dcba2e70a4cd899fbd78ce4d5bea2.png)
[exercise-7] crossover answers

1010 things that college students majoring in it must do before graduation

Determine the Photo Position

渗透测试 ( 2 ) --- 渗透测试系统、靶机、GoogleHacking、kali工具
随机推荐
Alice and Bob (2021牛客暑期多校训练营1)
Hdu-6025-prime sequence (girls' competition)
b站 實時彈幕和曆史彈幕 Protobuf 格式解析
[exercise-9] Zombie's Treasury test
[exercise-7] (UVA 10976) fractions again?! (fraction split)
【练习-11】4 Values whose Sum is 0(和为0的4个值)
Information security - security professional name | CVE | rce | POC | Vul | 0day
Borg maze (bfs+ minimum spanning tree) (problem solving report)
区间和------离散化
渗透测试 2 --- XSS、CSRF、文件上传、文件包含、反序列化漏洞
初入Redis
信息安全-安全专业名称|CVE|RCE|POC|VUL|0DAY
Essai de pénétration (1) - - outils nécessaires, navigation
B - 代码派对(女生赛)
渗透测试 ( 3 ) --- Metasploit Framework ( MSF )
基于web的照片数码冲印网站
洛谷P1102 A-B数对(二分,map,双指针)
Analyse du format protobuf du rideau en temps réel et du rideau historique de la station B
渗透测试 ( 8 ) --- Burp Suite Pro 官方文档
C language learning notes