有代码吗,实在是不会

解决方案 »

  1.   

    void FeatureController::detect(const Mat & _grey_img,
                                   vector<Point2> & _feature_points,
                                   vector<FeatureDescriptor> & _feature_descriptors) {    Mat grey_img_float = _grey_img.clone();
        grey_img_float.convertTo(grey_img_float, CV_32FC1);    
        VlSiftFilt * vlSift = vl_sift_new(width, height,
                                          log2(min(width, height)),
                                          SIFT_LEVEL_COUNT,
                                          SIFT_MINIMUM_OCTAVE_INDEX);
        vl_sift_set_peak_thresh(vlSift, SIFT_PEAK_THRESH);
        vl_sift_set_edge_thresh(vlSift, SIFT_EDGE_THRESH);
        
        if(vl_sift_process_first_octave(vlSift, (vl_sift_pix const *) ROI.data) != VL_ERR_EOF) {
            do {
                vl_sift_detect(vlSift);
                for(int i = 0; i < vlSift->nkeys; ++i) {
                    double angles[4];
                    _feature_points.emplace_back(vlSift->keys[i].x, vlSift->keys[i].y);
                    FeatureDescriptor descriptor;
                    int angleCount = vl_sift_calc_keypoint_orientations(vlSift, angles, &vlSift->keys[i]);
                    for(int j = 0; j < angleCount; ++j) {
                        Mat descriptor_array(1, SIFT_DESCRIPTOR_DIM, CV_32FC1);
                        vl_sift_calc_keypoint_descriptor(vlSift, (vl_sift_pix *) descriptor_array.data, &vlSift->keys[i], angles[j]);
                        descriptor.addDescriptor(descriptor_array);
                    }
                    _feature_descriptors.emplace_back(descriptor);
                }
            } while (vl_sift_process_next_octave(vlSift) != VL_ERR_EOF);
        }
        vl_sift_delete(vlSift);
    }