Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
cv::Mat getEyeball(cv::Mat &eye, std::vector<cv::Vec3f> &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];
}


What I have tried:

the only code I can't understand
C++
uchar *ptr = eye.ptr<uchar>(y);
and
C++
int value = static_cast<int>(*ptr);
can you tell me how these lines of code are used to me and how to translate them into java programming language?
Posted
Updated 18-Dec-18 22:33pm
v2

C++
uchar *ptr = eye.ptr<uchar>(y);

The ptr function takes an integer parameter (y) and returns a pointer to an array of unsigned characters.
C++
int value = static_cast<int>(*ptr);

The character that is pointed to by the pointer is cast to an integer value. This is then added to an element of the sums array in the following loop.
 
Share this answer
 
These both statements are looking strange for me. A wrong cast from a value to a pointer and than a recast to value. This strange cast to a uchar is limiting the maximal value to 255, and so is a bug for bigger y. Why not use a direct assigment:
C++
int value = y;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900