当前位置:网站首页>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 、
边栏推荐
- Research Report on market supply and demand and strategy of Chinese hospital cleaning chemicals industry
- 学习记录:USART—串口通讯
- LeetCode#19. Delete the penultimate node of the linked list
- Cost accounting [18]
- 7-1 懂的都懂 (20 分)
- 区间和------离散化
- China earth moving machinery market trend report, technical dynamic innovation and market forecast
- Cost accounting [13]
- 力扣刷题记录
- ucorelab3
猜你喜欢
C语言数组的概念
ucore lab7
入门C语言基础问答
动态规划前路径问题优化方式
LeetCode#19. Delete the penultimate node of the linked list
Crawler series of learning while tapping (3): URL de duplication strategy and Implementation
STM32学习记录:输入捕获应用
Learning record: STM32F103 clock system overview working principle
STM32 how to use stlink download program: light LED running light (Library version)
Learning record: how to perform PWM output
随机推荐
Cost accounting [18]
Accounting regulations and professional ethics [1]
Learning record: Tim - Basic timer
Crawler series (9): item+pipeline data storage
洛谷P1102 A-B数对(二分,map,双指针)
通俗地理解什么是编程语言
ucorelab3
Research Report on pharmaceutical R & D outsourcing service industry - market status analysis and development prospect forecast
LeetCode#198. raid homes and plunder houses
F - Birthday Cake(山东省赛)
Research Report on market supply and demand and strategy of geosynthetics industry in China
JS --- JS function and scope (II)
Accounting regulations and professional ethics [3]
Research Report on surgical fluid treatment industry - market status analysis and development prospect prediction
1010 things that college students majoring in it must do before graduation
Research Report on market supply and demand and strategy of Chinese hospital cleaning chemicals industry
Cost accounting [16]
Cost accounting [24]
ucorelab4
Learning record: use stm32f1 watchdog