From 96d2f81f55450285f407201fdbf5c4e39e570e0f Mon Sep 17 00:00:00 2001 From: Guillaume Infantes Date: Thu, 16 Jan 2020 10:44:21 +0100 Subject: [PATCH] correctly set ymin and ymax inverted ymin and ymax in detection output : adapt chains add fix to trt and ncnn --- src/backends/caffe/caffelib.cc | 4 ++-- src/backends/ncnn/ncnnlib.cc | 4 ++-- src/backends/tensorrt/tensorrtlib.cc | 4 ++-- src/chain_actions.cc | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/backends/caffe/caffelib.cc b/src/backends/caffe/caffelib.cc index a55eb8a1c..da27a024a 100644 --- a/src/backends/caffe/caffelib.cc +++ b/src/backends/caffe/caffelib.cc @@ -2557,9 +2557,9 @@ namespace dd cats.push_back(this->_mlmodel.get_hcorresp(detection[1])); APIData ad_bbox; ad_bbox.add("xmin",static_cast(detection[3]*(cols-1))); - ad_bbox.add("ymax",static_cast(detection[4]*(rows-1))); + ad_bbox.add("ymin",static_cast(detection[4]*(rows-1))); ad_bbox.add("xmax",static_cast(detection[5]*(cols-1))); - ad_bbox.add("ymin",static_cast(detection[6]*(rows-1))); + ad_bbox.add("ymax",static_cast(detection[6]*(rows-1))); bboxes.push_back(ad_bbox); } if (leave) diff --git a/src/backends/ncnn/ncnnlib.cc b/src/backends/ncnn/ncnnlib.cc index b53c72333..c4bb6bf13 100644 --- a/src/backends/ncnn/ncnnlib.cc +++ b/src/backends/ncnn/ncnnlib.cc @@ -244,9 +244,9 @@ namespace dd APIData ad_bbox; ad_bbox.add("xmin",static_cast(values[2] * inputc.width())); - ad_bbox.add("ymax",static_cast(values[3] * inputc.height())); + ad_bbox.add("ymin",static_cast(values[3] * inputc.height())); ad_bbox.add("xmax",static_cast(values[4] * inputc.width())); - ad_bbox.add("ymin",static_cast(values[5] * inputc.height())); + ad_bbox.add("ymax",static_cast(values[5] * inputc.height())); bboxes.push_back(ad_bbox); } } diff --git a/src/backends/tensorrt/tensorrtlib.cc b/src/backends/tensorrt/tensorrtlib.cc index 569b9e0dd..65146aa29 100644 --- a/src/backends/tensorrt/tensorrtlib.cc +++ b/src/backends/tensorrt/tensorrtlib.cc @@ -564,9 +564,9 @@ namespace dd cats.push_back(this->_mlmodel.get_hcorresp(detection[1])); APIData ad_bbox; ad_bbox.add("xmin",static_cast(detection[3]*(cols-1))); - ad_bbox.add("ymax",static_cast(detection[4]*(rows-1))); + ad_bbox.add("ymin",static_cast(detection[4]*(rows-1))); ad_bbox.add("xmax",static_cast(detection[5]*(cols-1))); - ad_bbox.add("ymin",static_cast(detection[6]*(rows-1))); + ad_bbox.add("ymax",static_cast(detection[6]*(rows-1))); bboxes.push_back(ad_bbox); } if (leave) diff --git a/src/chain_actions.cc b/src/chain_actions.cc index 2a629d947..575790d81 100644 --- a/src/chain_actions.cc +++ b/src/chain_actions.cc @@ -82,16 +82,16 @@ namespace dd double cxmin = std::max(0.0,xmin-deltax); double cxmax = std::min(static_cast(img.cols),xmax+deltax); - double cymax = std::max(0.0,ymax-deltay); - double cymin = std::min(static_cast(img.rows),ymin+deltay); + double cymin = std::max(0.0,ymin-deltay); + double cymax = std::min(static_cast(img.rows),ymax+deltay); - if (cxmin > img.cols || cymax > img.rows || cxmax < 0 || cymin < 0) + if (cxmin > img.cols || cymin > img.rows || cxmax < 0 || cymax < 0) { _chain_logger->warn("bounding box does not intersect image, skipping crop action"); continue; } - cv::Rect roi(cxmin,cymax,cxmax-cxmin,cymin-cymax); + cv::Rect roi(cxmin,cymax,cxmax-cxmin,cymax-cymin); cv::Mat cropped_img = img(roi); // adding bbox id