Measure White Pixels in an image

asked 2016-01-27 01:57:06 -0500

Sanman gravatar image

updated 2016-01-28 09:45:01 -0500

I have extracted eyes from face using Haar Cascade. Now I want to measure the number of white pixels in the extracted eye image. Please Help . . . .

int main()
{
CascadeClassifier face, eye;
if(!face.load("C:\\HAAR\\haarcascade_frontalcatface.xml")){

    printf("Error Loading Face Cascade");
        return -1;
}

    if(!eye.load("C:\\HAAR\\haarcascade_eye_tree_eyeglasses.xml")){

    printf("Error Loading Eye Cascade");
        return -1;
} 
    VideoCapture capture(0);
    if(!capture.isOpened())
    {

        printf("Error opening Video Stream");
        return -1;
    }

    Mat capimg,greyimg;
    vector<Rect> faces,eyes;

    while(1)
    {

        capture>>capimg;
        waitKey(10);            
            cvtColor(capimg, greyimg, CV_BGR2GRAY);
            cv::equalizeHist(greyimg,greyimg);
        face.detectMultiScale(greyimg, faces, 1.1, 10, CV_HAAR_SCALE_IMAGE | CV_HAAR_DO_CANNY_PRUNING, cvSize(0,0), cvSize(300,300));

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

            Point pt1(faces[i].x+faces[i].width,faces[i].y+faces[i].height);
            Point pt2(faces[i].x,faces[i].y);
            Mat faceroi=greyimg(faces[i]);
            eye.detectMultiScale(faceroi, eyes,1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30,30));
            for(size_t j=0; j<eyes.size(); j++)
            {

                Point center(faces[i].x+eyes[j].x+eyes[j].width*0.5,faces[i].y+eyes[j].y+eyes[j].height*0.5);
                int radius = cvRound((eyes[j].width+eyes[j].height)*0.25);
                circle(capimg, center, radius, Scalar(255,0,0),2,8,0);
            }
            rectangle(capimg, pt1, pt2, cvScalar(0,255,0),2,8,0);
        }
        imshow("Result",capimg);
        waitKey(3);
        char c= waitKey(3);
        if (c==27)
        break;

    }
return 0;

}
edit retag flag offensive close merge delete

Comments

1

inRange and countNonZero do not help ?

pklab gravatar imagepklab ( 2016-01-27 06:12:39 -0500 )edit