当前位置:网站首页>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 .
边栏推荐
- Accounting regulations and professional ethics [1]
- Research Report on market supply and demand and strategy of China's Medical Automation Industry
- 程序员的你,有哪些炫技的代码写法?
- STM32 learning record: play with keys to control buzzer and led
- STM32 learning record: LED light flashes (register version)
- JS --- all knowledge of JS objects and built-in objects (III)
- C语言数组的概念
- Record of brushing questions with force deduction -- complete knapsack problem (I)
- 动态规划前路径问题
- Research Report on market supply and demand and strategy of China's earth drilling industry
猜你喜欢
随机推荐
HDU - 6024 Building Shops(女生赛)
ucore lab7
STM32學習記錄:輸入捕獲應用
JS --- all basic knowledge of JS (I)
Learning record: use stm32f1 watchdog
STM32学习记录:LED灯闪烁(寄存器版)
The wechat red envelope cover designed by the object is free! 16888
Research Report on shell heater industry - market status analysis and development prospect forecast
力扣刷题记录--完全背包问题(一)
LeetCode#2062. Count vowel substrings in strings
Printing quality inspection and verification system Industry Research Report - market status analysis and development prospect forecast
LeetCode#118. Yanghui triangle
Research Report of peripheral venous catheter (pivc) industry - market status analysis and development prospect prediction
Es6--- two methods of capturing promise status as failed
Learning record: use STM32 external input interrupt
毕业才知道IT专业大学生毕业前必做的1010件事
Es6---es6 content details
学习记录:理解 SysTick系统定时器,编写延时函数
nodejs爬虫
Cost accounting [16]









