Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version
void whitePixelCount()
{
    VideoCapture cap(0);
    if(!cap.isOpened())
        return;

    Mat thresImg;
    namedWindow("thresImg",1);
    for(;;)
    {
        Mat frame;
        cap >> frame;
        cvtColor(frame, thresImg, CV_BGR2GRAY);
        blur(thresImg, thresImg, Size(5,5));
        threshold(thresImg, thresImg, 100, 255, THRESH_BINARY);
        Mat subImg(thresImg, Rect(100,100,100,100));
        Scalar nwp = sum(subImg)/255;
        cout << "number of white pixels: " << nwp[0] << endl;
        rectangle(thresImg, Point(100,100), Point(200,200), Scalar(100));
        imshow("thresImg", thresImg);
        if(waitKey(30) >= 0) break;
    }
}

You can donate to this project.