当前位置:网站首页>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 .
边栏推荐
- LeetCode#268. Missing numbers
- Take you to use wxpy to create your own chat robot (plus wechat interface basic data visualization)
- Cost accounting [14]
- Market trend report, technical innovation and market forecast of Chinese hospital respiratory humidification equipment
- LeetCode#19. Delete the penultimate node of the linked list
- Research Report on market supply and demand and strategy of Chinese graphic screen printing equipment industry
- 7-1 懂的都懂 (20 分)
- JS --- detailed explanation of JS facing objects (VI)
- Accounting regulations and professional ethics [2]
- Accounting regulations and professional ethics [4]
猜你喜欢

Learning record: Tim - capacitive key detection

LeetCode#36. Effective Sudoku

Jupyter installation and use tutorial

Learning record: understand systick system timer and write delay function

学习记录:STM32F103 时钟系统概述工作原理

Learning record: STM32F103 clock system overview working principle

JS --- all basic knowledge of JS (I)

Learning record: USART serial communication
![mysql导入数据库报错 [Err] 1273 – Unknown collation: ‘utf8mb4_0900_ai_ci’](/img/e6/f4a696179282fe1f4193410c5a493a.png)
mysql导入数据库报错 [Err] 1273 – Unknown collation: ‘utf8mb4_0900_ai_ci’

用C语言写网页游戏
随机推荐
用C语言写网页游戏
Indonesian medical sensor Industry Research Report - market status analysis and development prospect forecast
How to build a nail robot that can automatically reply
Crawler series of learning while tapping (3): URL de duplication strategy and Implementation
Cost accounting [24]
CS zero foundation introductory learning record
编程到底难在哪里?
Cost accounting [19]
Learning record: USART serial communication
STM32 learning record: LED light flashes (register version)
Research Report on market supply and demand and strategy of China's medical chair industry
STM32 learning record: play with keys to control buzzer and led
Cost accounting [18]
Research Report on market supply and demand and strategy of China's land incineration plant industry
csapp shell lab
STM32学习记录:输入捕获应用
Research Report on medical toilet industry - market status analysis and development prospect forecast
学习记录:使用STM32外部输入中断
ucore lab 6
ucorelab4