Update ArSessionMetadata

This commit is contained in:
Georg Hagen
2024-12-06 16:08:51 +01:00
parent 79f87747db
commit 18fe7eb544
2 changed files with 56 additions and 16 deletions

View File

@@ -14,8 +14,7 @@
namespace OpenVulkano::AR
{
ArSessionMetadata::ArSessionMetadata()
: ArSessionMetadata(ArType::UNKNOWN, ArDepthFormat::UNAVAILABLE, {0,0}, { 1920, 1440 }, 60,
SystemInfo::GetDeviceModelName(), SystemInfo::GetOsNameHumanReadable())
: ArSessionMetadata(ArType::UNKNOWN, ArDepthFormat::UNAVAILABLE, {0,0}, { 1920, 1440 }, 60)
{}
ArSessionMetadata::ArSessionMetadata(ArType type, ArDepthFormat format, Math::Range<uint8_t> confRange, Math::Vector2ui resolution, float frameRate)
@@ -54,33 +53,48 @@ namespace OpenVulkano::AR
{
YAML::Node meta = YAML::LoadFile(filePath);
return {
ArSessionMetadata metadata = {
ArType::GetFromName(meta["Type"].Scalar()),
ArDepthFormat::GetFromName(meta["DepthType"].Scalar()).value_or(ArDepthFormat::UNAVAILABLE),
Math::Range<uint8_t>(meta["MinConfidence"].as<uint8_t>(), meta["MaxConfidence"].as<uint8_t>()),
meta["Resolution"].as<Math::Vector2ui>(),
meta["FrameRate"].as<float>(60),
meta["Resolution"].as<Math::Vector2ui>(), meta["FrameRate"].as<float>(60),
meta["Device"].as<std::string>("Unknown"), meta["OS"].as<std::string>("Unknown"),
meta["Vesion"].as<uint32_t>(2)
meta["Version"].as<uint32_t>(2)
};
auto recNode = meta["Recording"];
if (recNode.IsMap())
{
metadata.recDuration = recNode["Duration"].as<int32_t>(-1);
metadata.recFrameCount = recNode["FrameCount"].as<int64_t>(-1);
metadata.recSkippedFrames = recNode["SkippedFrames"].as<int32_t>(-1);
}
return metadata;
}
ArSessionMetadata::ArSessionMetadata(const std::string& dirPath)
bool ArSessionMetadata::DirHasMetadata(const std::filesystem::path& dirPath)
{
return std::filesystem::exists(dirPath / RECORDING_METADATA_FILENAME_INFO) ||
std::filesystem::exists(dirPath / RECORDING_METADATA_FILENAME_XML) ||
std::filesystem::exists(dirPath / RECORDING_METADATA_FILENAME);
}
ArSessionMetadata::ArSessionMetadata(const std::filesystem::path& dirPath)
{
std::optional<ArSessionMetadata> metaFromFile;
std::filesystem::path rPath(dirPath);
if (!is_directory(rPath)) throw std::runtime_error("Ar recording path must be a directory!");
std::filesystem::path xmlInfoPath(dirPath + "/arType.info");
if (!is_directory(dirPath)) throw std::runtime_error("Ar recording path must be a directory!");
std::filesystem::path xmlInfoPath(dirPath / RECORDING_METADATA_FILENAME_INFO);
if (std::filesystem::exists(xmlInfoPath))
{
metaFromFile = FromXML(xmlInfoPath.string());
}
xmlInfoPath = { dirPath + "/ArRecording.xml" };
xmlInfoPath = dirPath / RECORDING_METADATA_FILENAME_XML;
if (std::filesystem::exists(xmlInfoPath))
{
metaFromFile = FromXML(xmlInfoPath.string());
}
std::filesystem::path ymlInfoPath(dirPath + "/ArRecording.yml");
std::filesystem::path ymlInfoPath = dirPath / RECORDING_METADATA_FILENAME;
if (std::filesystem::exists(ymlInfoPath))
{
metaFromFile = FromYaml(ymlInfoPath.string());
@@ -109,19 +123,31 @@ namespace OpenVulkano::AR
depthFormat.GetAltName(), imageResolution.x, imageResolution.y, frameRate, device, os, version);
}
std::string ArSessionMetadata::FinishedRecordingInfoToYaml() const
{
if (recFrameCount < 1 || recDuration < 1 || recSkippedFrames < 1) return "";
return fmt::format(R"(Recording:
Duration: {}
FrameCount: {}
SkippedFrames: {}
)",
recDuration, recFrameCount, recSkippedFrames);
}
std::string ArSessionMetadata::ToYaml() const
{
return fmt::format(R"(Type: {}
DepthType: {}
MinConfidence: {}
MaxConfidence: {}
Resolution: ({},{})
Resolution: '({},{})'
FrameRate: {}
Device: {}
OS: {}
Version: {}
{}
)",
type.GetName(), depthFormat.GetName(), static_cast<int>(confidenceRange.min), static_cast<int>(confidenceRange.max),
imageResolution.x, imageResolution.y, frameRate, device, os, version);
imageResolution.x, imageResolution.y, frameRate, device, os, version, FinishedRecordingInfoToYaml());
}
}