检测实现OpenCV2.4.4实现Shi-Tomasi角点检测(goodFeaturesToTrack)

最近研究检测实现,稍微总结一下,以后继续补充:

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>

using namespace cv;
using namespace std;

//全局变量
Mat src1, src1_gray,
    src2, src2_gray;

int maxCorners = 23;
int maxTrackbar = 100;

char* source_window1 = "src1";
char* source_window2 = "src2";


void goodFeaturesToTrack_Demo( int, void* )
{
    //参数初始化
    if(maxCorners < 1)//允许返回的最多角点个数
        maxCorners = 1;
    vector<Point2f> corners1,corners2;//角点容器
    double qualityLevel = 0.01;//最小特征值小于qualityLevel*最大特征值的点将被忽略
    double minDistance = 10;//两角点间最小距离
    int blockSize = 3;//邻域尺寸
    bool useHarrisDetector = false;//是不是使用Harris
    double k = 0.04;

    //拷贝原图
    Mat src1_copy = src1.clone();
    Mat src2_copy = src2.clone();

    //调用函数停止Shi-Tomasi角点检测
    goodFeaturesToTrack( src1_gray,
                         corners1,
                         maxCorners,
                         qualityLevel,
                         minDistance,
                         Mat(),
                         blockSize,
                         useHarrisDetector,
                         k );
    goodFeaturesToTrack( src2_gray,
                         corners2,
                         maxCorners,
                         qualityLevel,
                         minDistance,
                         Mat(),
                         blockSize,
                         useHarrisDetector,
                         k );


    //画出角点
    cout<<"角点个数:"<<corners1.size()<<endl;//等于maxCorners
    for( int i = 0; i < corners1.size(); i++ )
    {
        circle( src1_copy, corners1[i], 4, Scalar(0,255,0),2);
        circle( src2_copy, corners2[i], 4, Scalar(0,255,0),2);
    }

    //表现图像
    imshow( source_window1, src1_copy );
    imshow( source_window2, src2_copy );
}

int main()
{
    //加载源图并转换为灰度图
    src1 = imread("horse1.jpg");
    src2 = imread("horse2.jpg");
    cvtColor( src1, src1_gray, CV_BGR2GRAY );
    cvtColor( src2, src2_gray, CV_BGR2GRAY );

    //创立窗口
    namedWindow( source_window1, CV_WINDOW_AUTOSIZE );
    namedWindow( source_window2, CV_WINDOW_AUTOSIZE );

    //创立滑块条,调节允许的角点个数
    createTrackbar( "角点个数:", source_window1, &maxCorners, maxTrackbar, goodFeaturesToTrack_Demo );

    goodFeaturesToTrack_Demo( 0, 0 );

    waitKey(0);
    return(0);
}
    每日一道理
时间好比一条小溪,它能招引我们奔向生活的海洋;时间如同一叶扁舟,它将帮助我们驶向理想的彼岸;时间犹如一支画笔,它会指点我们描绘人生的画卷。

    

    效果图:

    检测和实现

文章结束给大家分享下程序员的一些笑话语录: 很多所谓的牛人也不过如此,离开了你,微软还是微软,Google还是Google,苹果还是苹果,暴雪还是暴雪,而这些牛人离开了公司,自己什么都不是。

--------------------------------- 原创文章 By
检测和实现
---------------------------------

posted @ 2013-05-28 23:09  xinyuyuanm  阅读(453)  评论(0编辑  收藏  举报