Files
FastDeploy/csrcs/fastdeploy/vision/visualize/segmentation.cc
huangjianhui 0e0dfd9565 [Left TODO] Support PaddleSeg deployment (#39)
* Support new model PaddleSeg

* Fix conflict

* PaddleSeg add visulization function

* fix bug

* Fix BindPPSeg wrong name

* Fix variable name

* Update by comments

* Add ppseg-unet example python version

* Change the way to decompress  model file

* Visualize resize mask back to original image size

* Update paddleseg support

* Add essential files to support ppseg

* Support logits matrix resize

* Support mask matrix resize

* Fix some bugs

* Format code

* Add code comment

* Format code

Co-authored-by: Jason <jiangjiajun@baidu.com>
2022-08-05 09:11:01 +08:00

47 lines
1.6 KiB
C++

// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifdef ENABLE_VISION_VISUALIZE
#include "fastdeploy/vision/visualize/visualize.h"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
namespace fastdeploy {
namespace vision {
void Visualize::VisSegmentation(const cv::Mat& im,
const SegmentationResult& result,
cv::Mat* vis_img, const int& num_classes) {
auto color_map = GetColorMap(num_classes);
int64_t height = result.shape[0];
int64_t width = result.shape[1];
*vis_img = cv::Mat::zeros(height, width, CV_8UC3);
int64_t index = 0;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
int category_id = result.label_map[index++];
vis_img->at<cv::Vec3b>(i, j)[0] = color_map[3 * category_id + 0];
vis_img->at<cv::Vec3b>(i, j)[1] = color_map[3 * category_id + 1];
vis_img->at<cv::Vec3b>(i, j)[2] = color_map[3 * category_id + 2];
}
}
cv::addWeighted(im, .5, *vis_img, .5, 0, *vis_img);
}
} // namespace vision
} // namespace fastdeploy
#endif