当前位置:网站首页>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 .
边栏推荐
- China's earthwork equipment market trend report, technical dynamic innovation and market forecast
- 学习记录:理解 SysTick系统定时器,编写延时函数
- Learning record: USART serial communication
- Cost accounting [14]
- Visual analysis of data related to crawling cat's eye essays "sadness flows upstream into a river" | the most moving film of Guo Jingming's five years
- Research Report on surgical fluid treatment industry - market status analysis and development prospect prediction
- Record of brushing questions with force deduction -- complete knapsack problem (I)
- LeetCode#53. Maximum subarray sum
- LeetCode#198. raid homes and plunder houses
- Cost accounting [13]
猜你喜欢
Learning record: use STM32 external input interrupt
学习记录:USART—串口通讯
JS --- BOM details of JS (V)
STM32 learning record: play with keys to control buzzer and led
学习记录:如何进行PWM 输出
Jupyter installation and use tutorial
csapp shell lab
Your wechat nickname may be betraying you
学习记录:STM32F103 时钟系统概述工作原理
洛谷P1102 A-B数对(二分,map,双指针)
随机推荐
Printing quality inspection and verification system Industry Research Report - market status analysis and development prospect forecast
JS --- JS function and scope (II)
Take you to use wxpy to create your own chat robot (plus wechat interface basic data visualization)
Cost accounting [14]
HDU - 6024 Building Shops(女生赛)
Alice and Bob (2021牛客暑期多校训练营1)
毕业才知道IT专业大学生毕业前必做的1010件事
Research Report on medical anesthesia machine industry - market status analysis and development prospect prediction
Learning record: understand systick system timer and write delay function
Find 3-friendly Integers
LeetCode#268. Missing numbers
学习记录:使用STM32F1看门狗
Cost accounting [24]
E. Breaking the Wall
Visual analysis of data related to crawling cat's eye essays "sadness flows upstream into a river" | the most moving film of Guo Jingming's five years
学习记录:TIM—基本定时器
学习记录:使用STM32外部输入中断
Indonesian medical sensor Industry Research Report - market status analysis and development prospect forecast
Cost accounting [15]
学习记录:如何进行PWM 输出