compare_histogram
Computes the color histogram of the image (cv::calcHist()) and compares it with a reference histogram (cv::compareHist()), e.g. to find the scene or the object of the reference.
opencv_apps |
3.0.0 and later |
|---|---|
ROS |
ROS One, jazzy, kilted, lyrical and later |
OpenCV |
any version of the distributions |
Group |
Histogram comparison, the nodes of which publish |
Usage
# ROS 2
ros2 launch opencv_apps compare_histogram.launch.xml image:=/camera/image_raw debug_view:=false
# ROS 1
roslaunch opencv_apps compare_histogram.launch image:=/camera/image_raw debug_view:=false
Try it with the demo video
Download the input video of the demo above, publish it as image with image_publisher, and run the node on it, in the terminals:
wget https://ros-perception.github.io/opencv_apps/media/clips/street.mp4
# terminal 1: publish the video as image in a loop
ros2 run image_publisher image_publisher_node street.mp4 --ros-args -p publish_rate:=10.0 -r image_raw:=image
# terminal 2: run the node with the parameters of the demo
H=$(python3 -c "import cv2; img = cv2.VideoCapture('street.mp4').read()[1]; print([round(float(v), 6) for c in range(3) for v in cv2.normalize(cv2.calcHist([img], [c], None, [32], [0, 256]), None, 0, 1, cv2.NORM_MINMAX).flatten()])") # the reference histogram of the first frame
ros2 launch opencv_apps compare_histogram.launch.xml image:=image histogram_comparison_type:=3 histogram_size:=32 node_name:=compare_histogram_color reference_histogram:="$H"
# terminal 3: view the result
ros2 run rqt_image_view rqt_image_view /compare_histogram_color/image
The reference histogram is that of the first frame of the clip, as test/ros2/test_compare_histogram.py.
See Credits of the demo videos for the license of the video.
Subscribed topics
Topic |
Type |
|---|---|
|
|
Published topics
Topic |
Type |
|---|---|
|
|
|
|
|
|
|
|
Parameters
See also the common parameters.
Name |
Type |
Default (range) |
Changed at run time |
Description |
|---|---|---|---|---|
|
bool |
false |
yes |
Accumulation flag. If it is set, the histogram is not cleared between images |
|
int |
0 (0 - 3) |
yes |
Histogram Comparison method, 0: Correlation, 1: Chi_Square, 2: Intersection, 3: Bhattacharyya |
|
int |
256 (1 - 1024) |
yes |
Number of bins of the histogram of each channel |
|
int |
3 |
no, restart the node |
Specify queue_size of input image subscribers |
|
double[] |
[] |
yes |
Reference of the histogram comparison, channels x histogram_size values in the layout of ~/histogram |
Source
src/nodelet/compare_histogram_nodelet.cpp, launch/compare_histogram.launch.xml