简体   繁体   English

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

[英]Finding Local Maxima Grayscale Image opencv

I am trying to create my personal Blob Detection algorithm As far as I know I first must create different Gaussian Kernels with different sigmas (which I am doing using Mat kernel= getGaussianKernel(x,y); ) Then get the Laplacian of that kernel and then filter the Image with that so I create my scalespace. 我正在尝试创建我的个人Blob检测算法,据我所知,我首先必须创建具有不同sigma的不同高斯核(我正在使用Mat kernel= getGaussianKernel(x,y); ),然后获取该内核的Laplacian并然后用它过滤图像,以便创建缩放空间。 Now I need to find the Local Maximas in each result Image of the scalespace. 现在,我需要在每个结果的比例空间图像中找到Local Maximas。 But I cannot seem to find a proper way to do so.... my Code so far is 但是我似乎找不到合适的方法来做……。到目前为止,我的代码是

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; 
}

which I found in this thread here, which it supposedly returns a vector of points where the maximas are. 我在这里的线程中找到了它,它据说返回了最大值所在点的向量。 it does return a vector of points but all the x and y coordinates of each point are always -17891602... What to do??? 它确实返回点的向量,但是每个点的所有x和y坐标始终为-17891602。 Please if you are to lead me in something else other than correcting my code be informative because I know nothing about opencv. 如果您除了修改我的代码之外还带领我做其他事情,请提供信息,因为我对opencv一无所知。 I am just learning 我只是在学习

The problem here is that your LocMax point is declared inside the inner loop and never initialized, so it's returning garbage data every time. 这里的问题是您的LocMax点在内部循环内声明,并且从未初始化,因此每次都会返回垃圾数据。 If you look back at the StackOverflow question you linked , you'll see that their similar variable Point maxLoc(0,0) is declared at the top and constructed to point at the middle of the search window. 如果回头看您链接StackOverflow问题 ,您会看到它们的类似变量Point maxLoc(0,0)在顶部声明,并构造为指向搜索窗口的中间。 It only needs to be initialized once. 它只需要初始化一次。 Subsequent loop iterations will replace the value with the minMaxLoc function result. 随后的循环迭代将用minMaxLoc函数结果替换该值。

In summary, remove this line in your inner loop: 总而言之,在您的内部循环中删除此行:

Point LocMax; // delete this

And add a slightly altered version near the top: 并在顶部附近添加略有改动的版本:

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

That should get you started anyway. 无论如何,这应该会让您入门。

I found it guys. 我找到了。 The problem was my threshold was too high. 问题是我的门槛太高。 I do not understand why it gave me negative points instead of zero points but lowering the threshold worked 我不明白为什么它给了我负分而不是零分但降低了门槛有效

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

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