Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to translate opencv C++ code ,containing pointers to JAVA?

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]; }

click to hide/show revision 2
None

updated 2018-12-17 11:45:52 -0600

berak gravatar image

How to translate opencv C++ code ,containing pointers to JAVA?

.

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 *ptr = eye.ptr<uchar>(y); 
      for (int x = 0; x < eye.cols; x++)
      {
          int value = static_cast<int>(ptr);
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];
}

}