-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Nbuono/implement symphony dataset parser (#333)
Co-authored-by: Nicolaniello Buono <[email protected]> Co-authored-by: Nico Buono <[email protected]>
- Loading branch information
1 parent
8d32967
commit 74ba6cf
Showing
9 changed files
with
179 additions
and
3 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
67
experimental/learn_descriptors/symphony_lake_parser_test.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
filegroup( | ||
name = "symphony_lake_snippet", | ||
srcs = glob(["**/*"]), | ||
visibility=["//visibility:public"], | ||
) |