当前位置:网站首页>Opencv learning log 15 count the number of solder joints and output
Opencv learning log 15 count the number of solder joints and output
2022-07-06 15:43:00 【@Spring sauce】
Preface
This article is mainly about opencv How to count and output the number of solder joints in .
One 、 Code
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
int main()
{
cv::Mat srcMat = imread("C://Users//john//Desktop//1.jpg", 0);
cv::Mat resMat;
cv::Mat resover;
cv::Mat resover_dec;
cv::Mat resover_sign;
cv::Mat Matstate;
cv::Mat center;
cv::Mat kernel(14, 14, CV_8UC1);
// imshow("src", srcMat);
threshold(srcMat, resMat, 100, 255, THRESH_OTSU); // Dajin law
bitwise_not(resMat, resover);
imshow("resover", resover);
morphologyEx(resover, resover_dec, 2, kernel, Point(0, 0), 1, BORDER_CONSTANT, morphologyDefaultBorderValue());// corrosion
imshow("resover_dec", resover_dec);
connectedComponentsWithStats(resover_dec, resover_sign, Matstate, center, 8, CV_32S); // Connected domain markers
int line = 0;
int dotnum = 0;
int i;
line = Matstate.rows;
for (i = 0; i < Matstate.rows; i++)
{
if (Matstate.at<int>(i, 4) >= 100)
{
dotnum = dotnum + 1;
cv::Rect rect;
rect.x = Matstate.at<int>(i, 0);
rect.y = Matstate.at<int>(i, 1);
rect.width = Matstate.at<int>(i, 2);
rect.height = Matstate.at<int>(i, 3);
rectangle(resover_dec, rect, CV_RGB(255, 255, 255), 1, 8, 0);
}
}
std::cout << dotnum << std::endl;
imshow("resover_dec", resover_dec);
waitKey(0);
}
summary
1. The code can run directly , If you don't understand, please leave a message .
边栏推荐
- 想应聘程序员,您的简历就该这样写【精华总结】
- Record of force deduction and question brushing
- C语言数组的概念
- 编程到底难在哪里?
- LeetCode#198. raid homes and plunder houses
- Research Report on market supply and demand and strategy of China's land incineration plant industry
- LeetCode#36. Effective Sudoku
- Research Report on medical toilet industry - market status analysis and development prospect forecast
- Opencv learning log 12 binarization of Otsu method
- Optimization method of path problem before dynamic planning
猜你喜欢
随机推荐
动态规划前路径问题优化方式
Record of brushing questions with force deduction -- complete knapsack problem (I)
Es6--- two methods of capturing promise status as failed
Cost accounting [21]
LeetCode#62. Different paths
Alice and Bob (2021牛客暑期多校训练营1)
C 基本语法
Accounting regulations and professional ethics [5]
Matlab example: two expressions of step function
Cost accounting [14]
Research Report on surgical fluid treatment industry - market status analysis and development prospect prediction
Cost accounting [23]
Research Report on market supply and demand and strategy of Chinese graphic screen printing equipment industry
STM32学习记录:玩转按键控制蜂鸣器和LED
Printing quality inspection and verification system Industry Research Report - market status analysis and development prospect forecast
Learning record: understand systick system timer and write delay function
Hospital privacy screen Industry Research Report - market status analysis and development prospect forecast
Accounting regulations and professional ethics [4]
TCP的三次握手与四次挥手
JS --- all knowledge of JS objects and built-in objects (III)