Skip to content

Commit

Permalink
Nbuono/implement symphony dataset parser (#333)
Browse files Browse the repository at this point in the history
Co-authored-by: Nicolaniello Buono <[email protected]>
Co-authored-by: Nico Buono <[email protected]>
  • Loading branch information
3 people authored Nov 25, 2024
1 parent 8d32967 commit 74ba6cf
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 3 deletions.
Empty file added .gitmodules
Empty file.
17 changes: 17 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ http_archive(
integrity = "sha256-CVtgQSRXe8o2wMjNcJrxtlUxiHZY9ZQJ0kde8BkrTPw="
)

http_archive(
name = "symphony_lake_snippet",
urls = ["https://www.dropbox.com/scl/fi/gh7855qdos5mspinst77k/symphony_lake_snippet.zip?rlkey=mg7qe0gq51r446dwhr9g2wiut&st=774393fx&dl=1"],
build_file = "//third_party:BUILD.symphony_lake_snippet",
sha256 = "f16211fb370c9471153c9ed4a345b9fb848d292dbb8b7dc26fea24cb30ba5c15",
)

http_archive(
name = "bazel_skylib",
sha256 = "bc283cdfcd526a52c3201279cda4bc298652efa898b10b4db0837dc51652756f",
Expand Down Expand Up @@ -466,6 +473,16 @@ http_archive(
integrity = "sha256-cSp9CdKiJlL7BqSa9RbgUZeaOYStsGfahnYOYO1Rp/U="
)

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "symphony_lake_parser",
urls = ["https://github.com/pizzaroll04/SymphonyLakeDataset/archive/4b38c2519270a43f76858e6c97c1f1de1735e5d0.zip"],
strip_prefix = "SymphonyLakeDataset-4b38c2519270a43f76858e6c97c1f1de1735e5d0",
build_file = "//third_party:BUILD.symphony_lake_parser",
sha256 = "d203e486507c7950ae9a346406fe2c42f8b2d204e8d25ba07a47c834f4ae8ede",
)

http_archive(
name = "gtsam",
build_file = "@rules_gtsam//third_party:gtsam.BUILD",
Expand Down
28 changes: 26 additions & 2 deletions experimental/learn_descriptors/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

package(features=["warning_compile_flags"])

cc_library(
Expand All @@ -17,6 +16,31 @@ cc_test(
]
)


cc_library(
name = "symphony_lake_parser",
hdrs = ["symphony_lake_parser.hh"],
copts = ["-Wno-unused-parameter"],
visibility = ["//visibility:public"],
srcs = ["symphony_lake_parser.cc"],
deps = [
"@symphony_lake_parser",
"//common:check"
]
)

cc_test(
name = "symphony_lake_parser_test",
srcs = ["symphony_lake_parser_test.cc"],
copts = ["-Wno-unused-parameter"],
data = ["@symphony_lake_snippet"],
deps = [
"@com_google_googletest//:gtest_main",
":symphony_lake_parser",
"//common:check"
]
)

cc_test(
name = "gtsam_test",
srcs = ["gtsam_test.cc"],
Expand All @@ -25,4 +49,4 @@ cc_test(
"@gtsam//:gtsam",
":learn_descriptors"
]
)
)
15 changes: 15 additions & 0 deletions experimental/learn_descriptors/symphony_lake_parser.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "experimental/learn_descriptors/symphony_lake_parser.hh"

#include <iostream>

#include "common/check.hh"

namespace robot::experimental::learn_descriptors {
DataParser::DataParser(const std::filesystem::path &image_root_dir,
const std::vector<std::string> &survey_list) {
CHECK(std::filesystem::exists(image_root_dir), "Image root dir does not exist!",
image_root_dir);
surveys_.load(image_root_dir.string(), survey_list);
}
DataParser::~DataParser() {}
} // namespace robot::experimental::learn_descriptors
21 changes: 21 additions & 0 deletions experimental/learn_descriptors/symphony_lake_parser.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once
#pragma once
#include <string.h>

#include <filesystem>

#include "symphony_lake_dataset/SurveyVector.h"

namespace robot::experimental::learn_descriptors {
class DataParser {
public:
DataParser(const std::filesystem::path &image_root_dir,
const std::vector<std::string> &survey_list);
~DataParser();

const symphony_lake_dataset::SurveyVector &get_surveys() const { return surveys_; };

private:
symphony_lake_dataset::SurveyVector surveys_;
};
} // namespace robot::experimental::learn_descriptors
67 changes: 67 additions & 0 deletions experimental/learn_descriptors/symphony_lake_parser_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include "experimental/learn_descriptors/symphony_lake_parser.hh"

#include <cstdlib>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

#include "common/check.hh"
#include "gtest/gtest.h"
#include "opencv2/opencv.hpp"

namespace robot::experimental::learn_descriptors {
namespace {
bool is_test() { return std::getenv("BAZEL_TEST") != nullptr; }
} // namespace

class SymphonyLakeDatasetTestHelper {
public:
static bool images_equal(cv::Mat img1, cv::Mat img2) {
if (img1.size() != img2.size() || img1.type() != img2.type()) {
return false;
}
cv::Mat diff;
cv::absdiff(img1, img2, diff);
diff = diff.reshape(1);
return cv::countNonZero(diff) == 0;
}
};
TEST(SymphonyLakeParserTest, snippet_140106) {
const std::filesystem::path image_root_dir = "external/symphony_lake_snippet/symphony_lake";
const std::vector<std::string> survey_list{"140106_snippet"};

DataParser data_parser = DataParser(image_root_dir, survey_list);

const symphony_lake_dataset::SurveyVector &survey_vector = data_parser.get_surveys();

cv::Mat image;
cv::Mat target_img;
if (!is_test()) {
cv::namedWindow("Symphony Dataset Image", cv::WINDOW_AUTOSIZE);
}
printf("Press 'q' in graphic window to quit\n");
for (int i = 0; i < static_cast<int>(survey_vector.getNumSurveys()); i++) {
const symphony_lake_dataset::Survey &survey = survey_vector.get(i);
for (int j = 0; j < static_cast<int>(survey.getNumImages()); j++) {
image = survey.loadImageByImageIndex(j);

// get the target image
std::stringstream target_img_name;
target_img_name << "0000" << j << ".jpg";
const size_t target_img_name_length = 8;
std::string target_img_name_str = target_img_name.str();
target_img_name_str.replace(0, target_img_name_str.size() - target_img_name_length, "");
std::filesystem::path target_img_dir =
image_root_dir / survey_list[i] / "0027" / target_img_name_str;
target_img = cv::imread(target_img_dir.string());

EXPECT_TRUE(SymphonyLakeDatasetTestHelper::images_equal(image, target_img));
if (!is_test()) {
cv::imshow("Symphony Dataset Image", image);
cv::waitKey(2);
}
}
}
}
} // namespace robot::experimental::learn_descriptors
2 changes: 1 addition & 1 deletion setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ sudo apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get -y install clang clang-15 clang-format-15 libxcursor-dev \
libxrandr-dev libxinerama-dev libxi-dev freeglut3-dev libstdc++-12-dev gcc-11 g++-11 libtbb-dev \
libfmt-dev libspdlog-dev libvtk9-dev coinor-libipopt-dev coinor-libclp-dev \
libgirepository1.0-dev libcairo2-dev libcanberra-gtk-module
libgirepository1.0-dev libcairo2-dev libgtk2.0-dev libcanberra-gtk-module

26 changes: 26 additions & 0 deletions third_party/BUILD.symphony_lake_parser
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package(features=["-warning_compile_flags"])

cc_library(
name = "symphony_lake_parser",
hdrs = [
"include/symphony_lake_dataset/SurveyVector.h",
"include/symphony_lake_dataset/csv_functions.h",
"include/symphony_lake_dataset/Function.h",
"include/symphony_lake_dataset/ImagePoint.h",
"include/symphony_lake_dataset/ParseSurvey.h",
"include/symphony_lake_dataset/Pose.h",
"include/symphony_lake_dataset/Survey.h",
],
copts = ["-Wno-unused-parameter"],
visibility = ["//visibility:public"],
srcs = [
"src/Function.cpp",
"src/ParseSurvey.cpp",
"src/Survey.cpp",
"src/SurveyVector.cpp"
],
strip_include_prefix="include/",
deps = [
"@opencv//:opencv",
],
)
6 changes: 6 additions & 0 deletions third_party/BUILD.symphony_lake_snippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

filegroup(
name = "symphony_lake_snippet",
srcs = glob(["**/*"]),
visibility=["//visibility:public"],
)

0 comments on commit 74ba6cf

Please sign in to comment.