SmartSpectra C++ SDK
Measure human vitals from video with SmartSpectra C++ SDK.
Loading...
Searching...
No Matches
file_stream.hpp
1//
2// Created by greg on 2/28/24.
3// Copyright (c) 2024 Presage Technologies
4//
5
6#pragma once
7// === standard library includes (if any) ===
8#include <string>
9#include <regex>
10#include <filesystem>
11#include <map>
12// === third-party includes (if any) ===
13#include <absl/status/statusor.h>
14#include <mediapipe/framework/port/opencv_core_inc.h>
15#include <mediapipe/framework/port/opencv_imgcodecs_inc.h>
16// === local includes (if any) ===
17#include <smartspectra/video_source/video_source.hpp>
18
19
20namespace presage::smartspectra::video_source::file_stream {
21
23public:
24 absl::Status Initialize(const VideoSourceSettings& settings);
25
26 [[nodiscard]] bool SupportsExactFrameTimestamp() const override;
27
28 [[nodiscard]] int64_t GetFrameTimestamp() const override;
29
30 int GetWidth() override;
31 int GetHeight() override;
32protected:
33 void ProducePreTransformFrame(cv::Mat& frame) override;
34private:
35 const int64_t kTimestampNotYetSet = -1;
36
37 // static
38 static absl::StatusOr<std::regex> BuildFrameFileNameRegex(const std::string& wildcard_filename_mask);
39
40 std::map<int64_t, std::filesystem::path> ScanInputDirectory();
41
42 // parameters
43 std::regex frame_filename_regex;
44 std::filesystem::path directory;
45 std::string end_of_stream_filename;
46 int retry_delay_ms = 10;
47 bool erase_read_files;
48 bool loop;
49
50 // state
51 int64_t i_frame = 0;
52 int64_t current_frame_timestamp = kTimestampNotYetSet;
53 bool end_of_stream_encountered = false;
54 // only used in loop mode
55 std::map<int64_t, std::filesystem::path> loop_frame_filenames;
56 std::map<int64_t, std::filesystem::path>::iterator current_frame_data;
57 std::filesystem::path end_of_stream_path;
58
59 int first_frame_width = -1;
60 int first_frame_height = -1;
61};
62
63
64} // namespace presage::smartspectra::video_source::file_stream
Abstract interface for camera/video input sources.
Definition video_source.hpp:30
int64_t GetFrameTimestamp() const override
Definition file_stream.cpp:118
absl::Status Initialize(const VideoSourceSettings &settings)
Definition file_stream.cpp:122
Configuration options for constructing a VideoSource.
Definition settings.hpp:23