diff --git a/deploy/cpp/docs/linux_build.md b/deploy/cpp/docs/linux_build.md index 440d6b9d83686ec597d71ecc1b6b62f1dc3f55d1..b920e957e1d51229475209d985d2df719cd13ed9 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 ba38b0896373dd2e886751b51170e8a53474d849..a87294350351b03c5864c7641d3a081c733fd610 100644 --- a/deploy/cpp/src/main.cc +++ b/deploy/cpp/src/main.cc @@ -14,8 +14,8 @@ #include -#include #include +#include #include #include #include @@ -128,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 @@ -384,17 +353,21 @@ 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 set `image_file`." << std::endl; return -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, + PredictImage(all_img_paths, FLAGS_batch_size, FLAGS_threshold, FLAGS_run_benchmark, &det, FLAGS_output_dir); } return 0;