当前位置:网站首页>Opencv learning log 16 paperclip count
Opencv learning log 16 paperclip count
2022-07-06 15:43:00 【@Spring sauce】
Preface
This article is mainly about opencv How to count the number of paper clips in image processing .
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, resover_sign, Matstate, center, 8, CV_32S); // Connected domain markers
int line = 0;
int clipnum = 0;
int i;
line = Matstate.rows;
for (i = 0; i < Matstate.rows; i++)
{
if (Matstate.at<int>(i, 4) >= 2000&& Matstate.at<int>(i, 4)<=8000)
{
clipnum = clipnum + 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, rect, CV_RGB(255, 255, 255), 1, 8, 0);
}
}
std::cout << clipnum << std::endl;
imshow("resover", resover);
waitKey(0);
}
summary
1. The code can run directly , If you don't understand, please leave a message 、
边栏推荐
- 学习记录:理解 SysTick系统定时器,编写延时函数
- C 基本语法
- Research Report on market supply and demand and strategy of China's Medical Automation Industry
- Cost accounting [14]
- Perinatal Software Industry Research Report - market status analysis and development prospect forecast
- cs零基础入门学习记录
- Cost accounting [23]
- 学习记录:使用STM32外部输入中断
- Scoring system based on 485 bus
- Research Report of cylindrical grinder industry - market status analysis and development prospect forecast
猜你喜欢
随机推荐
csapp shell lab
Market trend report, technological innovation and market forecast of pneumonia drugs obtained by Chinese hospitals
C语言是低级和高级的分水岭
Cost accounting [14]
LeetCode#198. raid homes and plunder houses
ucorelab3
Cost accounting [13]
入门C语言基础问答
Indonesian medical sensor Industry Research Report - market status analysis and development prospect forecast
JS --- all basic knowledge of JS (I)
Market trend report, technical innovation and market forecast of lip care products in China and Indonesia
学习记录:TIM—基本定时器
C 基本语法
Printing quality inspection and verification system Industry Research Report - market status analysis and development prospect forecast
Cost accounting [22]
基于web的照片数码冲印网站
学习记录:如何进行PWM 输出
学习记录:使用STM32F1看门狗
Crawler series (9): item+pipeline data storage
E. Breaking the Wall