From 2c711de013de00e06f006f959c0c8bc2d1a67f7e Mon Sep 17 00:00:00 2001 From: Tino Hager Date: Sun, 15 Jul 2018 00:05:54 +0200 Subject: [PATCH] optimize performance detect check image size before resize --- src/yolo_v2_class.hpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/yolo_v2_class.hpp b/src/yolo_v2_class.hpp index 6f7e47bd..3dc93866 100644 --- a/src/yolo_v2_class.hpp +++ b/src/yolo_v2_class.hpp @@ -96,9 +96,15 @@ public: std::shared_ptr mat_to_image_resize(cv::Mat mat) const { if (mat.data == NULL) return std::shared_ptr(NULL); - cv::Mat det_mat; - cv::resize(mat, det_mat, cv::Size(get_net_width(), get_net_height())); - return mat_to_image(det_mat); + + cv::Size s = mat.size(); + if (get_net_width() != s.width || get_net_height() != s.height) { + cv::Mat det_mat; + cv::resize(mat, det_mat, cv::Size(get_net_width(), get_net_height())); + return mat_to_image(det_mat); + } + + return mat_to_image(mat); } static std::shared_ptr mat_to_image(cv::Mat img_src)