-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCaptureFileCameraVideo.hpp
More file actions
47 lines (38 loc) · 1.08 KB
/
Copy pathCaptureFileCameraVideo.hpp
File metadata and controls
47 lines (38 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#pragma once
#include <cmath>
#include <cstdint>
#include <string>
#include <opencv2/core.hpp>
#include <opencv2/videoio.hpp>
#include "CaptureFileCameraInput.hpp"
namespace CaptureFileCameraDetail
{
/// 读取视频文件的基本信息。
inline bool ReadVideoInfo(const std::string& path, VideoInfo& info)
{
cv::VideoCapture cap(path);
if (!cap.isOpened())
{
return false;
}
info.width = static_cast<int>(cap.get(cv::CAP_PROP_FRAME_WIDTH));
info.height = static_cast<int>(cap.get(cv::CAP_PROP_FRAME_HEIGHT));
info.fps = cap.get(cv::CAP_PROP_FPS);
if (info.fps > 0.0 && std::isfinite(info.fps))
{
info.fallback_period_us =
static_cast<uint64_t>(std::llround(microseconds_per_second / info.fps));
}
return true;
}
/// 普通视频文件读取器。
class VideoInput
{
public:
bool Open(const std::string& path) { return capture_.open(path); }
bool Read(cv::Mat& decoded) { return capture_.read(decoded); }
void Rewind() { capture_.set(cv::CAP_PROP_POS_FRAMES, 0.0); }
private:
cv::VideoCapture capture_{};
};
} // namespace CaptureFileCameraDetail