1

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. Now I need to find the Local Maximas in each result Image of the scalespace. 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??? Please if you are to lead me in something else other than correcting my code be informative because I know nothing about opencv. I am just learning

Mark Amery
  • 143,130
  • 81
  • 406
  • 459
John Demetriou
  • 4,093
  • 6
  • 52
  • 88
  • Note that this code will not give results for points at the buttom and right edges of the image when pProcess has not been triggered earlier: this code is not robust! – TimZaman Jun 15 '14 at 11:13

2 Answers2

0

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. 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. It only needs to be initialized once. Subsequent loop iterations will replace the value with the minMaxLoc function result.

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.

Community
  • 1
  • 1
Austin Mullins
  • 7,307
  • 2
  • 33
  • 48
  • still get the same x and y, am I sending wrong matching distance? – John Demetriou Feb 28 '13 at 21:22
  • I really thought that would do it. I think you should set a breakpoint and trace your memory. It's one thing if your vector is coming back with length 0, but if it has a list of points with unique memory addresses, then those points are defined (or at least allocated) somewhere and then obliterated. – Austin Mullins Feb 28 '13 at 22:00
  • that's the thing, it does not have unique values, they are all the same – John Demetriou Feb 28 '13 at 22:13
  • Right, the values are all the same. What about the memory addresses? Is it at least allocating new Point objects? – Austin Mullins Feb 28 '13 at 22:15
  • I do not know how to check that, nor I have time – John Demetriou Mar 01 '13 at 09:59
  • The default contructor of `Point` will initialize it to (0,0), and LocMax is set by `minMaxLoc(mROI,NULL,NULL,NULL,&LocMax);`. There is no point to declare and use it outside the loop. – cedrou Mar 01 '13 at 10:23
0

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

John Demetriou
  • 4,093
  • 6
  • 52
  • 88