0

我刚刚开始研究瞳孔跟踪。我对瞳孔做了一些阈值处理,但仍然没有需要的准确。下面是我当前的阈值图像

当前阈值图像

图像

我希望只看到轮廓中的瞳孔,但不幸的是我也看到了其他噪音。下面是我的代码

int main( int argc, char** argv )
{ 
     Mat src, src_gray, src_bw_glint, src_bw_iris, dst, dsti;
     int threshold_value1 = 130;
     int threshold_value2 = 30;
     int const max_BINARY_value = 255;
     VideoCapture cap(1); // open the default camera
     if(!cap.isOpened())  // check if we succeeded
         return -1;
     Mat frame;
     vector<vector<Point> > contours;
     vector<Vec4i> hierarchy;

     int p = 0;

     for(;;)
     {

        cap >> src; // get a new frame from camera

        /// Convert it to gray
        cvtColor( src, src_gray, CV_BGR2GRAY );

        Mat drawing = Mat::zeros( src_gray.size(), CV_8UC3 );

        /// Reduce the noise so we avoid false circle detection
        GaussianBlur( src_gray, src_gray, Size(9, 9), 2, 2 );
        namedWindow( " Demo_Gray", CV_WINDOW_AUTOSIZE );
        imshow( " Demo_Gray", src_gray );

        //Threshold
        threshold( src_gray, src_bw_iris, threshold_value2, max_BINARY_value, 1);

        int morph_size = 5;
        Mat element = getStructuringElement( MORPH_ELLIPSE, Size( 2*morph_size + 1, 2*morph_size+1 ), Point( morph_size,morph_size ) );
        cout<<element;

        morphologyEx( src_bw_iris, dst, MORPH_DILATE, element,Point(-1,-1), 1);
        //imshow("Open Image", dst);
        morphologyEx( dst, dsti, MORPH_TOPHAT, element,Point(-1,-1), 10 );
        //imshow("TopHAt Image", dsti);
        morphologyEx( dsti, dsti, MORPH_DILATE, element,Point(-1,-1), 1);
        imshow("TopHAt Image", dsti);

        findContours( dsti, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );

        for( int i = 0; i< contours.size(); i++ )
        {             
            //Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255));
            Scalar color = Scalar(p, 255, p);

            drawContours( drawing, contours,i, color, 2, 8, hierarchy, 0, Point() );
            // circle( drawing, mc[i], 4, color1, -1, 8, 0 );                
            imshow("Drawing", drawing);                
        }

        if (waitKey(1) == 'q') {
            break;
        }

    }
    return 0; 
}

我想知道我工作的最佳阈值方法,以便仅跟踪学生。另外,如果您认为,请告诉我,这可以比我所做的简单得多。

4

2 回答 2

0

I recommend pre-processing with a median filter

Your image without any filter:

your image

and your image processed with a median filter:

your image processed with a median filter

于 2018-06-17T14:31:27.780 回答
0

我认为阈值处理不会改善您的结果。

这是我要做的:

  1. 在您的二进制结果中,应用一个带有大圆形结构元素的开口。所有的小图案都将被删除,只有大(或多或少)的圆形会保留下来。
  2. 提取形状索引,主要是圆度索引(参见此处的列表)。
  3. 更圆形的图案将是瞳孔。
于 2017-01-20T18:00:41.313 回答