From b9a03552cf30464cedb456df54a2398bfb2926b3 Mon Sep 17 00:00:00 2001 From: Kei Okada Date: Mon, 14 Feb 2022 16:07:31 +0900 Subject: [PATCH] add CalcHist, CompareHist example, rewrited from #104 --- CMakeLists.txt | 5 +- cfg/CompareHistogram.cfg | 53 ++++ ...togram.launch => compare_histogram.launch} | 8 +- nodelet_plugins.xml | 8 +- src/nodelet/compare_histogram_nodelet.cpp | 299 ++++++++++++++++++ src/nodelet/intensity_histogram.cpp | 224 ------------- test/CMakeLists.txt | 1 + test/test-compare_histogram.test | 66 ++++ 8 files changed, 433 insertions(+), 231 deletions(-) create mode 100644 cfg/CompareHistogram.cfg rename launch/{intensity_histogram.launch => compare_histogram.launch} (59%) create mode 100644 src/nodelet/compare_histogram_nodelet.cpp delete mode 100644 src/nodelet/intensity_histogram.cpp create mode 100644 test/test-compare_histogram.test diff --git a/CMakeLists.txt b/CMakeLists.txt index 4bdd4a53..ce3e3e2d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,6 +52,7 @@ generate_dynamic_reconfigure_options( cfg/GoodfeatureTrack.cfg cfg/CornerHarris.cfg # + cfg/CompareHistogram.cfg cfg/EqualizeHistogram.cfg cfg/CamShift.cfg cfg/FBackFlow.cfg @@ -169,7 +170,7 @@ opencv_apps_add_nodelet(discrete_fourier_transform src/nodelet/discrete_fourier_ # ./tutorial_code/Histograms_Matching/calcBackProject_Demo1.cpp # ./tutorial_code/Histograms_Matching/calcBackProject_Demo2.cpp # ./tutorial_code/Histograms_Matching/calcHist_Demo.cpp - # ./tutorial_code/Histograms_Matching/compareHist_Demo.cpp + opencv_apps_add_nodelet(compare_histogram src/nodelet/compare_histogram_nodelet.cpp) # ./tutorial_code/Histograms_Matching/compareHist_Demo.cpp opencv_apps_add_nodelet(equalize_histogram src/nodelet/equalize_histogram_nodelet.cpp) # ./tutorial_code/Histograms_Matching/EqualizeHist_Demo.cpp # ./tutorial_code/Histograms_Matching/MatchTemplate_Demo.cpp @@ -263,7 +264,7 @@ opencv_apps_add_nodelet(camshift src/nodelet/camshift_nodelet.cpp) # ./camshiftd # ./create_mask.cpp # ./dbt_face_detection.cpp # ./delaunay2.cpp -opencv_apps_add_nodelet(intensity_histogram src/nodelet/intensity_histogram.cpp) # ./demhist.cpp +# ./demhist.cpp # ./detect_blob.cpp # ./detect_mser.cpp # ./dft.cpp diff --git a/cfg/CompareHistogram.cfg b/cfg/CompareHistogram.cfg new file mode 100644 index 00000000..769ffc72 --- /dev/null +++ b/cfg/CompareHistogram.cfg @@ -0,0 +1,53 @@ +#! /usr/bin/env python +# Software License Agreement (BSD License) +# +# Copyright (c) 2022, Kei Okada +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Kei Okada nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + + +PACKAGE = "opencv_apps" + +from dynamic_reconfigure.parameter_generator_catkin import * + +gen = ParameterGenerator() +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) + +histogram_comparison_type = gen.enum([ gen.const("Correlation", int_t, 0, "Correlation"), + gen.const("Chi_Square", int_t, 1, "Chi-Square"), + gen.const("Intersection", int_t, 2, "Intersection"), + gen.const("Bhattacharyya", int_t, 3, "Bhattacharyya distance")], + "Histogram Comparison method") +gen.add("histogram_comparison_type", int_t, 1, "Histogram Comparison method", 0, 0, 3, edit_method=histogram_comparison_type) + +gen.add("histogram_size", int_t, 2, "Array of histogram sizes in each dimension", 256, 1, 1024) +gen.add("uniform", bool_t, 3, "Flag indicating whether the histogram is uniform or not", True) +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) + +exit(gen.generate(PACKAGE, "compare_histogram", "CompareHistogram")) diff --git a/launch/intensity_histogram.launch b/launch/compare_histogram.launch similarity index 59% rename from launch/intensity_histogram.launch rename to launch/compare_histogram.launch index 9eb8185c..3b729369 100644 --- a/launch/intensity_histogram.launch +++ b/launch/compare_histogram.launch @@ -5,12 +5,18 @@ + + - + + + + $(arg reference_histogram) + diff --git a/nodelet_plugins.xml b/nodelet_plugins.xml index 9620bb73..430ac892 100644 --- a/nodelet_plugins.xml +++ b/nodelet_plugins.xml @@ -123,12 +123,12 @@ Nodelet to demonstrate the famous watershed segmentation algorithm in OpenCV: watershed() - - Nodelet for histogram equalization + + Nodelet of compare histogram - - Nodelet of intensity histogram + + Nodelet for histogram equalization + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +