Shi-Tomasi角点检测

 

 

 

 

 

 shi-Tomasi角点检测相对Harris检测的计算量会更小,速度快。

 

 

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

using namespace cv;
using namespace std;

int num_corners = 25;
int max_corners = 200;
const char* output_title = "ShiTomasi Detector";
void ShiTomasi_Demo(int, void*);
Mat src, gray_src;
RNG rng(12345);
int main(int argc, char** argv) {
    src = imread("L:6.jpg");
    if (src.empty()) {
        printf("could not load image...\n");
        return -1;
    }
    namedWindow("input image", CV_WINDOW_AUTOSIZE);
    imshow("input image", src);

    cvtColor(src, gray_src, COLOR_BGR2GRAY);
    namedWindow(output_title, CV_WINDOW_AUTOSIZE);
    createTrackbar("Num Corners:", output_title, &num_corners, max_corners, ShiTomasi_Demo);
    ShiTomasi_Demo(0, 0);

    waitKey(0);
    return 0;
}

void ShiTomasi_Demo(int, void*) {
    if (num_corners < 5) {
        num_corners = 5;
    }
    vector<Point2f> corners;
    double qualityLevel = 0.01;
    double minDistance = 10;
    int blockSize = 3;
    bool useHarris = false;
    double k = 0.04;
    Mat resultImg = gray_src.clone();
    cvtColor(resultImg, resultImg, COLOR_GRAY2BGR);
    goodFeaturesToTrack(gray_src, corners, num_corners, qualityLevel, minDistance, Mat(), blockSize, useHarris, k);
    //ShiTomasi函数的API:
    printf("Number of Detected Corners:  %d\n", corners.size());
    //打印corners的个数

    for (size_t t = 0; t < corners.size(); t++) {
        circle(resultImg, corners[t], 2, Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255)), 2, 8, 0);
        //画圆
    }
    imshow(output_title, resultImg);
}

结果:

 

 

 

拖动滑动条时显示的检测到的角点数;

 

 

posted @ 2019-10-09 21:34  量子与太极  阅读(527)  评论(0编辑  收藏  举报