打开CV Harris角点检测

时间:2016-12-30 07:19:32

标签: c++ opencv

我创建了一个使用

检测角落的简单类

哈里斯算法

。它正在工作,但当我使用轨迹栏更改阈值时,当值变低(低于100)时,该过程将停止。

这是我的示例代码。

我的头文件

   class CornerCapturer{

        struct configValues
        {
            int block;
            int k_size;
            int thre;
            double k;
            configValues() :block(2), k_size(3), thre(100), k(0.04){}
        };
    public:
        static configValues conf;
        void captureCorners();
        static void captevent(int, void*);
        Mat captureCornerPoints(int thresh, int block, int k_size, double k, Mat frame);
    };

我的Cpp文件

void CaptureBall::detectCorners(){
    CornerCapturer capt;
    VideoCapture cap = capture.captureVideo();
    cap.read(frame);
    capt.captureCorners();
    for (;;){
        cap.read(frame);
        capt.captevent(0, 0);
        waitKey(5);
    }
}



void CornerCapturer::captureCorners(){

    int *t = &CornerCapturer::conf.thre;

    namedWindow("Open", CV_WINDOW_AUTOSIZE);
    captevent(0, 0);
    createTrackbar("Thresh", "Open", t, 255, CornerCapturer::captevent);

}

void CornerCapturer::captevent(int, void*){
    Mat res;
    CornerCapturer cap;
    res = cap.captureCornerPoints(CornerCapturer::conf.thre, CornerCapturer::conf.block, CornerCapturer::conf.k_size, CornerCapturer::conf.k, frame);
    imshow("Open", res);
}

Mat CornerCapturer::captureCornerPoints(int thresh, int block, int k_size, double k, Mat f){
    Mat gray, corner_detected, cnv_normal,copy;
    copy = f;
    cvtColor(copy, gray, COLOR_RGB2GRAY);               // convert to gray image

    cornerHarris(gray, corner_detected, block, k_size, k, BORDER_DEFAULT);  // detect cornet points
    normalize(corner_detected, cnv_normal, 0, 255, NORM_MINMAX, CV_32FC1, Mat());   // normalize image


    for (int j = 0; j < cnv_normal.rows; j++)
    {
        for (int i = 0; i < cnv_normal.cols; i++)
        {
            if ((int)cnv_normal.at<float>(j, i) > thresh)
            {
                circle(copy, Point(i, j), 8, Scalar(120), 2, 8, 0); // put points
            }
        }
    }
    return copy;
}

我将OpenCV库用于轨道角落

0 个答案:

没有答案