From 4d9c17c171564bcbc0dc6ed4cf9911d92e9c0f2a Mon Sep 17 00:00:00 2001 From: wangxinxin08 <69842442+wangxinxin08@users.noreply.github.com> Date: Wed, 21 Oct 2020 16:54:34 +0800 Subject: [PATCH] modify MkDir function to fix bugs (#1591) --- deploy/cpp/src/main.cc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/deploy/cpp/src/main.cc b/deploy/cpp/src/main.cc index 32e8b491f..9fa1ac03c 100644 --- a/deploy/cpp/src/main.cc +++ b/deploy/cpp/src/main.cc @@ -54,8 +54,7 @@ static bool PathExists(const std::string& path){ } static void MkDir(const std::string& path) { - std::string path_error(path); - path_error += " mkdir failed!"; + if (PathExists(path)) return; int ret = 0; #ifdef _WIN32 ret = _mkdir(path.c_str()); @@ -63,6 +62,8 @@ static void MkDir(const std::string& path) { ret = mkdir(path.c_str(), 0755); #endif // !_WIN32 if (ret != 0) { + std::string path_error(path); + path_error += " mkdir failed!"; throw std::runtime_error(path_error); } } @@ -169,8 +170,13 @@ void PredictImage(const std::string& image_path, std::vector compression_params; compression_params.push_back(CV_IMWRITE_JPEG_QUALITY); compression_params.push_back(95); - cv::imwrite(output_dir + OS_PATH_SEP + "output.jpg", vis_img, compression_params); - printf("Visualized output saved as output.jpg\n"); + std::string output_path(output_dir); + if (output_dir.rfind(OS_PATH_SEP) != output_dir.size() - 1) { + output_path += OS_PATH_SEP; + } + output_path += "output.jpg"; + cv::imwrite(output_path, vis_img, compression_params); + printf("Visualized output saved as %s\n", output_path.c_str()); } } -- GitLab