Opencv Harris角点检测

Posted herd

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Opencv Harris角点检测相关的知识,希望对你有一定的参考价值。

#include <iostream>
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;

Mat img1, img2, img3, img4, img5, img6, img_result, img_gray1, img_gray2, img_gray3, img_canny1, img_binary1, img_dist1, img_dist2, kernel_1, kernel_2, img_laplance, img_sharp;

char win1[] = "window1";
char win2[] = "window2";
char win3[] = "window3";
char win4[] = "window4";
char win5[] = "window5";
char win6[] = "window6";
char win7[] = "window7";

int thread_value = 100;
int max_value = 255;
RNG rng1(12345);
RNG rng2(1235);

int Demo_Harris();
void Demo_1(int, void*);

//Harris角点检测
int Demo_Harris()
{
  namedWindow(win1, CV_WINDOW_AUTOSIZE);
  //namedWindow(win2, CV_WINDOW_AUTOSIZE);
  //namedWindow(win3, CV_WINDOW_AUTOSIZE);

  img1 = imread("D://images//4//3.jpg");
  //img2 = imread("D://images//1//p5_1.jpg");
  if (img1.empty())
  {
    cout << "could not load image..." << endl;
    return 0;
  }
  imshow(win1, img1);

  cvtColor(img1, img2, CV_BGR2GRAY);
  imshow(win2, img2);

  createTrackbar("Track", win1, &thread_value, max_value, Demo_1);
  Demo_1(0, 0);

  return 0;
}

void Demo_1(int, void*)
{
  img3 = Mat::zeros(img2.size(), CV_32FC1);
  int blockSize = 2;
  int kSize = 3;
  double k = 0.04;

  cornerHarris(img2, img3, blockSize, kSize, k, BORDER_DEFAULT);

  //归一化处理
  normalize(img3, img_dist1, 0, 255, NORM_MINMAX, CV_32FC1, Mat());
  //
  convertScaleAbs(img_dist1, img_dist2);

  img4 = img1.clone();
  for (size_t row = 0; row<img4.rows; row++)
  {
    uchar* now_row = img_dist2.ptr(row);//获取当前行
    for (size_t col = 0; col<img4.cols; col++)
    {
      int value = (int)*now_row;
      if (value>thread_value)
      {
        circle(img4, Point(col, row), 2, Scalar(rng1.uniform(0, 255), rng1.uniform(0, 255), rng1.uniform(0, 255)), 2, 8, 0);
      }
      now_row++;
    }
  }
  imshow(win4, img4);
}

int main()
{
  Demo_Harris();

  waitKey(0);
  return 0;
}

 技术分享图片

技术分享图片























































以上是关于Opencv Harris角点检测的主要内容,如果未能解决你的问题,请参考以下文章

OpenCV——Harris角点检测

opencv-角点检测之Harris角点检测

OpenCV 例程300篇238. OpenCV 中的 Harris 角点检测

OpenCV 例程300篇238. OpenCV 中的 Harris 角点检测

python使用openCV图像加载(转化为灰度图像)Harris角点检测器算法(Harris Corner Detector)进行角点检测在图像上标记每个角点可视化标记了角点的图像数据

python使用openCV图像加载(转化为灰度图像)Harris角点检测器算法(Harris Corner Detector)进行角点检测在图像上标记每个角点可视化标记了角点的图像数据