当前位置:网站首页>Opencv learning log 14 - count the number of coins in the picture (regardless of overlap)
Opencv learning log 14 - count the number of coins in the picture (regardless of overlap)
2022-07-06 15:43:00 【@Spring sauce】
Preface
This article mainly describes how to count the number of coins 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 res2Mat;
cv::Mat Matstate;
cv::Mat center;
//adaptiveThreshold(srcMat, resMat, 255, ADAPTIVE_THRESH_GAUSSIAN_C, THRESH_BINARY_INV, 15, 10);// Adaptive binarization
threshold(srcMat, resMat, 100, 255, THRESH_BINARY);
connectedComponentsWithStats(resMat, res2Mat, Matstate, center, 8, CV_32S); // Connected domain markers
int line = 0;
line = Matstate.rows;
//cv::Mat B = Matstate.rowRange(0, 3).clone(); // extract 0 To 2 That's ok
int i;
int j;
int coinnum = 0;
for (i = 0; i < Matstate.rows; i++)
{
if (Matstate.at<int>(i, 4) >= 1000 && Matstate.at<int>(i, 4) <= 10000)
{
coinnum = coinnum + 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(resMat, rect, CV_RGB(255, 255, 255), 1, 8, 0);
}
}
std::cout << coinnum << std::endl;
imshow("resMat", resMat);
waitKey(0);
}
summary
1. The code can run directly , If you don't understand, please leave a message .
边栏推荐
- ucore lab5
- Report on the market trend, technological innovation and market forecast of printing and decorative paper in China
- China's PCB connector market trend report, technological innovation and market forecast
- 学习记录:如何进行PWM 输出
- 12306: mom, don't worry about me getting the ticket any more (1)
- 1010 things that college students majoring in it must do before graduation
- LeetCode#412. Fizz Buzz
- Accounting regulations and professional ethics [4]
- LeetCode#198. raid homes and plunder houses
- Learning records: serial communication and solutions to errors encountered
猜你喜欢
STM32 learning record: play with keys to control buzzer and led
Learning record: Tim - Basic timer
FSM和i2c实验报告
LeetCode#19. Delete the penultimate node of the linked list
力扣刷题记录
How to build a nail robot that can automatically reply
STM32學習記錄:輸入捕獲應用
STM32如何使用STLINK下载程序:点亮LED跑马灯(库版本)
UCORE Lab 1 system software startup process
Record of force deduction and question brushing
随机推荐
UCORE Lab 1 system software startup process
Cost accounting [13]
Find 3-friendly Integers
Research Report on market supply and demand and strategy of Chinese hospital cleaning chemicals industry
Cost accounting [13]
E. Breaking the Wall
LeetCode#36. Effective Sudoku
Cost accounting [18]
编程到底难在哪里?
Research Report on printed circuit board (PCB) connector industry - market status analysis and development prospect forecast
LeetCode#62. Different paths
MATLAB实例:阶跃函数的两种表达方式
Accounting regulations and professional ethics [5]
cs零基础入门学习记录
Es6--- two methods of capturing promise status as failed
D - Function(HDU - 6546)女生赛
ucorelab4
Crawler series of learning while tapping (3): URL de duplication strategy and Implementation
Cost accounting [15]
Hospital privacy screen Industry Research Report - market status analysis and development prospect forecast