当前位置:网站首页>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 .
边栏推荐
- Gartner:关于零信任网络访问最佳实践的五个建议
- 7-1 懂的都懂 (20 分)
- PySide6 信号、槽
- Basic Q & A of introductory C language
- C basic grammar
- b站 實時彈幕和曆史彈幕 Protobuf 格式解析
- [exercise-7] (UVA 10976) fractions again?! (fraction split)
- Ball Dropping
- Opencv learning log 33 Gaussian mean filtering
- Information security - Analysis of security orchestration automation and response (soar) technology
猜你喜欢

STM32 learning record: LED light flashes (register version)

Information security - Analysis of security orchestration automation and response (soar) technology

渗透测试 ( 2 ) --- 渗透测试系统、靶机、GoogleHacking、kali工具
Frida hook so layer, protobuf data analysis

Write web games in C language
frida hook so层、protobuf 数据解析

信息安全-史诗级漏洞Log4j的漏洞机理和防范措施

Information security - threat detection - detailed design of NAT log access threat detection platform

b站 实时弹幕和历史弹幕 Protobuf 格式解析

渗透测试 ( 5 ) --- 扫描之王 nmap、渗透测试工具实战技巧合集
随机推荐
[teacher Gao UML software modeling foundation] collection of exercises and answers for level 20 cloud class
[exercise-4] (UVA 11988) broken keyboard = = (linked list)
China's earthwork tire market trend report, technical dynamic innovation and market forecast
渗透测试 ( 5 ) --- 扫描之王 nmap、渗透测试工具实战技巧合集
【练习-6】(PTA)分而治之
C language is the watershed between low-level and high-level
Matlab comprehensive exercise: application in signal and system
Shell Scripting
Analyse du format protobuf du rideau en temps réel et du rideau historique de la station B
Interesting drink
b站 实时弹幕和历史弹幕 Protobuf 格式解析
Differential (one-dimensional, two-dimensional, three-dimensional) Blue Bridge Cup three body attack
Borg maze (bfs+ minimum spanning tree) (problem solving report)
Opencv learning log 30 -- histogram equalization
对iptables进行常规操作
E. Breaking the Wall
X-Forwarded-For详解、如何获取到客户端IP
C language learning notes
渗透测试 ( 2 ) --- 渗透测试系统、靶机、GoogleHacking、kali工具
0 - 1 problème de sac à dos (1)