本文主要是介绍学习c++版opencv3.4之22-霍夫圆检测,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
霍夫圆检测。
从直角坐标系转为极坐标系后圆心比较亮。
#include <opencv2/opencv.hpp>
#include <iostream>
#include <math.h>using namespace std;
using namespace cv;Mat src, dst;
Mat gray_img;
int main(){
// Mat src1;
// src1 = imread("/Users/ming/Documents/test.jpg");
// resize(src1, src, Size(src1.cols/2, src1.rows/2));src = imread("/Users/ming/Documents/win7logo.jpeg");src.copyTo(dst);if (!src.data){printf("cannot load image ...");return -1;}namedWindow("src img", CV_WINDOW_AUTOSIZE);imshow("src img", src);medianBlur(src, src, 3);
// imshow("medianBulr", src);cvtColor(src, gray_img, CV_WINDOW_AUTOSIZE);Mat canny_img;Canny(gray_img, canny_img, 80, 200);imshow("canny img", canny_img);//霍夫圆检测vector<Vec3f> pcircle;HoughCircles(canny_img, pcircle, CV_HOUGH_GRADIENT, 1.0, 5);
// HoughCircles(canny_img, pcircle, CV_HOUGH_GRADIENT, 1, gray_img.rows / 5, 150, 70, 0, 0);Scalar color = Scalar(0, 0, 255);for (size_t i = 0; i < pcircle.size(); i++){Vec3f temp = pcircle[i];cout<<"circle: "<< temp << endl;circle(dst, Point(temp[0], temp[1]), temp[2], color); //画圆circle(dst, Point(temp[0], temp[1]), 2, Scalar(255,0,0)); //画圆心}imshow("houghcircle", dst);waitKey(0);return 0;
}
这篇关于学习c++版opencv3.4之22-霍夫圆检测的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!