使用 C++/OpenCV 的局部最大值

Local maximas with C++/OpenCV

我正在尝试使用 OpenCv 和 C++ 实现 Harris 角点检测器,但我似乎找不到找到局部最大值的算法,我是图像处理的新手,所以你能帮帮我吗?

取一个 3x3 window,然后检查中心像素是否最大

我发现我经常从我的二进制图像库中回收这个函数 https://github.com/MalcolmMcLean/binaryimagelibrary/

/*
  get 3x3 neighbourhood, padding for boundaries
  Params: out - return pointer for neighbourhood
          binary - the binary image
          width - image width
          height - image height
          x, y - centre pixel x, y co-ordinates
          border - value to pad borders with.
  Notes: pattern returned is
             0  1  2
             3  4  5
             6  7  8
         where 4 is the pixel at x, y.
*/
static void get3x3(unsigned char *out, unsigned char *binary, int width, int height, int x, int y, unsigned char border)
{
    if(y > 0 && x > 0)        out[0] = binary[(y-1)*width+x-1]; else out[0] = border;
    if(y > 0)                 out[1] = binary[(y-1)*width+x];   else out[1] = border;
    if(y > 0 && x < width-1)  out[2] = binary[(y-1)*width+x+1]; else out[2] = border;
    if(x > 0)                 out[3] = binary[y*width+x-1];     else out[3] = border;
                              out[4] = binary[y*width+x];
    if(x < width-1)           out[5] = binary[y*width+x+1];     else out[5] = border;
    if(y < height-1 && x > 0) out[6] = binary[(y+1)*width+x-1]; else out[6] = border;
    if(y < height-1)          out[7] = binary[(y+1)*width+x];   else out[7] = border;
    if(y < height-1 && x < width-1) out[8] = binary[(y+1)*width+x+1]; else out[8] = border; 
}`

` 您可能需要将 unsigned char 更改为 int 或 float - 该函数专为二进制图像设计。