cv_utils.h
Go to the documentation of this file.
1 // -*- mode: c++ -*-
2 /*********************************************************************
3  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2015, JSK Lab
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/o2r other materials provided
17  * with the distribution.
18  * * Neither the name of the JSK Lab nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *********************************************************************/
35 
36 #ifndef JSK_RECOGNITION_UTILS_CV_UTILS_H_
37 #define JSK_RECOGNITION_UTILS_CV_UTILS_H_
38 
39 #include <opencv2/opencv.hpp>
40 #if ( CV_MAJOR_VERSION >= 4)
41 #include <opencv2/imgproc/imgproc_c.h>
42 #endif
43 #include <jsk_recognition_msgs/HistogramWithRangeBin.h>
44 
45 namespace jsk_recognition_utils
46 {
54  cv::MatND computeHistogram(const cv::Mat& input_image, int bin_size,
55  float min_value, float max_value,
56  const cv::Mat& mask_image);
57 
62  std::vector<jsk_recognition_msgs::HistogramWithRangeBin>
63  cvMatNDToHistogramWithRangeBinArray(const cv::MatND& cv_hist, float min_value, float max_value);
64 
69  cv::MatND
71  const std::vector<jsk_recognition_msgs::HistogramWithRangeBin>& histogram);
72 
77  bool compareHistogramWithRangeBin(const jsk_recognition_msgs::HistogramWithRangeBin& left,
78  const jsk_recognition_msgs::HistogramWithRangeBin& right);
79 
85  void sortHistogramWithRangeBinArray(std::vector<jsk_recognition_msgs::HistogramWithRangeBin>& bins);
86 
92  std::vector<jsk_recognition_msgs::HistogramWithRangeBin>
93  topNHistogramWithRangeBins(const std::vector<jsk_recognition_msgs::HistogramWithRangeBin>& bins,
94  double top_n_rate);
95 
100  void
101  drawHistogramWithRangeBin(cv::Mat& image,
102  const jsk_recognition_msgs::HistogramWithRangeBin& bin,
103  float min_width_value,
104  float max_width_value,
105  float max_height_value,
106  cv::Scalar color);
107 
112  void labelToRGB(const cv::Mat src, cv::Mat& dst);
113 
114 
119  cv::Rect boundingRectOfMaskImage(const cv::Mat& image);
120 
125  bool isBGR(const std::string& encoding);
126  bool isRGB(const std::string& encoding);
127  bool isBGRA(const std::string& encoding);
128  bool isRGBA(const std::string& encoding);
129 
130 }
131 
132 #endif
bool isRGBA(const std::string &encoding)
Definition: cv_utils.cpp:199
bool isBGRA(const std::string &encoding)
Definition: cv_utils.cpp:194
cv::MatND computeHistogram(const cv::Mat &input_image, int bin_size, float min_value, float max_value, const cv::Mat &mask_image)
simple wrapper for cv::calcHist.
Definition: cv_utils.cpp:44
cv::MatND HistogramWithRangeBinArrayTocvMatND(const std::vector< jsk_recognition_msgs::HistogramWithRangeBin > &histogram)
convert jsk_recognition_msgs::HistogramimageWithRangeBin array to cv::MatND
Definition: cv_utils.cpp:77
std::vector< jsk_recognition_msgs::HistogramWithRangeBin > cvMatNDToHistogramWithRangeBinArray(const cv::MatND &cv_hist, float min_value, float max_value)
convert cv::MatND to jsk_recognition_msgs::HistogramimageWithRangeBin array
Definition: cv_utils.cpp:60
std::vector< jsk_recognition_msgs::HistogramWithRangeBin > topNHistogramWithRangeBins(const std::vector< jsk_recognition_msgs::HistogramWithRangeBin > &bins, double top_n_rate)
extract top-N histograms. bins should be sorted. top_n_rate should be 0-1.
Definition: cv_utils.cpp:100
void labelToRGB(const cv::Mat src, cv::Mat &dst)
convert label image to rgb one.
Definition: cv_utils.cpp:147
void sortHistogramWithRangeBinArray(std::vector< jsk_recognition_msgs::HistogramWithRangeBin > &bins)
sort std::vector<jsk_recognition_msgs::HistogramWithRangeBin>. largest value will be at the first ele...
Definition: cv_utils.cpp:94
bool isRGB(const std::string &encoding)
Definition: cv_utils.cpp:189
cv::Rect boundingRectOfMaskImage(const cv::Mat &image)
compute bounding rectangle of mask image.
Definition: cv_utils.cpp:164
void drawHistogramWithRangeBin(cv::Mat &image, const jsk_recognition_msgs::HistogramWithRangeBin &bin, float min_width_value, float max_width_value, float max_height_value, cv::Scalar color)
draw bin to cv::Mat
Definition: cv_utils.cpp:124
bool isBGR(const std::string &encoding)
Check encodings.
Definition: cv_utils.cpp:184
bool compareHistogramWithRangeBin(const jsk_recognition_msgs::HistogramWithRangeBin &left, const jsk_recognition_msgs::HistogramWithRangeBin &right)
return true if left.count is larger than right.count.
Definition: cv_utils.cpp:88


jsk_recognition_utils
Author(s):
autogenerated on Mon May 3 2021 03:03:03