Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/124.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 中心功能在此程序中执行什么操作?_C++_Opencv - Fatal编程技术网

C++ 中心功能在此程序中执行什么操作?

C++ 中心功能在此程序中执行什么操作?,c++,opencv,C++,Opencv,我从中得到了这个程序,虽然我认为这个程序很容易理解,但在理解给定的代码,特别是这个程序使用的中心函数时,我有一些问题。我已经搜索了OpenCV和C++的中心函数,关于函数没有任何结果。以下是网站提供的代码: cv::Vec3f getEyeball(cv::Mat &eye, std::vector<cv::Vec3f> &circles) { std::vector<int> sums(circles.size(), 0); for (int y

我从中得到了这个程序,虽然我认为这个程序很容易理解,但在理解给定的代码,特别是这个程序使用的中心函数时,我有一些问题。我已经搜索了OpenCV和C++的中心函数,关于函数没有任何结果。以下是网站提供的代码:

cv::Vec3f 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;
      }
  }
  .
  .
  .
}
程序中的中心不是函数,它是OpenCV中模板类型点的对象名

由于它是用户定义的名称,因此可以将名称从中心更改为任何有效的变量名

基本上,这段代码是:

cv::Point center((int)std::round(circles[i][0]),
                               (int)std::round(circles[i][1]));
它将x坐标intstd::roundcircles[i][0]和y坐标intstd::roundcircles[i][1]存储在名为“中心”的点对象中

点的详细文档


现在,通过center.x和center.y,可以分别提取名为center的点对象中存储的x和y坐标。

有意义。我通常用大写字母来初始化对象名,所以当有人用小写字母来代替它时,我会很生气。另外,我对C++的对象初始化有点陌生,因为我经常使用java。谢谢