here is an example. I have a health bar. If player has 100% HP, he has his health bar all the way red. If he gets attacked, part of the health bar is red and the rest is dark (as he lost some HP). I made a ROI on the place where his health bar is. How would I calculate a percentage of his life using OpenCV?
Here is the final solution I got. Thanks to Miki
Mat testBar = src(Rec_UserBarHP); Mat testBarHSV; cvtColor(testBar, testBarHSV, COLOR_BGR2HSV); Mat mask1; inRange(testBarHSV, Scalar(0, 70, 50), Scalar(10, 255, 255), mask1); Mat mask = mask1; int TotalPixels = testBarHSV.rows * testBarHSV.cols; float ZeroPixels = TotalPixels - countNonZero(testBarHSV); ostringstream str; str << "Number of red pixels:" << ZeroPixels; putText(src, str.str(), Point(5, 5), FONT_HERSHEY_COMPLEX_SMALL, 1.0, Scalar(255, 255, 255), 1, CV_AA);