Skip to content

Commit

Permalink
Solving the issue of out of bounds caused by detection boxes less tha…
Browse files Browse the repository at this point in the history
…n 0 when filling colors in segmentation masks
  • Loading branch information
lindsayshuo committed May 9, 2024
1 parent 46dd2c4 commit 4feb62e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions yolov8/src/postprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ cv::Rect get_rect(cv::Mat& img, float bbox[4]) {
t = t / r_h;
b = b / r_h;
}
return cv::Rect(round(l), round(t), round(r - l), round(b - t));
l = std::max(0.0f, l);
t = std::max(0.0f, t);
int width = std::max(0, std::min(int(round(r - l)), img.cols - int(round(l))));
int height = std::max(0, std::min(int(round(b - t)), img.rows - int(round(t))));

return cv::Rect(int(round(l)), int(round(t)), width, height);
}

cv::Rect get_rect_adapt_landmark(cv::Mat& img, float bbox[4], float lmk[kNumberOfPoints * 3]) {
Expand Down Expand Up @@ -53,7 +58,12 @@ cv::Rect get_rect_adapt_landmark(cv::Mat& img, float bbox[4], float lmk[kNumberO
// lmk[i + 2]
}
}
return cv::Rect(l, t, r - l, b - t);
l = std::max(0.0f, l);
t = std::max(0.0f, t);
int width = std::max(0, std::min(int(round(r - l)), img.cols - int(round(l))));
int height = std::max(0, std::min(int(round(b - t)), img.rows - int(round(t))));

return cv::Rect(int(round(l)), int(round(t)), width, height);
}

static float iou(float lbox[4], float rbox[4]) {
Expand Down

0 comments on commit 4feb62e

Please sign in to comment.