Skip to content

Commit

Permalink
fix(bytetrack): No need to throw exception when idx is out of range
Browse files Browse the repository at this point in the history
Since ColorMapper just returns a unique color to the caller,
we simply use modulo to get a valid color index.
In such a way there is no need to check the index validity and throw
a runtime exception.

Signed-off-by: chtseng <[email protected]>
  • Loading branch information
chtseng committed Jul 23, 2024
1 parent be56a2f commit 089dbb3
Showing 1 changed file with 1 addition and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

#include <algorithm>
#include <memory>
#include <stdexcept>
#include <string>
#include <vector>

Expand All @@ -54,10 +53,7 @@ class ColorMapper

cv::Scalar operator()(size_t idx)
{
if (kColorNum <= idx) {
throw std::runtime_error("idx should be between [0, 255]");
}
return color_table_.at<cv::Vec3b>(0, idx);
return color_table_.at<cv::Vec3b>(0, idx % kColorNum);
}

protected:
Expand Down

0 comments on commit 089dbb3

Please sign in to comment.