Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

apart from iterating over pixels, consider this idea, - instead: make a circle mask image, and decide of the mean value from the masked image:

  int best = -1;
  double bestval = 999999.0;
  for (int i = 0; i < circles.size(); i++)
  {
      // TODO: filter circles for size & position

      // start with a black image
      Mat mask(eye.size(), eye.type(), Scalar.all(0));

      cv::Point center((int)std::round(circles[i][0]), (int)std::round(circles[i][1]));
      int radius = (int)std::round(circles[i][2]);

      // draw a filled, white circle
      Imgproc.circle(mask, center, radius, Scalar.all(255), -1);
      Mat masked = new Mat();

      // mask out everything apart from the circle region
      Core.bitwise_and(eye, mask, masked);

      // mean value of the circle region only
      Scalar mean = Core.mean(masked);

      // retain best         
      if (mean.val[0] < bestVal)
      {
          bestVal = mean.val[0];
          best = i;
      }
  }

apart from iterating over pixels, consider this idea, - instead: make a circle mask image, and decide of on the mean value from the masked out image:

  int best = -1;
  double bestval = 999999.0;
  for (int i = 0; i < circles.size(); i++)
  {
      // TODO: filter circles for size & position

      // start with a black image
      Mat mask(eye.size(), eye.type(), Scalar.all(0));

      cv::Point center((int)std::round(circles[i][0]), (int)std::round(circles[i][1]));
      int radius = (int)std::round(circles[i][2]);

      // draw a filled, white circle
      Imgproc.circle(mask, center, radius, Scalar.all(255), -1);
      Mat masked = new Mat();

      // mask out everything apart from the circle region
      Mat masked = new Mat();
      Core.bitwise_and(eye, mask, masked);

      // mean value of the circle region only
      Scalar mean = Core.mean(masked);

      // retain best         
      if (mean.val[0] < bestVal)
      {
          bestVal = mean.val[0];
          best = i;
      }
  }

apart from iterating over pixels, consider this idea, - instead: make a circle mask image, and decide on the mean value from the masked out image:

  int best = -1;
  double bestval = 999999.0;
  for (int i = 0; i < circles.size(); i++)
  {
      // TODO: filter circles for size & position

      // start with a black image
      Mat mask(eye.size(), eye.type(), Scalar.all(0));

      cv::Point center((int)std::round(circles[i][0]), (int)std::round(circles[i][1]));
      int radius = (int)std::round(circles[i][2]);

      // draw a filled, white circle
      Imgproc.circle(mask, center, radius, Scalar.all(255), -1);

      // mask out everything apart from the circle region
      Mat masked = new Mat();
      Core.bitwise_and(eye, mask, masked);

      // mean value of the circle region only
      Scalar mean = Core.mean(masked);
Core.mean(eye,mask);

      // retain best         
      if (mean.val[0] < bestVal)
      {
          bestVal = mean.val[0];
          best = i;
      }
  }