HDMI输入直至Yolov5识别全流程代码
This commit is contained in:
18
hdmiIn/rk3588_hdmi_in_out-in_and_out/include/fps_counter.h
Normal file
18
hdmiIn/rk3588_hdmi_in_out-in_and_out/include/fps_counter.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef FPS_COUNTER_H
|
||||
#define FPS_COUNTER_H
|
||||
|
||||
#include <chrono>
|
||||
#include <deque>
|
||||
|
||||
class FPSCounter {
|
||||
public:
|
||||
FPSCounter(size_t window_size = 10);
|
||||
double update();
|
||||
|
||||
private:
|
||||
size_t window_size_;
|
||||
std::deque<std::chrono::steady_clock::time_point> time_points_;
|
||||
std::deque<double> fps_values_;
|
||||
};
|
||||
|
||||
#endif // FPS_COUNTER_H
|
||||
25
hdmiIn/rk3588_hdmi_in_out-in_and_out/include/framebuffer.h
Normal file
25
hdmiIn/rk3588_hdmi_in_out-in_and_out/include/framebuffer.h
Normal file
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// Created by kaylor on 1/9/25.
|
||||
//
|
||||
|
||||
#ifndef FRAMEBUFFER_H
|
||||
#define FRAMEBUFFER_H
|
||||
#include "linux/fb.h"
|
||||
#include "opencv2/opencv.hpp"
|
||||
#include "string"
|
||||
|
||||
class FrameBuffer {
|
||||
public:
|
||||
FrameBuffer(std::string device);
|
||||
~FrameBuffer();
|
||||
bool WriteFrameBuffer(const cv::Mat image);
|
||||
|
||||
private:
|
||||
std::string device_;
|
||||
int fd_;
|
||||
char *fb_ptr_{nullptr};
|
||||
fb_fix_screeninfo fix_screeninfo_;
|
||||
fb_var_screeninfo var_screeninfo_;
|
||||
};
|
||||
|
||||
#endif // FRAMEBUFFER_H
|
||||
21
hdmiIn/rk3588_hdmi_in_out-in_and_out/include/hdmi_in.h
Normal file
21
hdmiIn/rk3588_hdmi_in_out-in_and_out/include/hdmi_in.h
Normal file
@@ -0,0 +1,21 @@
|
||||
//
|
||||
// Created by kaylor on 1/8/25.
|
||||
//
|
||||
|
||||
#ifndef HDMI_IN_H
|
||||
#define HDMI_IN_H
|
||||
|
||||
#include "opencv2/opencv.hpp"
|
||||
|
||||
class HdmiIn {
|
||||
public:
|
||||
HdmiIn(std::string device_name);
|
||||
~HdmiIn();
|
||||
cv::Mat get_next_frame();
|
||||
|
||||
private:
|
||||
cv::VideoCapture capture_;
|
||||
std::string device_name_;
|
||||
};
|
||||
|
||||
#endif // HDMI_IN_H
|
||||
39
hdmiIn/rk3588_hdmi_in_out-in_and_out/include/video_saver.h
Normal file
39
hdmiIn/rk3588_hdmi_in_out-in_and_out/include/video_saver.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef VIDEO_SAVER_H
|
||||
#define VIDEO_SAVER_H
|
||||
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <filesystem>
|
||||
#include <queue>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <thread>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
class VideoSaver {
|
||||
public:
|
||||
VideoSaver(int fps, int width, int height, size_t max_total_size_gb = 1);
|
||||
~VideoSaver();
|
||||
|
||||
void write_frame(const cv::Mat& frame);
|
||||
static void file_deleter();
|
||||
static void stop_file_deleter();
|
||||
|
||||
private:
|
||||
void start_new_file();
|
||||
void check_and_cleanup_files();
|
||||
|
||||
int fps_;
|
||||
int width_;
|
||||
int height_;
|
||||
int frame_count_;
|
||||
size_t max_total_size_bytes_;
|
||||
cv::VideoWriter writer_;
|
||||
|
||||
static std::mutex delete_mutex;
|
||||
static std::condition_variable delete_cv;
|
||||
static std::queue<std::string> files_to_delete_queue;
|
||||
static bool stop_delete_thread;
|
||||
};
|
||||
|
||||
#endif // VIDEO_SAVER_H
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef VIRTUAL_DEVICE_H
|
||||
#define VIRTUAL_DEVICE_H
|
||||
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <queue>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
|
||||
// 声明全局变量为 extern
|
||||
extern std::queue<cv::Mat> frame_queue;
|
||||
extern std::mutex queue_mutex;
|
||||
extern std::condition_variable queue_cv;
|
||||
extern bool stop_thread;
|
||||
|
||||
int init_virtual_device(const std::string& device_path, int width, int height);
|
||||
void write_to_virtual_device(int fd, const cv::Mat& frame);
|
||||
void virtual_device_writer(int fd);
|
||||
|
||||
#endif // VIRTUAL_DEVICE_H
|
||||
Reference in New Issue
Block a user