opencv hough圓心檢測
阿新 • • 發佈:2018-12-15
#include "stdafx.h" #include <opencv2\opencv.hpp> #include <iostream> #include <math.h> using namespace cv; using namespace std; int main() { Mat src, image; src = imread("C:\\Users\\lbn\\Desktop\\夜間車輛\\11.bmp",1); if (src.empty()) { cout << "Cannot load" << "image" << endl; return -1; } cvtColor(src, image, CV_BGR2GRAY); GaussianBlur(image, image, Size(5, 5), 0, 0); vector<Vec3f> circles; HoughCircles(image, circles, HOUGH_GRADIENT, 2, image.cols / 10); for (size_t i = 0; i < circles.size(); ++i) { circle(src, Point(cvRound(circles[i][0]), cvRound(circles[i][1])), cvRound(circles[i][2]), Scalar(0, 0, 255), 2, cv::LINE_AA); } imshow("Hough Circles", src); waitKey(); return 0; }