You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.0 KiB

#ifndef IMAGE_STORAGE_H
#define IMAGE_STORAGE_H
#include <opencv2/opencv.hpp>
#include <string>
#include <queue>
#include <thread>
#include <mutex>
#include <condition_variable>
class ImageStorage {
private:
std::queue<std::pair<cv::Mat, std::string>> imageQueue;
std::mutex queueMutex;
std::condition_variable cv;
std::thread storageThread;
static ImageStorage* instance; // 静态成员指针,存储单例对象
bool stopFlag;
// 私有构造函数和析构函数,防止外部创建实例
ImageStorage();
~ImageStorage();
// 存储线程的工作函数
void storeImages();
public:
// 获取单例实例
static ImageStorage* getInstance();
// 禁止拷贝构造和赋值
ImageStorage(const ImageStorage&) = delete;
ImageStorage& operator=(const ImageStorage&) = delete;
// 添加图片到队列
int addImage(const std::string &path,const cv::Mat &image,bool badd = false);
// 停止存储线程
void stop();
};
#endif // IMAGE_STORAGE_H