Skip to content

Commit 660ef87

Browse files
committed
create color legend
1 parent 03f7625 commit 660ef87

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ wget https://github.com/Megvii-BaseDetection/YOLOX/releases/download/0.1.1rc0/yo
149149
```
150150

151151
- Test results:
152+
153+
+ cityscapes dataset's color legend
154+
155+
![city scapes color legend](./data/images/cityscapes_legend.jpg)
156+
152157
+ test result on sample image of cityscapes dataset (this model is trained on cityscapes dataset)
153158
![paddleseg city scapes](./data/images/sample_city_scapes_result.jpg)
154159

data/images/cityscapes_legend.jpg

36.6 KB
Loading

examples/SemanticSegmentationPaddleSegBisenetv2App.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ int main(int argc, char* argv[])
4646
Ort::SemanticSegmentationPaddleSegBisenetv2::IMG_W);
4747

4848
auto result = processOneFrame(osh, img, dst.data());
49-
cv::imwrite("result.jpg", result);
49+
cv::Mat legend = drawColorChart(Ort::CITY_SCAPES_CLASSES, COLORS);
50+
cv::imshow("legend", legend);
51+
cv::imshow("overlaid result", result);
52+
cv::waitKey(0);
5053

5154
return EXIT_SUCCESS;
5255
}

examples/Utility.hpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ inline std::vector<cv::Scalar> toCvScalarColors(const std::vector<std::array<int
3030
}
3131

3232
inline cv::Mat visualizeOneImage(const cv::Mat& img, const std::vector<std::array<float, 4>>& bboxes,
33-
const std::vector<uint64_t>& classIndices, const std::vector<cv::Scalar> allColors,
33+
const std::vector<uint64_t>& classIndices, const std::vector<cv::Scalar>& allColors,
3434
const std::vector<std::string>& allClassNames = {})
3535
{
3636
assert(bboxes.size() == classIndices.size());
@@ -63,7 +63,7 @@ inline cv::Mat visualizeOneImage(const cv::Mat& img, const std::vector<std::arra
6363

6464
inline cv::Mat visualizeOneImageWithMask(const cv::Mat& img, const std::vector<std::array<float, 4>>& bboxes,
6565
const std::vector<uint64_t>& classIndices, const std::vector<cv::Mat>& masks,
66-
const std::vector<cv::Scalar> allColors,
66+
const std::vector<cv::Scalar>& allColors,
6767
const std::vector<std::string>& allClassNames = {},
6868
const float maskThreshold = 0.5)
6969
{
@@ -116,4 +116,16 @@ inline cv::Mat visualizeOneImageWithMask(const cv::Mat& img, const std::vector<s
116116

117117
return result;
118118
}
119+
120+
cv::Mat drawColorChart(const std::vector<std::string>& classes, const std::vector<cv::Scalar>& colors)
121+
{
122+
cv::Mat legend = cv::Mat::zeros((classes.size() * 25) + 25, 300, CV_8UC(3));
123+
for (std::size_t i = 0; i < classes.size(); ++i) {
124+
cv::putText(legend, classes[i], cv::Point(5, (i * 25) + 17), cv::FONT_HERSHEY_SIMPLEX, 0.5,
125+
cv::Scalar(0, 0, 255), 2);
126+
cv::rectangle(legend, cv::Point(100, (i * 25)), cv::Point(300, (i * 25) + 25), colors[i], -1);
127+
}
128+
129+
return legend;
130+
}
119131
} // namespace

0 commit comments

Comments
 (0)