zoukankan      html  css  js  c++  java
  • opencv::Harris角点检测

    Harris角点检测理论:

    大致描述: 图像大小x,y, 以x和y为基点,(每个图像点 减去 系数(x,y) ,平方)求和, 得到输出响应。

    R 既是我们要得到的角点, k取0.04-0.06之间。

    根据矩阵M的特征值,对图像上的每个像素点来说:
    
    -边缘
    
    -平坦区域
    
    -角点
    
    各有不通的特征值
    void cv::cornerHarris(
        InputArray src,    //输入灰度图像
        OutputArray dst,   //输出矩阵
        int blockSize,     //计算大小  
        int ksize,         //窗口大小  一般为3
        double k,          //计算角度响应时候的参数大小, 默认在0.04-0.06之间
        int borderType     //BORDER_DEFAULT 阈值,用来过滤角度响应
    )
    #include <opencv2/opencv.hpp>
    #include <iostream>
    
    using namespace cv;
    using namespace std;
    Mat src, gray_src;
    int thresh = 130;
    int max_count = 255;
    const char* output_title = "HarrisCornerDetection Result";
    
    void Harris_Demo(int, void*);
    int main(int argc, char** argv) {
    
        src = imread("D:/vcprojects/images/home.jpg");
        if (src.empty()) {
            printf("could not load image...
    ");
            return -1;
        }
        namedWindow("input image", CV_WINDOW_AUTOSIZE);
        imshow("input image", src);
    
        namedWindow(output_title, CV_WINDOW_AUTOSIZE);
        //灰度图
        cvtColor(src, gray_src, COLOR_BGR2GRAY);
        
        //创建一个拉条
        createTrackbar("Threshold:", output_title, &thresh, max_count, Harris_Demo);
        
        Harris_Demo(0, 0);
    
        waitKey(0);
        return 0;
    }
    
    void Harris_Demo(int, void*) {
        Mat dst, norm_dst, normScaleDst;
        
        //创建输出图像
        dst = Mat::zeros(gray_src.size(), CV_32FC1);
    
        int blockSize = 2;
        int ksize = 3;
        double k = 0.04;
        //角点检测
        cornerHarris(gray_src, dst, blockSize, ksize, k, BORDER_DEFAULT);
        //最大最小值归一化,将值规划到0-255,输入输出CV_32FC1保持一致
        normalize(dst, norm_dst, 0, 255, NORM_MINMAX, CV_32FC1, Mat());
        //绝对值
        convertScaleAbs(norm_dst, normScaleDst);
    
        //对角点检测并画圈
        Mat resultImg = src.clone();
        for (int row = 0; row < resultImg.rows; row++) {
    //取一行数据 uchar
    * currentRow = normScaleDst.ptr(row); for (int col = 0; col < resultImg.cols; col++) { int value = (int)*currentRow; if (value > thresh) {
              //绘制 标识角点 circle(resultImg, Point(col, row),
    2, Scalar(0, 0, 255), 2, 8, 0); } currentRow++; } } imshow(output_title, resultImg); }
  • 相关阅读:
    61. Rotate List
    60. Permutation Sequence
    59. Spiral Matrix II ***
    58. Length of Last Word
    57. Insert Interval
    328. Odd Even Linked List
    237. Delete Node in a Linked List
    关于找List的中间Node
    234. Palindrome Linked List
    203. Remove Linked List Elements *
  • 原文地址:https://www.cnblogs.com/osbreak/p/11597919.html
Copyright © 2011-2022 走看看