当前位置:网站首页>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 .
边栏推荐
- Ball Dropping
- C language must memorize code Encyclopedia
- [exercise-7] (UVA 10976) fractions again?! (fraction split)
- 树莓派4B安装opencv3.4.0
- [analysis of teacher Gao's software needs] collection of exercises and answers for level 20 cloud class
- 【练习-4】(Uva 11988)Broken Keyboard(破损的键盘) ==(链表)
- 快速转 TypeScript 指南
- 初入Redis
- 【练习-6】(PTA)分而治之
- Opencv learning log 13 corrosion, expansion, opening and closing operations
猜你喜欢
C language learning notes
Luogu P1102 A-B number pair (dichotomy, map, double pointer)
B - 代码派对(女生赛)
X-Forwarded-For详解、如何获取到客户端IP
Differential (one-dimensional, two-dimensional, three-dimensional) Blue Bridge Cup three body attack
Data storage in memory & loading into memory to make the program run
Ball Dropping
【高老师软件需求分析】20级云班课习题答案合集
信息安全-安全编排自动化与响应 (SOAR) 技术解析
快速转 TypeScript 指南
随机推荐
【练习-9】Zombie’s Treasure Chest
渗透测试 ( 3 ) --- Metasploit Framework ( MSF )
X-Forwarded-For详解、如何获取到客户端IP
Auto. Getting started with JS
C language is the watershed between low-level and high-level
0-1 knapsack problem (I)
Borg maze (bfs+ minimum spanning tree) (problem solving report)
区间和------离散化
Information security - security professional name | CVE | rce | POC | Vul | 0day
树莓派CSI/USB摄像头使用mjpg实现网页摄像头监控
Auto.js入门
Gartner:关于零信任网络访问最佳实践的五个建议
Penetration test (8) -- official document of burp Suite Pro
If you want to apply for a programmer, your resume should be written like this [essence summary]
socket通讯
Truck History
【高老师UML软件建模基础】20级云班课习题答案合集
最全编程语言在线 API 文档
mysql导入数据库报错 [Err] 1273 – Unknown collation: ‘utf8mb4_0900_ai_ci’
Vs2019 initial use