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 #include <jsk_recognition_msgs/HistogramWithRangeBin.h>
41 
42 namespace jsk_recognition_utils
43 {
51  cv::MatND computeHistogram(const cv::Mat& input_image, int bin_size,
52  float min_value, float max_value,
53  const cv::Mat& mask_image);
54 
59  std::vector<jsk_recognition_msgs::HistogramWithRangeBin>
60  cvMatNDToHistogramWithRangeBinArray(const cv::MatND& cv_hist, float min_value, float max_value);
61 
66  cv::MatND
68  const std::vector<jsk_recognition_msgs::HistogramWithRangeBin>& histogram);
69 
74  bool compareHistogramWithRangeBin(const jsk_recognition_msgs::HistogramWithRangeBin& left,
75  const jsk_recognition_msgs::HistogramWithRangeBin& right);
76 
82  void sortHistogramWithRangeBinArray(std::vector<jsk_recognition_msgs::HistogramWithRangeBin>& bins);
83 
89  std::vector<jsk_recognition_msgs::HistogramWithRangeBin>
90  topNHistogramWithRangeBins(const std::vector<jsk_recognition_msgs::HistogramWithRangeBin>& bins,
91  double top_n_rate);
92 
97  void
98  drawHistogramWithRangeBin(cv::Mat& image,
99  const jsk_recognition_msgs::HistogramWithRangeBin& bin,
100  float min_width_value,
101  float max_width_value,
102  float max_height_value,
103  cv::Scalar color);
104 
109  void labelToRGB(const cv::Mat src, cv::Mat& dst);
110 
111 
116  cv::Rect boundingRectOfMaskImage(const cv::Mat& image);
117 
122  bool isBGR(const std::string& encoding);
123  bool isRGB(const std::string& encoding);
124  bool isBGRA(const std::string& encoding);
125  bool isRGBA(const std::string& encoding);
126 
127 }
128 
129 #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 Fri Dec 6 2019 04:02:51