【问题标题】:OpenCV Help - Error: no match for ‘operator[]’ (operand types are ‘cv::Mat’ and ‘int’)OpenCV 帮助 - 错误:“operator[]”不匹配(操作数类型为“cv::Mat”和“int”)
【发布时间】:2017-04-02 06:34:03
【问题描述】:

在 OpenCV 2.4.10 中,我想将行矩阵转换为 12x12 矩阵:

//Extraction SIFT
  SiftDescriptorExtractor extractor;
  Mat descriptors_1, descriptors_2;
  extractor.compute( img_1, keypoints_1, descriptors_1);
  extractor.compute( img_2, keypoints_2, descriptors_2);

  Mat matrix(12,12, CV_8UC3, Scalar(0));
  int j = 0;
  for (int x = 0; x<12; x++)
  {
     for (int y = 0; y<12; y++)
     {
      matrix [x][y] = descriptors_2[x][j];
      j++

     }

  }

第 67 行的错误 no match for ‘operator[]’ (operand types are ‘cv::Mat’ and ‘int’)。 谁能帮我?谢谢。

【问题讨论】:

  • 你需要使用matrix.at&lt;unsigned char&gt;(y,x) = descriptors.at&lt; unsigned char&gt;(j,x)注意访问每个元素时应该是行列顺序见docs.opencv.org/2.4.10/modules/core/doc/…
  • 你为什么不直接reshape垫子? (同样的功能在 2.4.x 中也可用)

标签: c++ opencv compiler-errors sift operation


【解决方案1】:

试试这个也许会有所帮助;

Vec3f intensity = descriptors_2.at<Vec3f>(j, i);
matrix.at<unsigned char>(j,i)[0] = internsity.val[0];
matrix.at<unsigned char>(j,i)[1] = internsity.val[1];
matrix.at<unsigned char>(j,i)[2] = internsity.val[2];

【讨论】:

    【解决方案2】:

    cv::Mat 不像 std::vector 或 std::array。 cv::Mat 的内部数据是 uchar*。您需要通过函数http://docs.opencv.org/2.4.10/modules/core/doc/basic_structures.html#mat-at 确定要检索的数据类型。

    返回的描述符是浮点数,所以你的矩阵类型应该是 CV32FC1。 How does the SiftDescriptorExtractor from OpenCV convert descriptor values?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-09
      相关资源
      最近更新 更多