1 | initial version |
One possible solution
Mat image = imread("ball.jpg", 0);
threshold(image, image, 127, 255, THRESH_BINARY);
//Set your ROI points
Point a = Point(image.cols, 20);
Point b = Point(image.cols, 50);
Point c = Point(image.cols/2, image.rows);
Point d = Point(image.cols/2+50, image.rows);
vector<Point> points;
points.push_back(a);
points.push_back(b);
points.push_back(c);
points.push_back(d);
//Find the corresponding ROI based on the poitns
convexHull(points, points); //to assure correct point order
Mat roi(image.rows, image.cols, CV_8U, Scalar(0)); //black image
fillConvexPoly(roi, points, Scalar(255)); //draw ROI in white
//Filter original image according to ROI
Mat filtered_image;
image.copyTo(filtered_image, roi); //alternative: bitwise_and(image, roi, filtered_image);
int non_zero = countNonZero(filtered_image);