OpenCV帮助 - 错误:'operator []'不匹配(操作数类型是'cv :: Mat'和'int')

时间:2016-11-18 11:56:17

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

在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’)上的错误。 谁能帮我?谢谢。

2 个答案:

答案 0 :(得分: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];

答案 1 :(得分:0)

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

返回的描述符是float,因此矩阵类型应为CV32FC1。 How does the SiftDescriptorExtractor from OpenCV convert descriptor values?