diff --git a/deploy/cpp/demo/classifier.cpp b/deploy/cpp/demo/classifier.cpp index 1ed05d524be87c86e3cf51933ef20695a5603182..cf3bb5ccf64c43ec42d59a9b73fdced6b50b8dc5 100644 --- a/deploy/cpp/demo/classifier.cpp +++ b/deploy/cpp/demo/classifier.cpp @@ -51,7 +51,7 @@ int main(int argc, char** argv) { return -1; } - // 加载模型 + // Load model PaddleX::Model model; model.Init(FLAGS_model_dir, FLAGS_use_gpu, @@ -59,7 +59,7 @@ int main(int argc, char** argv) { FLAGS_gpu_id, FLAGS_key); - // 进行预测 + // Predict int imgs = 1; if (FLAGS_image_list != "") { std::ifstream inf(FLAGS_image_list); @@ -67,7 +67,7 @@ int main(int argc, char** argv) { std::cerr << "Fail to open file " << FLAGS_image_list << std::endl; return -1; } - // 多batch预测 + // Mini-batch predict std::string image_path; std::vector image_paths; while (getline(inf, image_path)) { @@ -75,7 +75,7 @@ int main(int argc, char** argv) { } imgs = image_paths.size(); for (int i = 0; i < image_paths.size(); i += FLAGS_batch_size) { - // 读图像 + // Read image int im_vec_size = std::min(static_cast(image_paths.size()), i + FLAGS_batch_size); std::vector im_vec(im_vec_size - i); diff --git a/deploy/cpp/demo/detector.cpp b/deploy/cpp/demo/detector.cpp index 0dedd5e6b56894ee48a2a4e8aaaddb3bef358b62..ef7fd782715bef5d9cc1dae43c87ceaa123e914f 100644 --- a/deploy/cpp/demo/detector.cpp +++ b/deploy/cpp/demo/detector.cpp @@ -45,7 +45,7 @@ DEFINE_int32(thread_num, "Number of preprocessing threads"); int main(int argc, char** argv) { - // 解析命令行参数 + // Parsing command-line google::ParseCommandLineFlags(&argc, &argv, true); if (FLAGS_model_dir == "") { @@ -56,7 +56,7 @@ int main(int argc, char** argv) { std::cerr << "--image or --image_list need to be defined" << std::endl; return -1; } - // 加载模型 + // Load model PaddleX::Model model; model.Init(FLAGS_model_dir, FLAGS_use_gpu, @@ -65,7 +65,7 @@ int main(int argc, char** argv) { FLAGS_key); int imgs = 1; std::string save_dir = "output"; - // 进行预测 + // Predict if (FLAGS_image_list != "") { std::ifstream inf(FLAGS_image_list); if (!inf) { @@ -90,7 +90,7 @@ int main(int argc, char** argv) { im_vec[j - i] = std::move(cv::imread(image_paths[j], 1)); } model.predict(im_vec, &results, thread_num); - // 输出结果目标框 + // Output predicted bounding boxes for (int j = 0; j < im_vec_size - i; ++j) { for (int k = 0; k < results[j].boxes.size(); ++k) { std::cout << "image file: " << image_paths[i + j] << ", "; @@ -104,7 +104,7 @@ int main(int argc, char** argv) { << results[j].boxes[k].coordinate[3] << ")" << std::endl; } } - // 可视化 + // Visualize results for (int j = 0; j < im_vec_size - i; ++j) { cv::Mat vis_img = PaddleX::Visualize( im_vec[j], results[j], model.labels, FLAGS_threshold); @@ -118,7 +118,7 @@ int main(int argc, char** argv) { PaddleX::DetResult result; cv::Mat im = cv::imread(FLAGS_image, 1); model.predict(im, &result); - // 输出结果目标框 + // Output predicted bounding boxes for (int i = 0; i < result.boxes.size(); ++i) { std::cout << "image file: " << FLAGS_image << std::endl; std::cout << ", predict label: " << result.boxes[i].category @@ -130,7 +130,7 @@ int main(int argc, char** argv) { << result.boxes[i].coordinate[3] << ")" << std::endl; } - // 可视化 + // Visualize results cv::Mat vis_img = PaddleX::Visualize(im, result, model.labels, FLAGS_threshold); std::string save_path = diff --git a/deploy/cpp/demo/segmenter.cpp b/deploy/cpp/demo/segmenter.cpp index 351e1f7dd815ac4bea23797f352088d75aa2c683..d13a328f5beecc90fe9257a4f32ee63a8fe609a5 100644 --- a/deploy/cpp/demo/segmenter.cpp +++ b/deploy/cpp/demo/segmenter.cpp @@ -41,7 +41,7 @@ DEFINE_int32(thread_num, "Number of preprocessing threads"); int main(int argc, char** argv) { - // 解析命令行参数 + // Parsing command-line google::ParseCommandLineFlags(&argc, &argv, true); if (FLAGS_model_dir == "") { @@ -53,7 +53,7 @@ int main(int argc, char** argv) { return -1; } - // 加载模型 + // Load model PaddleX::Model model; model.Init(FLAGS_model_dir, FLAGS_use_gpu, @@ -61,7 +61,7 @@ int main(int argc, char** argv) { FLAGS_gpu_id, FLAGS_key); int imgs = 1; - // 进行预测 + // Predict if (FLAGS_image_list != "") { std::ifstream inf(FLAGS_image_list); if (!inf) { @@ -86,7 +86,7 @@ int main(int argc, char** argv) { im_vec[j - i] = std::move(cv::imread(image_paths[j], 1)); } model.predict(im_vec, &results, thread_num); - // 可视化 + // Visualize results for (int j = 0; j < im_vec_size - i; ++j) { cv::Mat vis_img = PaddleX::Visualize(im_vec[j], results[j], model.labels); @@ -100,7 +100,7 @@ int main(int argc, char** argv) { PaddleX::SegResult result; cv::Mat im = cv::imread(FLAGS_image, 1); model.predict(im, &result); - // 可视化 + // Visualize results cv::Mat vis_img = PaddleX::Visualize(im, result, model.labels); std::string save_path = PaddleX::generate_save_path(FLAGS_save_dir, FLAGS_image); diff --git a/deploy/cpp/demo/video_classifier.cpp b/deploy/cpp/demo/video_classifier.cpp index 9a97919180e0ef098fc3393c20569c43c5a42e29..96be867d40800455184b7938dc829e8a0b8f8390 100644 --- a/deploy/cpp/demo/video_classifier.cpp +++ b/deploy/cpp/demo/video_classifier.cpp @@ -57,7 +57,7 @@ int main(int argc, char** argv) { return -1; } - // 加载模型 + // Load model PaddleX::Model model; model.Init(FLAGS_model_dir, FLAGS_use_gpu, @@ -65,7 +65,7 @@ int main(int argc, char** argv) { FLAGS_gpu_id, FLAGS_key); - // 打开视频流 + // Open video cv::VideoCapture capture; if (FLAGS_use_camera) { capture.open(FLAGS_camera_id); @@ -85,11 +85,11 @@ int main(int argc, char** argv) { } } - // 创建VideoWriter + // Create a VideoWriter cv::VideoWriter video_out; std::string video_out_path; if (FLAGS_save_result) { - // 获取视频流信息: 分辨率, 帧率 + // Get video information: resolution, fps int video_width = static_cast(capture.get(CV_CAP_PROP_FRAME_WIDTH)); int video_height = static_cast(capture.get(CV_CAP_PROP_FRAME_HEIGHT)); int video_fps = static_cast(capture.get(CV_CAP_PROP_FPS)); @@ -126,16 +126,16 @@ int main(int argc, char** argv) { while (capture.read(frame)) { if (FLAGS_show_result || FLAGS_use_camera) { key = cv::waitKey(1); - // 按下ESC退出整个程序,保存视频文件到磁盘 + // When pressing `ESC`, then exit program and result video is saved if (key == 27) { break; } } else if (frame.empty()) { break; } - // 开始预测 + // Begin to predict model.predict(frame, &result); - // 可视化 + // Visualize results cv::Mat vis_img = frame.clone(); auto colormap = PaddleX::GenerateColorMap(model.labels.size()); int c1 = colormap[3 * result.category_id + 0]; diff --git a/deploy/cpp/demo/video_detector.cpp b/deploy/cpp/demo/video_detector.cpp index 83135577cda54178ce3f1f1d38b48270d652e9db..ee4d5bdb138d03020042e60d41ded0ca1efde46d 100644 --- a/deploy/cpp/demo/video_detector.cpp +++ b/deploy/cpp/demo/video_detector.cpp @@ -48,7 +48,7 @@ DEFINE_double(threshold, "The minimum scores of target boxes which are shown"); int main(int argc, char** argv) { - // 解析命令行参数 + // Parsing command-line google::ParseCommandLineFlags(&argc, &argv, true); if (FLAGS_model_dir == "") { @@ -59,14 +59,14 @@ int main(int argc, char** argv) { std::cerr << "--video_path or --use_camera need to be defined" << std::endl; return -1; } - // 加载模型 + // Load model PaddleX::Model model; model.Init(FLAGS_model_dir, FLAGS_use_gpu, FLAGS_use_trt, FLAGS_gpu_id, FLAGS_key); - // 打开视频流 + // Open video cv::VideoCapture capture; if (FLAGS_use_camera) { capture.open(FLAGS_camera_id); @@ -86,11 +86,11 @@ int main(int argc, char** argv) { } } - // 创建VideoWriter + // Create a VideoWriter cv::VideoWriter video_out; std::string video_out_path; if (FLAGS_save_result) { - // 获取视频流信息: 分辨率, 帧率 + // Get video information: resolution, fps int video_width = static_cast(capture.get(CV_CAP_PROP_FRAME_WIDTH)); int video_height = static_cast(capture.get(CV_CAP_PROP_FRAME_HEIGHT)); int video_fps = static_cast(capture.get(CV_CAP_PROP_FPS)); @@ -127,15 +127,16 @@ int main(int argc, char** argv) { while (capture.read(frame)) { if (FLAGS_show_result || FLAGS_use_camera) { key = cv::waitKey(1); - // 按下ESC退出整个程序,保存视频文件到磁盘 + // When pressing `ESC`, then exit program and result video is saved if (key == 27) { break; } } else if (frame.empty()) { break; } + // Begin to predict model.predict(frame, &result); - // 可视化 + // Visualize results cv::Mat vis_img = PaddleX::Visualize(frame, result, model.labels, FLAGS_threshold); if (FLAGS_show_result || FLAGS_use_camera) { diff --git a/deploy/cpp/demo/video_segmenter.cpp b/deploy/cpp/demo/video_segmenter.cpp index e26c6db05313e1bf8463889c03eadf493d845577..6a835117cd1434b5f26e0fb660e6fe07ef56e607 100644 --- a/deploy/cpp/demo/video_segmenter.cpp +++ b/deploy/cpp/demo/video_segmenter.cpp @@ -45,7 +45,7 @@ DEFINE_bool(save_result, true, "save the result of each frame to a video"); DEFINE_string(save_dir, "output", "Path to save visualized image"); int main(int argc, char** argv) { - // 解析命令行参数 + // Parsing command-line google::ParseCommandLineFlags(&argc, &argv, true); if (FLAGS_model_dir == "") { @@ -57,14 +57,14 @@ int main(int argc, char** argv) { return -1; } - // 加载模型 + // Load model PaddleX::Model model; model.Init(FLAGS_model_dir, FLAGS_use_gpu, FLAGS_use_trt, FLAGS_gpu_id, FLAGS_key); - // 打开视频流 + // Open video cv::VideoCapture capture; if (FLAGS_use_camera) { capture.open(FLAGS_camera_id); @@ -85,11 +85,11 @@ int main(int argc, char** argv) { } - // 创建VideoWriter + // Create a VideoWriter cv::VideoWriter video_out; std::string video_out_path; if (FLAGS_save_result) { - // 获取视频流信息: 分辨率, 帧率 + // Get video information: resolution, fps int video_width = static_cast(capture.get(CV_CAP_PROP_FRAME_WIDTH)); int video_height = static_cast(capture.get(CV_CAP_PROP_FRAME_HEIGHT)); int video_fps = static_cast(capture.get(CV_CAP_PROP_FPS)); @@ -126,16 +126,16 @@ int main(int argc, char** argv) { while (capture.read(frame)) { if (FLAGS_show_result || FLAGS_use_camera) { key = cv::waitKey(1); - // 按下ESC退出整个程序,保存视频文件到磁盘 + // When pressing `ESC`, then exit program and result video is saved if (key == 27) { break; } } else if (frame.empty()) { break; } - // 开始预测 + // Begin to predict model.predict(frame, &result); - // 可视化 + // Visualize results cv::Mat vis_img = PaddleX::Visualize(frame, result, model.labels); if (FLAGS_show_result || FLAGS_use_camera) { cv::imshow("video_segmenter", vis_img); diff --git a/examples/human_segmentation/deploy/cpp/human_segmenter.cpp b/examples/human_segmentation/deploy/cpp/human_segmenter.cpp index 02c4e3441669d1dae98607c93fb0a75eeae6456e..479c7a7fd469f6fcfa2cf7b980114893a4febd78 100644 --- a/examples/human_segmentation/deploy/cpp/human_segmenter.cpp +++ b/examples/human_segmentation/deploy/cpp/human_segmenter.cpp @@ -46,7 +46,7 @@ DEFINE_bool(save_result, true, "save the result of each frame to a video"); DEFINE_string(save_dir, "output", "Path to save visualized image"); int main(int argc, char** argv) { - // 解析命令行参数 + // Parsing command-line google::ParseCommandLineFlags(&argc, &argv, true); if (FLAGS_model_dir == "") { @@ -60,7 +60,7 @@ int main(int argc, char** argv) { return -1; } - // 加载模型 + // Load model PaddleX::Model model; model.Init(FLAGS_model_dir, FLAGS_use_gpu, @@ -68,7 +68,7 @@ int main(int argc, char** argv) { FLAGS_gpu_id, FLAGS_key); if (FLAGS_use_camera || FLAGS_video_path != "") { - // 打开视频流 + // Open video cv::VideoCapture capture; if (FLAGS_use_camera) { capture.open(FLAGS_camera_id); @@ -88,11 +88,11 @@ int main(int argc, char** argv) { } } - // 创建VideoWriter + // Create a VideoWriter cv::VideoWriter video_out; std::string video_out_path; if (FLAGS_save_result) { - // 获取视频流信息: 分辨率, 帧率 + // Get video information: resolution, fps int video_width = static_cast(capture.get(CV_CAP_PROP_FRAME_WIDTH)); int video_height = static_cast(capture.get(CV_CAP_PROP_FRAME_HEIGHT)); @@ -129,16 +129,16 @@ int main(int argc, char** argv) { while (capture.read(frame)) { if (FLAGS_show_result || FLAGS_use_camera) { key = cv::waitKey(1); - // 按下ESC退出整个程序,保存视频文件到磁盘 + // When pressing `ESC`, then exit program and result video is saved if (key == 27) { break; } } else if (frame.empty()) { break; } - // 开始预测 + // Begin to predict model.predict(frame, &result); - // 可视化 + // Visualize results std::vector label_map(result.label_map.data.begin(), result.label_map.data.end()); cv::Mat mask(result.label_map.shape[0], @@ -178,7 +178,7 @@ int main(int argc, char** argv) { PaddleX::SegResult result; cv::Mat im = cv::imread(FLAGS_image, 1); model.predict(im, &result); - // 可视化 + // Visualize results std::vector label_map(result.label_map.data.begin(), result.label_map.data.end()); cv::Mat mask(result.label_map.shape[0], diff --git a/examples/meter_reader/deploy/cpp/meter_reader/meter_reader.cpp b/examples/meter_reader/deploy/cpp/meter_reader/meter_reader.cpp index 79307fa05eb7b99c753fd978bcec9f0eb1e2f534..04c6f0e5316e9024c4f103e120a72f2f98f34203 100644 --- a/examples/meter_reader/deploy/cpp/meter_reader/meter_reader.cpp +++ b/examples/meter_reader/deploy/cpp/meter_reader/meter_reader.cpp @@ -51,7 +51,8 @@ DEFINE_string(seg_key, "", "Segmenter model key of encryption"); DEFINE_string(image, "", "Path of test image file"); DEFINE_string(image_list, "", "Path of test image list file"); DEFINE_string(save_dir, "output", "Path to save visualized image"); -DEFINE_double(score_threshold, 0.5, "Detected bbox whose score is lower than this threshlod is filtered"); +DEFINE_double(score_threshold, 0.5, + "Detected bbox whose score is lower than this threshlod is filtered"); void predict(const cv::Mat &input_image, PaddleX::Model *det_model, PaddleX::Model *seg_model, const std::string save_dir, @@ -207,7 +208,7 @@ int main(int argc, char **argv) { return -1; } - // 加载模型 + // Load model PaddleX::Model det_model; det_model.Init(FLAGS_det_model_dir, FLAGS_use_gpu, FLAGS_use_trt, FLAGS_gpu_id, FLAGS_det_key);