Shi-Tomasi角点检测

代码示例:

#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include<iostream>
#include<vector>
using namespace cv;
using namespace std;

#define WINDOW_NAME "Shi-Tomasi角点检测"

Mat src, gray;
int maxCornerNum = 33;
int maxTrackbarNum = 500;
RNG rng(12345);

//滚动条回调函数
void onGoodFeaturesToTrack(int, void*){
    if (maxCornerNum <= 1){
        maxCornerNum = 1;
    }
    //参数准备
    vector<Point2d> corners;
    double qualityLevel=0.01;//角点检测可接受的最小特征值
    double minDistance = 10;//角点之间的最小距离
    int blockSize = 3;//计算导数自相关矩阵时的指定的领域范围
    double k = 0.04;//权重系数
    Mat copy = src.clone();

    //进行Shi-Tomasi角点检测
    goodFeaturesToTrack(gray, 
        corners, 
        maxCornerNum, 
        qualityLevel,
        minDistance, 
        Mat(), 
        blockSize, 
        false, 
        k);
    //输出文字信息
    cout << "此次检测到的角点数量为:" << corners.size() << endl;
    //绘制检测到的角点
    int r = 4;
    for (int i = 0; i < corners.size(); i++){
        circle(copy, corners[i], r, Scalar(255,0,0), -1, 8, 0);
    }
    imshow(WINDOW_NAME, copy);
}

int main(){
    src = imread("church.jpg", 1);
    cvtColor(src, gray, COLOR_BGR2GRAY);

    namedWindow(WINDOW_NAME, WINDOW_AUTOSIZE);
    createTrackbar("最大角点数", WINDOW_NAME, &maxCornerNum, maxTrackbarNum, onGoodFeaturesToTrack);
    imshow(WINDOW_NAME, src);
    onGoodFeaturesToTrack(0, 0);

    waitKey(0);
    return 0;
}

效果:

 

转载于:https://www.cnblogs.com/bluebean/p/5733294.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值