1 Star 0 Fork 0

lewlovehow / Learning-OpenCV-3_examples

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
example_12-02.cpp 1.32 KB
一键复制 编辑 原始数据 按行查看 历史
Gary Bradski 提交于 2017-08-04 00:47 . Modified to work better
// Example 12-2. Using cv::HoughCircles() to return a sequence of circles found in a
// grayscale image
#include <math.h>
#include <iostream>
#include <vector>
#include <opencv2/opencv.hpp>
using std::cout;
using std::endl;
using std::vector;
void help(char** argv) {
cout << "\nExample 12-1. Using cv::dft() and cv::idft() to accelerate the computation of convolutions"
<< "\nHough Circle detect\nUsage: " << argv[0] <<" <path/imagename>\n"
<< "Example:\n" << argv[0] << " ../stuff.jpg\n" << endl;
}
int main(int argc, char** argv) {
help(argv);
if (argc != 2) {
return -1;
}
cv::Mat src, image;
src = cv::imread(argv[1], 1);
if (src.empty()) {
cout << "Cannot load " << argv[1] << endl;
return -1;
}
cv::cvtColor(src, image, cv::COLOR_BGR2GRAY);
cv::GaussianBlur(image, image, cv::Size(5, 5), 0, 0);
vector<cv::Vec3f> circles;
cv::HoughCircles(image, circles, cv::HOUGH_GRADIENT, 2, image.cols/4);
for (size_t i = 0; i < circles.size(); ++i) {
cv::circle(src,
cv::Point(cvRound(circles[i][0]), cvRound(circles[i][1])),
cvRound(circles[i][2]),
cv::Scalar(0, 0, 255),
2,
cv::LINE_AA);
}
cv::imshow("Hough Circles", src);
cv::waitKey(0);
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/lewlovehow/Learning-OpenCV-3_examples.git
git@gitee.com:lewlovehow/Learning-OpenCV-3_examples.git
lewlovehow
Learning-OpenCV-3_examples
Learning-OpenCV-3_examples
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891