• opencv:霍夫圆检测



    #include <opencv2/opencv.hpp>
    #include <iostream>
    
    using namespace cv;
    using namespace std;
    
    
    int main(int argc, char** argv)
    {
        Mat src = imread("f:/images/qq/circle.png");
        //Mat src = imread("f:/images/qq/yezi.png");
        if (src.empty())
        {
            printf("Could not find the image!
    ");
            return -1;
        }
    
        namedWindow("input", WINDOW_AUTOSIZE);
        imshow("input", src);
    
        Mat gray;
        cvtColor(src, gray, COLOR_BGR2GRAY);
        GaussianBlur(gray, gray, Size(9,9), 2, 2);
        imshow("gray", gray);
    
        vector<Vec3f> circles;
        int minDist = 20;
        double min_radius = 5;
        double max_radius = 100;
        // 接收灰度图像,要降噪,对噪声很敏感
        HoughCircles(gray, circles, HOUGH_GRADIENT, 3, minDist, 100, 100, max_radius, min_radius);
        for (size_t t = 0; t < circles.size(); t++) {
            Point center(circles[t][0], circles[t][1]);
            int radius = round(circles[t][2]);
            // 绘制圆
            circle(src, center, radius, Scalar(0, 0, 255), 2, 8, 0);
            circle(src, center, 3, Scalar(255, 0, 0), 2, 8, 0);
        }
    
        imshow("hough circle demo", src);
        
        waitKey(0);
        destroyAllWindows();
    
        return 0;
    }
    
    
    
    
  • 相关阅读:
    实验10 指针2。
    作业5 指针应用1。
    实验9 指针1。
    作业4 函数应用。
    实验8 数组2。
    实验7 综合练习。
    实验6 数组1。
    实验5 函数。
    作业3 应用分支与循环结构解决问题。
    作业2 分支、循环结构。
  • 原文地址:https://www.cnblogs.com/wbyixx/p/12324145.html
Copyright © 2020-2023  润新知