From b97fc1d9e3fb831ad9cf2a41ca849e8d41fa1ecf Mon Sep 17 00:00:00 2001 From: cnn Date: Fri, 2 Jul 2021 15:12:58 +0800 Subject: [PATCH] fix not find dirent.h on windows (#3550) --- deploy/cpp/docs/linux_build.md | 4 +-- deploy/cpp/src/main.cc | 47 ++++++++-------------------------- 2 files changed, 13 insertions(+), 38 deletions(-) diff --git a/deploy/cpp/docs/linux_build.md b/deploy/cpp/docs/linux_build.md index 5631e8a27..9d63bc8f5 100755 --- a/deploy/cpp/docs/linux_build.md +++ b/deploy/cpp/docs/linux_build.md @@ -35,7 +35,7 @@ fluid_inference **注意:** 预编译版本除`nv-jetson-cuda10-cudnn7.5-trt5` 以外其它包都是基于`GCC 4.8.5`编译,使用高版本`GCC`可能存在 `ABI`兼容性问题,建议降级或[自行编译预测库](https://www.paddlepaddle.org.cn/documentation/docs/zh/advanced_guide/inference_deployment/inference/build_and_install_lib_cn.html)。 -### Step4: 编译 +### Step3: 编译 编译`cmake`的命令在`scripts/build.sh`中,请根据实际情况修改主要参数,其主要内容说明如下: @@ -92,7 +92,7 @@ make **注意**: OPENCV依赖OPENBLAS,Ubuntu用户需确认系统是否已存在`libopenblas.so`。如未安装,可执行apt-get install libopenblas-dev进行安装。 -### Step5: 预测及可视化 +### Step4: 预测及可视化 编译成功后,预测入口程序为`build/main`其主要命令参数说明如下: | 参数 | 说明 | | ---- | ---- | diff --git a/deploy/cpp/src/main.cc b/deploy/cpp/src/main.cc index 0a16e4d3a..0f13ce005 100644 --- a/deploy/cpp/src/main.cc +++ b/deploy/cpp/src/main.cc @@ -1,3 +1,4 @@ + // Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,8 +15,8 @@ #include -#include #include +#include #include #include #include @@ -127,37 +128,6 @@ static void MkDirs(const std::string& path) { MkDir(path); } -void GetAllFiles(const char *dir_name, - std::vector &all_inputs) { - if (NULL == dir_name) { - std::cout << " dir_name is null ! " << std::endl; - return; - } - struct stat s; - lstat(dir_name, &s); - if (!S_ISDIR(s.st_mode)) { - std::cout << "dir_name is not a valid directory !" << std::endl; - all_inputs.push_back(dir_name); - return; - } else { - struct dirent *filename; // return value for readdir() - DIR *dir; // return value for opendir() - dir = opendir(dir_name); - if (NULL == dir) { - std::cout << "Can not open dir " << dir_name << std::endl; - return; - } - std::cout << "Successfully opened the dir !" << std::endl; - while ((filename = readdir(dir)) != NULL) { - if (strcmp(filename->d_name, ".") == 0 || - strcmp(filename->d_name, "..") == 0) - continue; - all_inputs.push_back(dir_name + std::string("/") + - std::string(filename->d_name)); - } - } -} - void PredictVideo(const std::string& video_path, PaddleDetection::ObjectDetector* det) { // Open video @@ -373,17 +343,22 @@ int main(int argc, char** argv) { if (!PathExists(FLAGS_output_dir)) { MkDirs(FLAGS_output_dir); } - std::vector all_imgs; + std::vector all_img_paths; + std::vector cv_all_img_paths; if (!FLAGS_image_file.empty()) { - all_imgs.push_back(FLAGS_image_file); + all_img_paths.push_back(FLAGS_image_file); if (FLAGS_batch_size > 1) { std::cout << "batch_size should be 1, when image_file is not None" << std::endl; FLAGS_batch_size = 1; } } else { - GetAllFiles((char *)FLAGS_image_dir.c_str(), all_imgs); + cv::glob(FLAGS_image_dir, cv_all_img_paths); + for (const auto & img_path : cv_all_img_paths) { + all_img_paths.push_back(img_path); + } } - PredictImage(all_imgs, FLAGS_batch_size, FLAGS_threshold, FLAGS_run_benchmark, &det, FLAGS_output_dir); + PredictImage(all_img_paths, FLAGS_batch_size, FLAGS_threshold, + FLAGS_run_benchmark, &det, FLAGS_output_dir); } return 0; } -- GitLab