在不使用霍夫圆圈的情况下检测圆 [英] Detecting Circles without using Hough Circles

查看:314
本文介绍了在不使用霍夫圆圈的情况下检测圆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个圈子的图片,我想找到这个圈子但不使用hough圈子。



我找到了一种方式,链接

解决方案

一种可能的方法是首先



输出 Canny





重新绘制的像素:




I have an image of a circle, I want to find the circle but not using hough circles.

I found a way, linked here.

But I can't find the transition coordinates from white to black as I don't know the x and y coordinates in the circle. What other methods are there, or how can I make that approach work?

This is my test image:

解决方案

One possible approach is to first threshold the image to get rid of some of the noise around the circle. Then you can extract the edge of the circle using Canny edge detection. Finally, findNonZero to get a list of pixel coordinates.


I first did a quick prototype with Python:

import cv2
import numpy as np

img = cv2.imread('circle.png', 0)
mask = cv2.threshold(img, 127, 255, cv2.THRESH_BINARY)[1]
edges = cv2.Canny(mask, 20, 100)
points = np.array([p[0] for p in cv2.findNonZero(edges)])


And then ported it to C++, adding some extra code to save all the intermediate images and plot the found pixels.

#include <opencv2/opencv.hpp>

int main()
{
    cv::Mat img(cv::imread("circle.png", 0));

    cv::Mat mask;
    cv::threshold(img, mask, 127, 255, cv::THRESH_BINARY);

    cv::imwrite("circle_1.png", mask);

    cv::Mat edges;
    cv::Canny(mask, edges, 20, 100);

    cv::imwrite("circle_2.png", edges);

    std::vector<cv::Point2i> points;
    cv::findNonZero(edges, points);

    cv::Mat output(cv::Mat::zeros(edges.size(), CV_8UC3));
    for (auto const& p : points) {
        output.at<cv::Vec3b>(p) = cv::Vec3b(127, 255, 127);
    }
    cv::imwrite("circle_3.png", output);
}


Output of threshold:

Output of Canny:

Re-plotted pixels:

这篇关于在不使用霍夫圆圈的情况下检测圆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆