当前位置:网站首页>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 .
边栏推荐
- 力扣刷题记录--完全背包问题(一)
- Cost accounting [14]
- Accounting regulations and professional ethics [1]
- China medical check valve market trend report, technical dynamic innovation and market forecast
- China's earthwork tire market trend report, technical dynamic innovation and market forecast
- How to build a nail robot that can automatically reply
- C语言必背代码大全
- JS调用摄像头
- Learning record: understand systick system timer and write delay function
- Cost accounting [20]
猜你喜欢
Record of force deduction and question brushing
ucore lab 6
Jupyter installation and use tutorial
LeetCode#237. Delete nodes in the linked list
Crawler series of learning while tapping (3): URL de duplication strategy and Implementation
Learning record: use stm32f1 watchdog
FSM and I2C experiment report
csapp shell lab
LeetCode#36. Effective Sudoku
D - Function(HDU - 6546)女生赛
随机推荐
LeetCode#268. Missing numbers
Cost accounting [16]
Report on the market trend, technological innovation and market forecast of printing and decorative paper in China
Research Report on shell heater industry - market status analysis and development prospect forecast
Learning record: understand systick system timer and write delay function
cs零基础入门学习记录
Market trend report, technological innovation and market forecast of pneumonia drugs obtained by Chinese hospitals
学习记录:串口通信和遇到的错误解决方法
Research Report of cylindrical grinder industry - market status analysis and development prospect forecast
TCP的三次握手与四次挥手
China potato slicer market trend report, technical dynamic innovation and market forecast
Indonesian medical sensor Industry Research Report - market status analysis and development prospect forecast
区间和------离散化
ucorelab3
Optimization method of path problem before dynamic planning
0-1背包问题(一)
通俗地理解什么是编程语言
Lab 8 file system
ucorelab4
Research Report on surgical fluid treatment industry - market status analysis and development prospect prediction