From 6073bea4ed6346c2844afec75707c85e5cc600d6 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Sat, 28 Oct 2023 02:32:31 +0000 Subject: [PATCH] DSP cleanup --- opensfm/src/features/dspsift.h | 3 +- opensfm/src/features/python/pybind.cc | 4 ++- opensfm/src/features/src/dspsift.cc | 46 ++++++++++++--------------- 3 files changed, 25 insertions(+), 28 deletions(-) diff --git a/opensfm/src/features/dspsift.h b/opensfm/src/features/dspsift.h index 14ac02bb2..2f4ac5485 100644 --- a/opensfm/src/features/dspsift.h +++ b/opensfm/src/features/dspsift.h @@ -5,6 +5,7 @@ namespace features { py::tuple dspsift(foundation::pyarray_f image, float peak_threshold, - float edge_threshold, int target_num_features); // TODO MORE + float edge_threshold, int target_num_features, + bool feature_root, bool domain_size_pooling); } diff --git a/opensfm/src/features/python/pybind.cc b/opensfm/src/features/python/pybind.cc index a67c78c86..10ffd063b 100644 --- a/opensfm/src/features/python/pybind.cc +++ b/opensfm/src/features/python/pybind.cc @@ -59,7 +59,9 @@ PYBIND11_MODULE(pyfeatures, m) { py::arg("target_num_features") = 0); m.def("dspsift", features::dspsift, py::arg("image"), py::arg("peak_threshold") = 0.003, py::arg("edge_threshold") = 10, - py::arg("target_num_features") = 0); + py::arg("target_num_features") = 0, + py::arg("feature_root") = true, + py::arg("domain_size_pooling") = true); m.def("match_using_words", features::match_using_words); m.def("compute_vlad_descriptor", features::compute_vlad_descriptor, diff --git a/opensfm/src/features/src/dspsift.cc b/opensfm/src/features/src/dspsift.cc index 000c59dc1..66b810836 100644 --- a/opensfm/src/features/src/dspsift.cc +++ b/opensfm/src/features/src/dspsift.cc @@ -46,14 +46,13 @@ FeatureDescriptors FeatureDescriptorsToUnsignedByte( namespace features { py::tuple dspsift(foundation::pyarray_f image, float peak_threshold, - float edge_threshold, int target_num_features) { + float edge_threshold, int target_num_features, + bool feature_root, bool domain_size_pooling) { if (!image.size()) { return py::none(); } - bool feature_root = true; // bool estimate_affine_shape = true; - bool domain_size_pooling = true; double dsp_min_scale = 1.0 / 6.0; double dsp_max_scale = 3.0; @@ -80,25 +79,25 @@ py::tuple dspsift(foundation::pyarray_f image, float peak_threshold, vl_covdet_set_peak_threshold(covdet.get(), peak_threshold); vl_covdet_set_edge_threshold(covdet.get(), edge_threshold); - std::cout << "IMAGE" << std::endl; - vl_covdet_put_image(covdet.get(), image.data(), image.shape(1), image.shape(0)); - - // vl_covdet_set_non_extrema_suppression_threshold(covdet, 0); - std::cout << "HERE" << std::endl; + // vl_covdet_set_non_extrema_suppression_threshold(covdet.get(), 0); - int num_features = 0; - while(true){ - int prev_num_features = num_features; - vl_covdet_detect(covdet.get(), target_num_features); - num_features = vl_covdet_get_num_features(covdet.get()); + vl_covdet_detect(covdet.get(), target_num_features); + int num_features = vl_covdet_get_num_features(covdet.get()); + + // int num_features = 0; + // while(true){ + // int prev_num_features = num_features; + // vl_covdet_detect(covdet.get(), target_num_features); + // num_features = vl_covdet_get_num_features(covdet.get()); + + // if (num_features < target_num_features && peak_threshold > 0.0001 && prev_num_features < num_features){ + // peak_threshold = (peak_threshold * 2.0f) / 3.0f; + // vl_covdet_set_peak_threshold(covdet.get(), peak_threshold); + // }else break; + // } - if (num_features < target_num_features && peak_threshold > 0.0001 && prev_num_features < num_features){ - peak_threshold = (peak_threshold * 2.0f) / 3.0f; - vl_covdet_set_peak_threshold(covdet.get(), peak_threshold); - }else break; - } // if (estimate_affine_shape){ // vl_covdet_extract_affine_shape(covdet.get()); // } else { @@ -131,8 +130,8 @@ py::tuple dspsift(foundation::pyarray_f image, float peak_threshold, float det = features[i].frame.a11 * features[i].frame.a22 - features[i].frame.a12 * features[i].frame.a21; float size = sqrt(fabs(det)); float angle = atan2(features[i].frame.a21, features[i].frame.a11) * 180.0f / M_PI; - keypoints[4 * i + 0] = features[i].frame.x;// + 0.5; // TODO: Should this be + 0.5? - keypoints[4 * i + 1] = features[i].frame.y;// + 0.5; + keypoints[4 * i + 0] = features[i].frame.x; + keypoints[4 * i + 1] = features[i].frame.y; keypoints[4 * i + 2] = size; keypoints[4 * i + 3] = angle; @@ -149,7 +148,6 @@ py::tuple dspsift(foundation::pyarray_f image, float peak_threshold, } keypoints_count = i; - keypoints.resize(4 * keypoints_count); // Compute the descriptors for the detected keypoints. descriptors.resize(keypoints_count, 128); @@ -241,13 +239,9 @@ py::tuple dspsift(foundation::pyarray_f image, float peak_threshold, descriptors.row(i) = FeatureDescriptorsToUnsignedByte(descriptor); } - // *descriptors = TransformVLFeatToUBCFeatureDescriptors(*descriptors); + // *descriptors = TransformVLFeatToUBCFeatureDescriptors(*descriptors); } - std::cout << descriptors.rows() << " x " << descriptors.cols() << std::endl; - std::cout << keypoints.size() << " " << descriptors.size() << std::endl; - - return py::make_tuple( foundation::py_array_from_data(keypoints.data(), keypoints_count, 4), foundation::py_array_from_data(descriptors.data(), keypoints_count, 128));