如何在opencv中获取被跟踪对象的坐标(x,y值)

时间:2017-03-08 06:36:59

标签: c++ opencv

我试图通过在c ++中使用open cv来跟踪瞳孔虹膜。 我想要跟踪瞳孔虹膜的坐标。我怎么才能得到它? 现在我可以跟踪瞳孔虹膜,但我希望坐标作为数字输出。哪个功能可以实现这一目标?

我到目前为止编写的代码是:

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

using namespace cv;
using namespace std;

int main() {

    VideoCapture cap(1); // open the default camera
    cap.set(CV_CAP_PROP_FRAME_WIDTH, 640);
    cap.set(CV_CAP_PROP_FRAME_HEIGHT, 360);

    if(!cap.isOpened())  // check if we succeeded
        return -1;

    namedWindow("Video",1);
    Mat src_gray;

    while(1) {

        Mat frame,grey,edge,draw,src_gray;
        cap >> frame;
        cvtColor( frame, grey, CV_BGR2GRAY );   // get a new frame from   camera
        Canny( grey, edge, 50, 150, 3);
        edge.convertTo(draw, CV_8U);
        GaussianBlur( edge, src_gray, Size(9, 9), 2, 2 );
        vector<Vec3f> circles;
        HoughCircles( src_gray, circles, CV_HOUGH_GRADIENT, 2,   src_gray.rows/16, 80, 100, 30, 50 );

        /// Draw the circles detected
        for( size_t i = 0; i < circles.size(); i++ ) {
            Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
            int radius = cvRound(circles[i][2]);
            // circle center
            circle( src_gray, center, 3, Scalar(0,255,0), -1, 8, 0 );
            // circle outline
            circle( src_gray, center, radius, Scalar(0,0,255), 3, 8, 0 );
        }

        Rect Rec(370,100,200,150);
        rectangle(src_gray,Rec,Scalar(255),1,8,0);
        namedWindow("roi",640*360);
        Mat Roi=src_gray(Rec);
        imshow("roi",Roi);
        imshow("Video", src_gray);

        // Press 'c' to escape
        if(waitKey(30) == 'c') break;
    }

    return 0;
}

0 个答案:

没有答案