visualize.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. #include <iostream>
  16. #include <map>
  17. #include <vector>
  18. #ifdef _WIN32
  19. #include <direct.h>
  20. #include <io.h>
  21. #else // Linux/Unix
  22. #include <dirent.h>
  23. #include <sys/io.h>
  24. #include <sys/stat.h>
  25. #include <sys/types.h>
  26. #include <unistd.h>
  27. #endif
  28. #include <string>
  29. #include <opencv2/core/core.hpp>
  30. #include <opencv2/highgui/highgui.hpp>
  31. #include <opencv2/imgproc/imgproc.hpp>
  32. #include "include/paddlex/results.h"
  33. #ifdef _WIN32
  34. #define OS_PATH_SEP "\\"
  35. #else
  36. #define OS_PATH_SEP "/"
  37. #endif
  38. namespace PaddleX {
  39. /*
  40. * @brief
  41. * Generate visualization colormap for each class
  42. *
  43. * @param number of class
  44. * @return color map, the size of vector is 3 * num_class
  45. * */
  46. std::vector<int> GenerateColorMap(int num_class);
  47. /*
  48. * @brief
  49. * Visualize the detection result
  50. *
  51. * @param img: initial image matrix
  52. * @param results: the detection result
  53. * @param labels: label map
  54. * @param colormap: visualization color map
  55. * @return visualized image matrix
  56. * */
  57. cv::Mat Visualize(const cv::Mat& img,
  58. const DetResult& results,
  59. const std::map<int, std::string>& labels,
  60. const std::vector<int>& colormap,
  61. float threshold = 0.5);
  62. /*
  63. * @brief
  64. * Visualize the segmentation result
  65. *
  66. * @param img: initial image matrix
  67. * @param results: the detection result
  68. * @param labels: label map
  69. * @param colormap: visualization color map
  70. * @return visualized image matrix
  71. * */
  72. cv::Mat Visualize(const cv::Mat& img,
  73. const SegResult& result,
  74. const std::map<int, std::string>& labels,
  75. const std::vector<int>& colormap);
  76. /*
  77. * @brief
  78. * generate save path for visualized image matrix
  79. *
  80. * @param save_dir: directory for saving visualized image matrix
  81. * @param file_path: sourcen image file path
  82. * @return path of saving visualized result
  83. * */
  84. std::string generate_save_path(const std::string& save_dir,
  85. const std::string& file_path);
  86. } // namespace PaddleX