当前位置:网站首页>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 、
边栏推荐
- Cost accounting [19]
- 1010 things that college students majoring in it must do before graduation
- STM32学习记录:LED灯闪烁(寄存器版)
- STM32如何使用STLINK下载程序:点亮LED跑马灯(库版本)
- 力扣刷题记录--完全背包问题(一)
- JS --- JS function and scope (II)
- 0-1 knapsack problem (I)
- Cost accounting [23]
- Accounting regulations and professional ethics [5]
- Shell脚本编程
猜你喜欢

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

STM32学习记录:玩转按键控制蜂鸣器和LED

C语言是低级和高级的分水岭

C语言必背代码大全

STM32学习记录:LED灯闪烁(寄存器版)

力扣刷题记录

基于web的照片数码冲印网站

STM32 how to use stlink download program: light LED running light (Library version)

Flex --- detailed explanation of flex layout attributes

D - Function(HDU - 6546)女生赛
随机推荐
Accounting regulations and professional ethics [4]
Research Report on market supply and demand and strategy of Chinese graphic screen printing equipment industry
China medical check valve market trend report, technical dynamic innovation and market forecast
1010 things that college students majoring in it must do before graduation
China's earthwork tire market trend report, technical dynamic innovation and market forecast
ucorelab4
Shell脚本编程
Report on the market trend, technological innovation and market forecast of printing and decorative paper in China
Matlab comprehensive exercise: application in signal and system
Cost accounting [19]
Flex --- detailed explanation of flex layout attributes
Cost accounting [13]
基于web的照片数码冲印网站
Learning records: serial communication and solutions to errors encountered
数据在内存中的存储&载入内存,让程序运行起来
JS --- all knowledge of JS objects and built-in objects (III)
Interesting drink
mysql导入数据库报错 [Err] 1273 – Unknown collation: ‘utf8mb4_0900_ai_ci’
C 基本语法
FSM和i2c实验报告