Skip to content

Commit b9a0355

Browse files
committed
add CalcHist, CompareHist example, rewrited from #104
1 parent 5c2b225 commit b9a0355

File tree

8 files changed

+433
-231
lines changed

8 files changed

+433
-231
lines changed

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ generate_dynamic_reconfigure_options(
5252
cfg/GoodfeatureTrack.cfg
5353
cfg/CornerHarris.cfg
5454
#
55+
cfg/CompareHistogram.cfg
5556
cfg/EqualizeHistogram.cfg
5657
cfg/CamShift.cfg
5758
cfg/FBackFlow.cfg
@@ -169,7 +170,7 @@ opencv_apps_add_nodelet(discrete_fourier_transform src/nodelet/discrete_fourier_
169170
# ./tutorial_code/Histograms_Matching/calcBackProject_Demo1.cpp
170171
# ./tutorial_code/Histograms_Matching/calcBackProject_Demo2.cpp
171172
# ./tutorial_code/Histograms_Matching/calcHist_Demo.cpp
172-
# ./tutorial_code/Histograms_Matching/compareHist_Demo.cpp
173+
opencv_apps_add_nodelet(compare_histogram src/nodelet/compare_histogram_nodelet.cpp) # ./tutorial_code/Histograms_Matching/compareHist_Demo.cpp
173174
opencv_apps_add_nodelet(equalize_histogram src/nodelet/equalize_histogram_nodelet.cpp) # ./tutorial_code/Histograms_Matching/EqualizeHist_Demo.cpp
174175
# ./tutorial_code/Histograms_Matching/MatchTemplate_Demo.cpp
175176

@@ -263,7 +264,7 @@ opencv_apps_add_nodelet(camshift src/nodelet/camshift_nodelet.cpp) # ./camshiftd
263264
# ./create_mask.cpp
264265
# ./dbt_face_detection.cpp
265266
# ./delaunay2.cpp
266-
opencv_apps_add_nodelet(intensity_histogram src/nodelet/intensity_histogram.cpp) # ./demhist.cpp
267+
# ./demhist.cpp
267268
# ./detect_blob.cpp
268269
# ./detect_mser.cpp
269270
# ./dft.cpp

cfg/CompareHistogram.cfg

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#! /usr/bin/env python
2+
# Software License Agreement (BSD License)
3+
#
4+
# Copyright (c) 2022, Kei Okada
5+
# All rights reserved.
6+
#
7+
# Redistribution and use in source and binary forms, with or without
8+
# modification, are permitted provided that the following conditions
9+
# are met:
10+
#
11+
# * Redistributions of source code must retain the above copyright
12+
# notice, this list of conditions and the following disclaimer.
13+
# * Redistributions in binary form must reproduce the above
14+
# copyright notice, this list of conditions and the following
15+
# disclaimer in the documentation and/or other materials provided
16+
# with the distribution.
17+
# * Neither the name of Kei Okada nor the names of its
18+
# contributors may be used to endorse or promote products derived
19+
# from this software without specific prior written permission.
20+
#
21+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24+
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25+
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26+
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27+
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30+
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31+
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32+
# POSSIBILITY OF SUCH DAMAGE.
33+
34+
35+
PACKAGE = "opencv_apps"
36+
37+
from dynamic_reconfigure.parameter_generator_catkin import *
38+
39+
gen = ParameterGenerator()
40+
gen.add("use_camera_info", bool_t, 0, "Indicates that the camera_info topic should be subscribed to to get the default input_frame_id. Otherwise the frame from the image message will be used.", False)
41+
42+
histogram_comparison_type = gen.enum([ gen.const("Correlation", int_t, 0, "Correlation"),
43+
gen.const("Chi_Square", int_t, 1, "Chi-Square"),
44+
gen.const("Intersection", int_t, 2, "Intersection"),
45+
gen.const("Bhattacharyya", int_t, 3, "Bhattacharyya distance")],
46+
"Histogram Comparison method")
47+
gen.add("histogram_comparison_type", int_t, 1, "Histogram Comparison method", 0, 0, 3, edit_method=histogram_comparison_type)
48+
49+
gen.add("histogram_size", int_t, 2, "Array of histogram sizes in each dimension", 256, 1, 1024)
50+
gen.add("uniform", bool_t, 3, "Flag indicating whether the histogram is uniform or not", True)
51+
gen.add("accumulate", bool_t, 4, "Accumulation flag. If it is set, the histogram is not cleared in the beginning when it is allocated", False)
52+
53+
exit(gen.generate(PACKAGE, "compare_histogram", "CompareHistogram"))

launch/intensity_histogram.launch renamed to launch/compare_histogram.launch

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@
55

66
<arg name="debug_view" default="true" doc="Specify whether the node displays a window to show edge image" />
77
<arg name="queue_size" default="3" doc="Specigy queue_size of input image subscribers" />
8+
<arg name="histogram_size" default="64" doc="number of bins" />
9+
<arg name="reference_histogram" default="" doc="reference of histogram comparison" />
810

911

1012
<!-- intensity_histogram.cpp -->
11-
<node name="$(arg node_name)" pkg="opencv_apps" type="intensity_histogram" >
13+
<node name="$(arg node_name)" pkg="opencv_apps" type="compare_histogram" >
1214
<remap from="image" to="$(arg image)" />
1315
<param name="debug_view" value="$(arg debug_view)" />
1416
<param name="queue_size" value="$(arg queue_size)" />
17+
<param name="histogram_size" value="$(arg histogram_size)" />
18+
<rosparam param="reference_histogram" subst_value="true">
19+
$(arg reference_histogram)
20+
</rosparam>
1521
</node>
1622
</launch>

nodelet_plugins.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,12 @@
123123
<description>Nodelet to demonstrate the famous watershed segmentation algorithm in OpenCV: watershed()</description>
124124
</class>
125125

126-
<class name="opencv_apps/equalize_histogram" type="opencv_apps::EqualizeHistogramNodelet" base_class_type="nodelet::Nodelet">
127-
<description>Nodelet for histogram equalization</description>
126+
<class name="opencv_apps/compare_histogram" type="opencv_apps::CompareHistogramNodelet" base_class_type="nodelet::Nodelet">
127+
<description>Nodelet of compare histogram</description>
128128
</class>
129129

130-
<class name="opencv_apps/intensity_histogram" type="opencv_apps::IntensityHistogramNodelet" base_class_type="nodelet::Nodelet">
131-
<description>Nodelet of intensity histogram</description>
130+
<class name="opencv_apps/equalize_histogram" type="opencv_apps::EqualizeHistogramNodelet" base_class_type="nodelet::Nodelet">
131+
<description>Nodelet for histogram equalization</description>
132132
</class>
133133

134134
<!--

0 commit comments

Comments
 (0)