首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用DIPlib检测圆

用DIPlib检测圆
EN

Stack Overflow用户
提问于 2022-02-07 14:22:54
回答 1查看 160关注 0票数 1

我试着在这张图像中检测到圆圈:

然后在另一个空白图像中使用DIPlib在C++中绘制这样的圆圈。

按照Cris Luengo的建议,我更改了代码,现在如下所示:

代码语言:javascript
复制
#include <iostream>
#include <vector>
#include <diplib.h>
#include <dipviewer.h>
#include <diplib/file_io.h>
#include <diplib/display.h>
#include <diplib/color.h>
#include <diplib/linear.h>
#include <diplib/detection.h>
#include <diplib/generation.h>

using namespace std;

int main()
{
    try{
    //read image
    dip::Image img;
    dip::ImageReadTIFF(img,"circle.tif");
    dip::ColorSpaceManager csm;
    img = csm.Convert(img, "grey");

    //circle detection
    //first convert the image in binary
    dip::Image bin_img = img<128;

    //Now calculate the gradient vector of the images
    dip::Image gv=dip::Gradient(img);

    //Apply the Hough transform to find the cicles
    dip::FloatCoordinateArray circles;
    circles=dip::FindHoughCircles(bin_img,gv,{},0.0,0.2);

    //Draw circles
    dip::Image detec_img= g_img.Similar(dip::DT_UINT8);
    for(auto i: circles){
                dip::FloatArray center;
                center.push_back(i[0]);
                center.push_back(i[1]);

                dip::dfloat diameter=i[2]*2;
                dip::DrawBandlimitedBall(detec_img,diameter,center, {255}, "empty");

                center.clear();
                }
    dip::ImageWriteTIFF(detec_img, "detected.tif");

我还改变了FindHoughCircles函数的参数,因为图像中有两个同心圆,所以中心之间的距离必须是0.0,但是程序无法检测到它。其结果是:

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-02-15 15:43:26

documentation for dip::FindHoughCircles的内容如下:

利用2-1Hough变换在二维二值图像中寻找圆圈.首先用dip::HoughTransformCircleCenters计算圆中心,然后计算每个中心的半径。注意,每个中心坐标只返回一个半径。

也就是说,这个函数找不到同心圆。

一种解决方法是运行该函数两次,对圆圈大小有不同的限制。

在DIPlib中,所有分配的映像(或者通过dip::Image构造函数,通过img.Forge(),通过img.Similar()等等)未初始化。在开始绘制像素:detec_img.Fill(0)之前,需要显式地将像素设置为零。您的输出映像在下半部分显示了以前的内存使用情况,我想知道计算结果是什么!:)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71020122

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档