There are several methods in the literature, for example:
. , .. Leung and Siu-Yeung Cho, " ", " ", 2012. at 4.2
, , . " ". 47.11 (2014): 3693-3708. 3.3.1
, , . , , - , .
, , 2. , .
, :

, , - :

:
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
Mat3b img = imread("path_to_image");
Mat1b bin;
cvtColor(img, bin, COLOR_BGR2GRAY);
vector<vector<Point>> contours;
findContours(bin.clone(), contours, RETR_EXTERNAL, CHAIN_APPROX_NONE);
for (int i = 0; i < contours.size(); ++i)
{
RotatedRect ell = fitEllipse(contours[i]);
Mat1b maskContour(img.rows, img.cols, uchar(0));
drawContours(maskContour, contours, i, Scalar(255), 2);
Mat1b maskEllipse(img.rows, img.cols, uchar(0));
ellipse(maskEllipse, ell, Scalar(255), 2);
Mat1b intersection = maskContour & maskEllipse;
float cnz = countNonZero(intersection);
float n = countNonZero(maskContour);
float measure = cnz / n;
ellipse(img, ell, Scalar(0, measure*255, 255 - measure*255), 3);
}
imshow("Result", img);
waitKey();
return 0;
}