코너 검출

해리스 코너 검출 방법

https://drive.google.com/uc?id=1uK4QlqE2_rQMkePXov4oTOMZSmYvqg2v

$E(\Delta x, \Delta y) = \sum_{x, y} w(x, y) [I(x + \Delta x, y + \Delta y) - I(x, y)]^{2}$

$R = Det(M) - k \cdot Tr(M)^{2}$

$M = \sum_{x, y} w(x, y) \left[ \begin{array}{rr} I_{x} I_{x} & I_{x} I_{y} \\ I_{x} I_{y} & I_{y} I_{y} \end{array} \right]$

void corner_harris()
{
  Mat src = imread("building.jpg", IMREAD_GRAYSCALE);

  if (src.empty())
  {
    cerr << "Image load failed!" << endl;
    return;
  }

  Mat harris;
  cornerHarris(src, harris, 3, 3, 0.04);

  Mat harris_norm;
  normalize(harris, harris_norm, 0, 255, NORM_MINMAX, CV_8U);

  Mat dst;
  cvtColor(src, dst, COLOR_GRAY2BGR);

  for (int j = 1; j < harris.rows - 1; j++)
  {
    for (int i = 1; i < harris.cols - 1; i++)
    {
      if (harris_norm.at<uchar>(j, i) > 120)
      {
        if (harris.at<float>(j, i) > harris.at<float>(j-1, i) &&
            harris.at<float>(j, i) > harris.at<float>(j+1, i) &&
            harris.at<float>(j, i) > harris.at<float>(j, i-1) &&
            harris.at<float>(j, i) > harris.at<float>(j, i+1))
        {
          circle(dst, Point(i, j), 5, Scalar(0, 0, 255), 2);
        }
      }
    }
  }

  imshow("src", src);
  imshow("harris_norm", harris_norm);
  imshow("dst", dst);

  waitKey(0);
  destroyAllWindows();
}

Fast 코너 검출 방법

https://drive.google.com/uc?id=1Jwr5_y2YGeLWG0XQ5KQfDaGlxy_xqHAt