#include <filesystem>
using namespace std;
namespace fs = std::filesystem;
标签:std,遍历,obj,17,image,C++,entry,path,cv From: https://www.cnblogs.com/WenJXUST/p/17145414.html
string path = filepath; // 替换为指定目录的路径 for (const auto& entry : fs::directory_iterator(path)) { if (entry.is_regular_file() && entry.path().extension() == ".jpg") { //std::cout << entry.path() << std::endl; // 输出jpg文件路径 fs::path dPath = entry.path(); string ddPath = dPath.string(); cv::Mat m = cv::imread(ddPath, 1); if (m.empty()) { fprintf(stderr, "cv::imread %s failed\n", imagepath); return -1; } double t1 = (double)cv::getTickCount(); std::vector<lineMLSD> lines; detect_mlsd(m, lines); //////////draw///////////////// cv::Mat image = m.clone(); for (size_t i = 0; i < lines.size(); i++) { const lineMLSD& obj = lines[i]; fprintf(stderr, "%d %d %d x %d\n", obj.sp.x, obj.sp.y, obj.ep.x, obj.ep.y); cv::line(image, obj.sp, obj.ep, cv::Scalar(0, 0, 255), 2); } float fps = (double)cv::getTickFrequency() / (cv::getTickCount() - t1); cv::putText(image, "FPS : " + std::to_string(int(fps)), cv::Point(50, 50), cv::FONT_HERSHEY_SIMPLEX, 1.5, cv::Scalar(50, 150, 50), 4); cv::imwrite("out/" + entry.path().filename().string(), image); } }