visualize.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. #ifdef __arm__ // for arm
  25. #include <aarch64-linux-gpu/sys/stat.h>
  26. #include <aarch64-linux-gpu/sys/types.h>
  27. #else
  28. #include <sys/stat.h>
  29. #include <sys/types.h>
  30. #endif
  31. #include <unistd.h>
  32. #endif
  33. #include <string>
  34. #include <opencv2/core/core.hpp>
  35. #include <opencv2/highgui/highgui.hpp>
  36. #include <opencv2/imgproc/imgproc.hpp>
  37. #include "include/paddlex/results.h"
  38. #ifdef _WIN32
  39. #define OS_PATH_SEP "\\"
  40. #else
  41. #define OS_PATH_SEP "/"
  42. #endif
  43. namespace PaddleX {
  44. /*
  45. * @brief
  46. * Generate visualization colormap for each class
  47. *
  48. * @param number of class
  49. * @return color map, the size of vector is 3 * num_class
  50. * */
  51. std::vector<int> GenerateColorMap(int num_class);
  52. /*
  53. * @brief
  54. * Visualize the detection result
  55. *
  56. * @param img: initial image matrix
  57. * @param results: the detection result
  58. * @param labels: label map
  59. * @param colormap: visualization color map
  60. * @return visualized image matrix
  61. * */
  62. cv::Mat Visualize(const cv::Mat& img,
  63. const DetResult& results,
  64. const std::map<int, std::string>& labels,
  65. const std::vector<int>& colormap,
  66. float threshold = 0.5);
  67. /*
  68. * @brief
  69. * Visualize the segmentation result
  70. *
  71. * @param img: initial image matrix
  72. * @param results: the detection result
  73. * @param labels: label map
  74. * @param colormap: visualization color map
  75. * @return visualized image matrix
  76. * */
  77. cv::Mat Visualize(const cv::Mat& img,
  78. const SegResult& result,
  79. const std::map<int, std::string>& labels,
  80. const std::vector<int>& colormap);
  81. /*
  82. * @brief
  83. * generate save path for visualized image matrix
  84. *
  85. * @param save_dir: directory for saving visualized image matrix
  86. * @param file_path: sourcen image file path
  87. * @return path of saving visualized result
  88. * */
  89. std::string generate_save_path(const std::string& save_dir,
  90. const std::string& file_path);
  91. } // namespace PaddleX