Skip to content

Commit

Permalink
DSP cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pierotofy committed Oct 28, 2023
1 parent ac3b101 commit 6073bea
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
3 changes: 2 additions & 1 deletion opensfm/src/features/dspsift.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
4 changes: 3 additions & 1 deletion opensfm/src/features/python/pybind.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
46 changes: 20 additions & 26 deletions opensfm/src/features/src/dspsift.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 6073bea

Please sign in to comment.