Converting Mat to Keypoint?

前端 未结 2 1322
半阙折子戏
半阙折子戏 2021-01-24 21:48

I\'m writing both descriptors (SurfDescriptorExtractor output) and keypoints (SurfFeatureDetector output) to an XML file. Before writing keypoints (std::vector) conversion to Ma

2条回答
  •  臣服心动
    2021-01-24 22:10

    This is how the opencv source code does the conversion in Java, I couldn't find this conversion in C++, it might not exist. You might be able to translate this to C++, it is not very complex.

     //Code from Opencv4Android: utils/Converters.java
     public static void Mat_to_vector_KeyPoint(Mat m, List kps) {
            if (kps == null)
                throw new java.lang.IllegalArgumentException("Output List can't be null");
    
            int count = m.rows();
            if (CvType.CV_64FC(7) != m.type() || m.cols() != 1)
                throw new java.lang.IllegalArgumentException(
                        "CvType.CV_64FC(7) != m.type() ||  m.cols()!=1\n" + m);
    
            kps.clear();
            double[] buff = new double[7 * count];
            m.get(0, 0, buff);
    
            for (int i = 0; i < count; i++) {
                kps.add(new KeyPoint((float) buff[7 * i], (float) buff[7 * i + 1], (float) buff[7 * i + 2], (float) buff[7 * i + 3],
                        (float) buff[7 * i + 4], (int) buff[7 * i + 5], (int) buff[7 * i + 6]));
            }
        }
    

提交回复
热议问题