update 添加异步存图

dev_lsy
xiewenji 4 weeks ago
parent fcc8fd70c7
commit 18afe43979

@ -62,6 +62,9 @@ public:
//创建目录 //创建目录
static int CreateDir(const std::string &dir); static int CreateDir(const std::string &dir);
// 异步存图
static int SaveImgAsync(const std::string &path, const cv::Mat &img);
// 点的距离是否过小 // 点的距离是否过小
static bool bcalDis(cv::Point p1, cv::Point p2, int disT); static bool bcalDis(cv::Point p1, cv::Point p2, int disT);
static double calDis(cv::Point p1, cv::Point p2); static double calDis(cv::Point p1, cv::Point p2);

@ -501,6 +501,32 @@ int CheckUtil::CreateDir(const std::string &dir)
return ret; return ret;
} }
int CheckUtil::SaveImgAsync(const std::string &path, const cv::Mat &img)
{
if (path.empty() || img.empty())
{
return -1;
}
// 拷贝图像,避免异步线程执行时原图像被释放或修改
cv::Mat imgCopy = img.clone();
// 创建保存路径的父目录
std::string::size_type pos = path.find_last_of('/');
if (pos != std::string::npos)
{
std::string parentDir = path.substr(0, pos);
CheckUtil::CreateDir(parentDir);
}
// 启动后台线程异步存图
std::thread([path, imgCopy]() {
cv::imwrite(path, imgCopy);
}).detach();
return 0;
}
bool CheckUtil::bcalDis(cv::Point p1, cv::Point p2, int disT) bool CheckUtil::bcalDis(cv::Point p1, cv::Point p2, int disT)
{ {
double dis = std::sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y)); double dis = std::sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));

Loading…
Cancel
Save