当前位置:网站首页>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 .
边栏推荐
- 【练习-8】(Uva 246)10-20-30==模拟
- [exercise-7] crossover answers
- Determine the Photo Position
- Shell脚本编程
- Information security - threat detection - detailed design of NAT log access threat detection platform
- [teacher Gao UML software modeling foundation] collection of exercises and answers for level 20 cloud class
- 1010 things that college students majoring in it must do before graduation
- 快速转 TypeScript 指南
- 【练习-4】(Uva 11988)Broken Keyboard(破损的键盘) ==(链表)
- E. Breaking the Wall
猜你喜欢
Penetration test (4) -- detailed explanation of meterpreter command
frida hook so层、protobuf 数据解析
Information security - Analysis of security orchestration automation and response (soar) technology
PySide6 信号、槽
Penetration test (2) -- penetration test system, target, GoogleHacking, Kali tool
渗透测试 2 --- XSS、CSRF、文件上传、文件包含、反序列化漏洞
渗透测试 ( 2 ) --- 渗透测试系统、靶机、GoogleHacking、kali工具
Determine the Photo Position
树莓派4B安装opencv3.4.0
信息安全-威胁检测-NAT日志接入威胁检测平台详细设计
随机推荐
HDU - 6024 building shops (girls' competition)
B - 代码派对(女生赛)
快速转 TypeScript 指南
PySide6 信号、槽
Data storage in memory & loading into memory to make the program run
Perform general operations on iptables
socket通讯
【练习-10】 Unread Messages(未读消息)
[exercise-6] (PTA) divide and conquer
JS call camera
MySQL import database error [err] 1273 - unknown collation: 'utf8mb4_ 0900_ ai_ ci’
【练习-9】Zombie’s Treasure Chest
F - birthday cake (Shandong race)
China's earthwork tire market trend report, technical dynamic innovation and market forecast
Borg maze (bfs+ minimum spanning tree) (problem solving report)
HDU-6025-Coprime Sequence(女生赛)
Gartner: five suggestions on best practices for zero trust network access
Basic Q & A of introductory C language
SSM框架常用配置文件
树莓派CSI/USB摄像头使用mjpg实现网页摄像头监控