Add option to run ar playback without loading images

This commit is contained in:
Georg Hagen
2024-09-22 16:20:55 +02:00
committed by ohyzha
parent 953d032b59
commit 2142118771
5 changed files with 33 additions and 24 deletions

View File

@@ -57,11 +57,11 @@ namespace OpenVulkano::AR
return { nullptr, ArCreateResult::FAILED_UNKNOWN, "Unknown exception while initializing AR system." }; return { nullptr, ArCreateResult::FAILED_UNKNOWN, "Unknown exception while initializing AR system." };
} }
ArCreateResult ArSession::CreatePlayback(const std::string& recordingPath, bool autoAdvance) ArCreateResult ArSession::CreatePlayback(const std::string& recordingPath, bool autoAdvance, bool loadImages, bool loadDepth)
{ {
try try
{ {
const auto session = std::make_shared<Playback::ArSessionPlayback>(recordingPath, autoAdvance); const auto session = std::make_shared<Playback::ArSessionPlayback>(recordingPath, autoAdvance, loadImages, loadDepth);
sessions.push_back(session); sessions.push_back(session);
return { session, ArCreateResult::SUCCESS, "" }; return { session, ArCreateResult::SUCCESS, "" };
} }

View File

@@ -113,7 +113,7 @@ namespace OpenVulkano::AR
* @param autoAdvance If set to true the playback will advance based on the stored timestamps. If set to false it will only advance if a new frame is requested. * @param autoAdvance If set to true the playback will advance based on the stored timestamps. If set to false it will only advance if a new frame is requested.
* @return ArCreateResult about the status of the AR session creation. The session pointer will always be nullptr unless the status is SUCCESS. * @return ArCreateResult about the status of the AR session creation. The session pointer will always be nullptr unless the status is SUCCESS.
*/ */
[[nodiscard]] static ArCreateResult CreatePlayback(const std::string& recordingPath, bool autoAdvance = true); [[nodiscard]] static ArCreateResult CreatePlayback(const std::string& recordingPath, bool autoAdvance = true, bool loadImages = true, bool loadDepth = true);
/** /**
* Creates a network streamed AR session. nullptr if failed to create session for given address. This will block till the connection with the remote host has been established. * Creates a network streamed AR session. nullptr if failed to create session for given address. This will block till the connection with the remote host has been established.

View File

@@ -16,21 +16,26 @@ namespace OpenVulkano::AR::Playback
//BlockProfiler profile("Read_AR_Frame"); //BlockProfiler profile("Read_AR_Frame");
const auto data = frameReader.ReadMetadata(); const auto data = frameReader.ReadMetadata();
frameMetadata = ArFrameMetadata::FromXML(data.Data(), data.Size()); frameMetadata = ArFrameMetadata::FromXML(data.Data(), data.Size());
colorImgData = frameReader.ReadColorImage(); if (session->GetCapabilities().IsDepthSupported())
auto depth = frameReader.ReadDepthImage(); {
confImgData = std::move(depth.confidence.image); auto depth = frameReader.ReadDepthImage();
depthImgData = std::move(depth.depth.image); confImgData = std::move(depth.confidence.image);
depthImage.format = session->GetSessionMetadata().depthFormat; depthImgData = std::move(depth.depth.image);
depthImage.intrinsic = frameMetadata.intrinsic.GetForResolution({depth.depth.header.width, depth.depth.header.height}); depthImage.format = session->GetSessionMetadata().depthFormat;
depthImage.depth.data = depthImgData.get(); depthImage.intrinsic = frameMetadata.intrinsic.GetForResolution({depth.depth.header.width, depth.depth.header.height});
depthImage.depth.resolution = { depth.depth.header.width, depth.depth.header.height }; depthImage.depth.data = depthImgData.get();
depthImage.confidence.data = confImgData.get(); depthImage.depth.resolution = {depth.depth.header.width, depth.depth.header.height};
depthImage.depth.resolution = { depth.confidence.header.width, depth.confidence.header.height }; depthImage.confidence.data = confImgData.get();
depthImage.depth.resolution = {depth.confidence.header.width, depth.confidence.header.height};
colorImage.intrinsic = frameMetadata.intrinsic.GetForResolution({ colorImgData.cols, colorImgData.rows }); }
colorImage.format = ArImagePlanar::Format::RGB; if (session->IsLoadColorEnabled())
colorImage.luminescenceOrColor = { colorImgData.data, { colorImgData.cols, colorImgData.rows }}; {
colorImage.luminescenceOrColor.numChannels = colorImgData.channels; colorImgData = frameReader.ReadColorImage();
colorImage.intrinsic = frameMetadata.intrinsic.GetForResolution({colorImgData.cols, colorImgData.rows});
colorImage.format = ArImagePlanar::Format::RGB;
colorImage.luminescenceOrColor = {colorImgData.data, {colorImgData.cols, colorImgData.rows}};
colorImage.luminescenceOrColor.numChannels = colorImgData.channels;
}
SetSaved(); SetSaved();
} }

View File

@@ -14,10 +14,11 @@ using namespace std::chrono_literals;
namespace OpenVulkano::AR::Playback namespace OpenVulkano::AR::Playback
{ {
ArSessionPlayback::ArSessionPlayback(const std::string& recordingPath, bool autoAdvance) ArSessionPlayback::ArSessionPlayback(const std::string& recordingPath, bool autoAdvance, bool loadImages, bool loadDepth)
: ArSession(ArSessionMetadata(recordingPath)), recordingPath(recordingPath), autoAdvance(autoAdvance), playbackReader(recordingPath) : ArSession(ArSessionMetadata(recordingPath)), recordingPath(recordingPath), autoAdvance(autoAdvance)
, loadImages(loadImages), loadDepth(loadDepth), playbackReader(recordingPath)
{ {
capabilities = ArSessionCapabilities(metadata.type, ArSessionType::PLAYBACK, false, metadata.depthFormat != ArDepthFormat::UNAVAILABLE, false, false, false); capabilities = ArSessionCapabilities(metadata.type, ArSessionType::PLAYBACK, false, metadata.depthFormat != ArDepthFormat::UNAVAILABLE && loadDepth, false, false, false);
constants = { Math::Matrix4f(1), metadata.confidenceRange }; constants = { Math::Matrix4f(1), metadata.confidenceRange };
m_playbackReaderThread = std::thread([this](){ReadWorker();}); m_playbackReaderThread = std::thread([this](){ReadWorker();});

View File

@@ -15,7 +15,7 @@ namespace OpenVulkano::AR::Playback
class ArSessionPlayback final : public ArSession, public std::enable_shared_from_this<ArSessionPlayback> class ArSessionPlayback final : public ArSession, public std::enable_shared_from_this<ArSessionPlayback>
{ {
public: public:
ArSessionPlayback(const std::string& recordingPath, bool autoAdvance); ArSessionPlayback(const std::string& recordingPath, bool autoAdvance, bool loadImages, bool loadDepth);
~ArSessionPlayback() override; ~ArSessionPlayback() override;
@@ -33,12 +33,15 @@ class ArSessionPlayback final : public ArSession, public std::enable_shared_from
[[nodiscard]] const std::string& GetPlaybackPath() const { return recordingPath; } [[nodiscard]] const std::string& GetPlaybackPath() const { return recordingPath; }
[[nodiscard]] bool IsLoadColorEnabled() const { return loadImages; }
[[nodiscard]] bool IsLoadDepthEnabled() const { return loadDepth; }
void SetRenderer(IRenderer* renderer) override; void SetRenderer(IRenderer* renderer) override;
Event<double> OnPlaybackProgress; Event<double> OnPlaybackProgress;
protected: protected:
Scene::Texture * MakeTexture(OpenVulkano::AR::ArFrame *frame) override; Scene::Texture* MakeTexture(OpenVulkano::AR::ArFrame* frame) override;
void ReturnTexture(Scene::Texture *texture) override; void ReturnTexture(Scene::Texture *texture) override;
@@ -48,7 +51,7 @@ class ArSessionPlayback final : public ArSession, public std::enable_shared_from
Math::Timestamp lastTimestamp; Math::Timestamp lastTimestamp;
const std::string recordingPath; const std::string recordingPath;
const bool autoAdvance; const bool autoAdvance, loadImages, loadDepth;
ArPlaybackReader playbackReader; ArPlaybackReader playbackReader;
ArTrackingState m_lastTrackingState = ArTrackingState::UNKNOWN; ArTrackingState m_lastTrackingState = ArTrackingState::UNKNOWN;