Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

bounding rect around detected eye region

Hi

I'm trying to do the following :

1.detect face and then eyes
2. after doing somw threshol to the detected eye region obtain morphologyEx (open) of eye region . 3. pass the result of morphologyEx (open) so that I can bound the eye region with a rectangle like this image .

image description

using function below I'm not getting this result .

image description

how can this be done ?

Thanks for help

void find_contour(Mat image)
{

Mat src_mat, gray_mat, canny_mat;
Mat contour_mat;
Mat bounding_mat;


contour_mat = image.clone();
bounding_mat = image.clone();


cvtColor(image, gray_mat, CV_GRAY2BGR);

// apply canny edge detection

Canny(gray_mat, canny_mat, 30, 128, 3, false);

//3. Find & process the contours
//3.1 find contours on the edge image.


vector< vector< cv::Point> > contours;
findContours(canny_mat, contours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE);

//3.2 draw contours & property value on the source image.


double area, length;
drawContours(contour_mat, contours, -1, cv::Scalar(0), 2);  //draw contours on the image

//3.3 find bounding of each contour, and draw it on the source image.

for (int i = 0; i < contours.size(); ++i)
{

    Rect rect;


    //compute the bounding rect, rotated bounding rect, minum enclosing circle.

    rect = boundingRect(contours[i]);


    //draw them on the bounding image.

    cv::rectangle(bounding_mat, rect, Scalar(255, 0, 0), 2);


}


imshow("Bounding ", bounding_mat);

}