mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-12-24 13:28:13 +08:00
Add new model PaddleSeg (#30)
* 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 Co-authored-by: Jason <jiangjiajun@baidu.com>
This commit is contained in:
@@ -19,3 +19,8 @@ from ... import fastdeploy_main as C
|
||||
|
||||
def vis_detection(im_data, det_result, line_size=1, font_size=0.5):
|
||||
C.vision.Visualize.vis_detection(im_data, det_result, line_size, font_size)
|
||||
|
||||
|
||||
def vis_segmentation(im_data, seg_result, vis_im_data, num_classes=1000):
|
||||
C.vision.Visualize.vis_segmentation(im_data, seg_result, vis_im_data,
|
||||
num_classes)
|
||||
|
||||
46
fastdeploy/vision/visualize/segmentation.cc
Normal file
46
fastdeploy/vision/visualize/segmentation.cc
Normal file
@@ -0,0 +1,46 @@
|
||||
// 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.masks.size();
|
||||
int64_t width = result.masks[1].size();
|
||||
*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 = static_cast<int>(result.masks[i][j]);
|
||||
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
|
||||
@@ -27,8 +27,11 @@ class FASTDEPLOY_DECL Visualize {
|
||||
static const std::vector<int>& GetColorMap(int num_classes = 1000);
|
||||
static void VisDetection(cv::Mat* im, const DetectionResult& result,
|
||||
int line_size = 2, float font_size = 0.5f);
|
||||
static void VisSegmentation(const cv::Mat& im,
|
||||
const SegmentationResult& result,
|
||||
cv::Mat* vis_img, const int& num_classes = 1000);
|
||||
};
|
||||
|
||||
} // namespace vision
|
||||
} // namespace fastdeploy
|
||||
} // namespace vision
|
||||
} // namespace fastdeploy
|
||||
#endif
|
||||
|
||||
@@ -18,11 +18,20 @@ namespace fastdeploy {
|
||||
void BindVisualize(pybind11::module& m) {
|
||||
pybind11::class_<vision::Visualize>(m, "Visualize")
|
||||
.def(pybind11::init<>())
|
||||
.def_static("vis_detection", [](pybind11::array& im_data,
|
||||
vision::DetectionResult& result,
|
||||
int line_size, float font_size) {
|
||||
auto im = PyArrayToCvMat(im_data);
|
||||
vision::Visualize::VisDetection(&im, result, line_size, font_size);
|
||||
.def_static("vis_detection",
|
||||
[](pybind11::array& im_data, vision::DetectionResult& result,
|
||||
int line_size, float font_size) {
|
||||
auto im = PyArrayToCvMat(im_data);
|
||||
vision::Visualize::VisDetection(&im, result, line_size,
|
||||
font_size);
|
||||
})
|
||||
.def_static("vis_segmentation", [](pybind11::array& im_data,
|
||||
vision::SegmentationResult& result,
|
||||
pybind11::array& vis_im_data,
|
||||
const int& num_classes) {
|
||||
cv::Mat im = PyArrayToCvMat(im_data);
|
||||
cv::Mat vis_im = PyArrayToCvMat(vis_im_data);
|
||||
vision::Visualize::VisSegmentation(im, result, &vis_im, num_classes);
|
||||
});
|
||||
}
|
||||
} // namespace fastdeploy
|
||||
} // namespace fastdeploy
|
||||
|
||||
Reference in New Issue
Block a user