cv::Mat getEyeball(cv::Mat &eye, cv::Mat &circles) { std::vector<int> sums(circles.size(), 0); for (int y = 0; y < eye.rows; y++) { uchar ptr = eye.ptr<uchar>(y); for (int x = 0; x < eye.cols; x++) { int value = static_cast<int>(ptr); for (int i = 0; i < circles.size(); i++) { cv::Point center((int)std::round(circles[i][0]), (int)std::round(circles[i][1])); int radius = (int)std::round(circles[i][2]); if (std::pow(x - center.x, 2) + std::pow(y - center.y, 2) < std::pow(radius, 2)) { sums[i] += value; } } ++ptr; } } int smallestSum = 9999999; int smallestSumIndex = -1; for (int i = 0; i < circles.size(); i++) { if (sums[i] < smallestSum) { smallestSum = sums[i]; smallestSumIndex = i; } } return circles[smallestSumIndex]; }