当前位置:网站首页>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 medical anesthesia machine industry - market status analysis and development prospect prediction
- STM32如何使用STLINK下载程序:点亮LED跑马灯(库版本)
- LeetCode#36. Effective Sudoku
- Research Report on market supply and demand and strategy of China's Medical Automation Industry
- JS --- BOM details of JS (V)
- ucore lab 2
- D - Function(HDU - 6546)女生赛
- 学习记录:USART—串口通讯
- STM32学习记录:玩转按键控制蜂鸣器和LED
- Research Report on market supply and demand and strategy of China's medical chair industry
猜你喜欢

JS --- detailed explanation of JS facing objects (VI)

Learning record: understand systick system timer and write delay function

LeetCode#19. Delete the penultimate node of the linked list

学习记录:使用STM32F1看门狗

Borg Maze (BFS+最小生成树)(解题报告)

Nodejs+vue网上鲜花店销售信息系统express+mysql

学习记录:串口通信和遇到的错误解决方法

C语言学习笔记

Learning record: how to perform PWM output

学习记录:理解 SysTick系统定时器,编写延时函数
随机推荐
Cost accounting [24]
毕业才知道IT专业大学生毕业前必做的1010件事
Research Report on pharmaceutical R & D outsourcing service industry - market status analysis and development prospect forecast
学习记录:STM32F103 时钟系统概述工作原理
学习记录:TIM—基本定时器
csapp shell lab
程序员的你,有哪些炫技的代码写法?
China's earthwork tire market trend report, technical dynamic innovation and market forecast
Research Report of cylindrical grinder industry - market status analysis and development prospect forecast
nodejs爬虫
China's earthwork equipment market trend report, technical dynamic innovation and market forecast
JS --- all knowledge of JS objects and built-in objects (III)
E. Breaking the Wall
7-1 懂的都懂 (20 分)
HDU-6025-Coprime Sequence(女生赛)
学习记录:使用STM32外部输入中断
Learning record: Tim - capacitive key detection
Opencv learning log 12 binarization of Otsu method
JS --- detailed explanation of JS facing objects (VI)
编程到底难在哪里?