繁体   English   中英

查找局部千里马灰度图像opencv

[英]Finding Local Maxima Grayscale Image opencv

我正在尝试创建我的个人Blob检测算法,据我所知,我首先必须创建具有不同sigma的不同高斯核(我正在使用Mat kernel= getGaussianKernel(x,y); ),然后获取该内核的Laplacian并然后用它过滤图像,以便创建缩放空间。 现在,我需要在每个结果的比例空间图像中找到Local Maximas。 但是我似乎找不到合适的方法来做……。到目前为止,我的代码是

vector <Point> GetLocalMaxima(const cv::Mat Src,int MatchingSize, int Threshold)
{  
    vector <Point> vMaxLoc(0); 

    if ((MatchingSize % 2 == 0) ) // MatchingSize has to be "odd" and > 0
    {
        return vMaxLoc;
    }

    vMaxLoc.reserve(100); // Reserve place for fast access 
    Mat ProcessImg = Src.clone();
    int W = Src.cols;
    int H = Src.rows;
    int SearchWidth  = W - MatchingSize;
    int SearchHeight = H - MatchingSize;
    int MatchingSquareCenter = MatchingSize/2;


    uchar* pProcess = (uchar *) ProcessImg.data; // The pointer to image Data 

    int Shift = MatchingSquareCenter * ( W + 1);
    int k = 0;

    for(int y=0; y < SearchHeight; ++y)
    { 
        int m = k + Shift;
        for(int x=0;x < SearchWidth ; ++x)
        {
            if (pProcess[m++] >= Threshold)
            {
                Point LocMax;
                Mat mROI(ProcessImg, Rect(x,y,MatchingSize,MatchingSize));
                minMaxLoc(mROI,NULL,NULL,NULL,&LocMax);
                if (LocMax.x == MatchingSquareCenter && LocMax.y == MatchingSquareCenter)
                { 
                    vMaxLoc.push_back(Point( x+LocMax.x,y + LocMax.y )); 
                    // imshow("W1",mROI);cvWaitKey(0); //For gebug              
                }
            }
        }
        k += W;
    }
    return vMaxLoc; 
}

我在这里的线程中找到了它,它据说返回了最大值所在点的向量。 它确实返回点的向量,但是每个点的所有x和y坐标始终为-17891602。 如果您除了修改我的代码之外还带领我做其他事情,请提供信息,因为我对opencv一无所知。 我只是在学习

这里的问题是您的LocMax点在内部循环内声明,并且从未初始化,因此每次都会返回垃圾数据。 如果回头看您链接StackOverflow问题 ,您会看到它们的类似变量Point maxLoc(0,0)在顶部声明,并构造为指向搜索窗口的中间。 它只需要初始化一次。 随后的循环迭代将用minMaxLoc函数结果替换该值。

总而言之,在您的内部循环中删除此行:

Point LocMax; // delete this

并在顶部附近添加略有改动的版本:

vector <Point> vMaxLoc(0); // This was your original first line 
Point LocMax(0,0);  // your new second line

无论如何,这应该会让您入门。

我找到了。 问题是我的门槛太高。 我不明白为什么它给了我负分而不是零分但降低了门槛有效

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM