当前位置:网站首页>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 of cylindrical grinder industry - market status analysis and development prospect forecast
- 编程到底难在哪里?
- Matlab comprehensive exercise: application in signal and system
- Take you to use wxpy to create your own chat robot (plus wechat interface basic data visualization)
- ucore lab5
- 学习记录:使用STM32外部输入中断
- LeetCode#204. Count prime
- Research Report on medical anesthesia machine industry - market status analysis and development prospect prediction
- 程序员的你,有哪些炫技的代码写法?
- LeetCode#268. Missing numbers
猜你喜欢
Lab 8 file system
学习记录:理解 SysTick系统定时器,编写延时函数
用C语言写网页游戏
学习记录:USART—串口通讯
JS --- all knowledge of JS objects and built-in objects (III)
JS --- detailed explanation of JS facing objects (VI)
Determine the Photo Position
mysql导入数据库报错 [Err] 1273 – Unknown collation: ‘utf8mb4_0900_ai_ci’
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
Crawling cat's eye movie review, data visualization analysis source code operation instructions
随机推荐
Path problem before dynamic planning
JS --- BOM details of JS (V)
Research Report on printed circuit board (PCB) connector industry - market status analysis and development prospect forecast
学习记录:TIM—基本定时器
JS --- all basic knowledge of JS (I)
STM32如何使用STLINK下载程序:点亮LED跑马灯(库版本)
Research Report of cylindrical grinder industry - market status analysis and development prospect forecast
Research Report on market supply and demand and strategy of China's medical chair industry
cs零基础入门学习记录
力扣刷题记录
TCP的三次握手与四次挥手
Opencv learning log 12 binarization of Otsu method
区间和------离散化
D - Function(HDU - 6546)女生赛
Accounting regulations and professional ethics [1]
Perinatal Software Industry Research Report - market status analysis and development prospect forecast
JS调用摄像头
Find 3-friendly Integers
Research Report on medical toilet industry - market status analysis and development prospect forecast
ucore lab 2