Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blob detection nodelet #130

Open
wants to merge 19 commits into
base: indigo
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ generate_dynamic_reconfigure_options(
cfg/HSVColorFilter.cfg
cfg/LabColorFilter.cfg
cfg/WatershedSegmentation.cfg
cfg/BlobDetection.cfg
)

## Generate messages in the 'msg' folder
Expand Down Expand Up @@ -102,6 +103,9 @@ add_message_files(
Contour.msg
ContourArray.msg
ContourArrayStamped.msg
Blob.msg
BlobArray.msg
BlobArrayStamped.msg
)

add_service_files(
Expand Down Expand Up @@ -327,6 +331,10 @@ opencv_apps_add_nodelet(segment_objects src/nodelet/segment_objects_nodelet.cpp)
# ./videostab.cpp
opencv_apps_add_nodelet(watershed_segmentation src/nodelet/watershed_segmentation_nodelet.cpp) # ./watershed.cpp

if(OpenCV_VERSION VERSION_GREATER "3.0")
opencv_apps_add_nodelet(blob_detection src/nodelet/blob_detection_nodelet.cpp) # ./blob_detection.cpp
endif()

# ros examples
opencv_apps_add_nodelet(simple_example src/nodelet/simple_example_nodelet.cpp)
opencv_apps_add_nodelet(simple_compressed_example src/nodelet/simple_compressed_example_nodelet.cpp)
Expand Down Expand Up @@ -387,9 +395,12 @@ if(CATKIN_ENABLE_TESTING)
message(WARNING "roslaunch_add_file check fails with unsupported doc attributes ${roslaunch_VERSION}")
else()
file(GLOB LAUNCH_FILES launch/*.launch)
if(NOT OpenCV_VERSION VERSION_GREATER "3.0")
list(REMOVE_ITEM LAUNCH_FILES ${CMAKE_CURRENT_SOURCE_DIR}/launch/blob_detection.launch)
endif()
foreach(LAUNCH_FILE ${LAUNCH_FILES})
roslaunch_add_file_check(${LAUNCH_FILE})
endforeach()
endif()
add_subdirectory(test)
endif()
endif()
72 changes: 72 additions & 0 deletions cfg/BlobDetection.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#! /usr/bin/env python
# Software License Agreement (BSD License)
#
# Copyright (c) 2022, Hui Shi, University of Tartu.
# 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 Hui Shi, University of Tartu 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)

gen.add("hue_lower_limit", int_t, 0, "The minimum allowed field value Hue", 0, 0, 179)
gen.add("hue_upper_limit", int_t, 0, "The maximum allowed field value Hue", 179, 0, 179)
gen.add("sat_lower_limit", int_t, 0, "The minimum allowed field value Saturation", 0, 0, 255)
gen.add("sat_upper_limit", int_t, 0, "The maximum allowed field value Saturation", 255, 0, 255)
gen.add("val_lower_limit", int_t, 0, "The minimum allowed field value Value", 0, 0, 255)
gen.add("val_upper_limit", int_t, 0, "The maximum allowed field value Value", 255, 0, 255)

morphology_ex_type = gen.enum([ gen.const("off", str_t, "off", "no morphological operation"),
gen.const("opening", str_t, "opening", "morphological operation type opening (erosion followed by dilation)"),
gen.const("closing", str_t, "closing", "morphological operation type closing (dilation followed by erosion)")],
"An enum for morphological operation type")
gen.add("morphology_ex_type", str_t, 0, "morphological operation type", "off", edit_method=morphology_ex_type)
gen.add("morphology_ex_kernel_size", int_t, 0, "morphological operation kernel size (should be odd number)", 3, 0, 100)

gen.add("filter_by_color", bool_t, 0, "filter by color, use True/False to turn on/off the filtration", True)
gen.add("blob_color", int_t, 0, "Use blob_color = 0 to extract dark blobs and blob_color = 255 to extract light blobs.", 255, 0, 255)
gen.add("filter_by_area", bool_t, 0, "filter by area, use True/False to turn on/off the filtration", True)
gen.add("min_area", double_t, 0, "Extracted blobs have an area between minArea (inclusive) and maxArea (exclusive).", 0, 0, 40000)
gen.add("max_area", double_t, 0, "Extracted blobs have an area between minArea (inclusive) and maxArea (exclusive).", 40000, 0, 40000)
gen.add("min_dist_between_blobs", double_t, 0, "The blobs located closer than minDistBetweenBlobs are merged.", 0, 0, 200)
gen.add("filter_by_circularity", bool_t, 0, "filter by circularity, use True/False to turn on/off the filtration", False)
gen.add("min_circularity", double_t, 0, "Extracted blobs have circularity between minCircularity (inclusive) and maxCircularity (exclusive).", 0, 0, 1)
gen.add("max_circularity", double_t, 0, "Extracted blobs have circularity between minCircularity (inclusive) and maxCircularity (exclusive).", 1, 0, 1)
gen.add("filter_by_inertia", bool_t, 0, "filter by inertia, use True/False to turn on/off the filtration", False)
gen.add("min_inertia_ratio", double_t, 0, "Extracted blobs have this ratio between minInertiaRatio (inclusive) and maxInertiaRatio (exclusive).", 0, 0, 1)
gen.add("max_inertia_ratio", double_t, 0, "Extracted blobs have this ratio between minInertiaRatio (inclusive) and maxInertiaRatio (exclusive).", 1, 0, 1)
gen.add("filter_by_convexity", bool_t, 0, "filter by convexity, use True/False to turn on/off the filtration", False)
gen.add("min_convexity", double_t, 0, "Extracted blobs have convexity between minConvexity (inclusive) and maxConvexity (exclusive).", 0, 0, 1)
gen.add("max_convexity", double_t, 0, "Extracted blobs have convexity between minConvexity (inclusive) and maxConvexity (exclusive).", 1, 0, 1)

exit(gen.generate(PACKAGE, "blob_detection", "BlobDetection"))
180 changes: 180 additions & 0 deletions config/blob_detection.rviz
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
Panels:
- Class: rviz/Displays
Help Height: 172
Name: Displays
Property Tree Widget:
Expanded:
- /Global Options1
- /Status1
- /Blob Detection Demo1
- /Thresholded Image1
- /Thresholded Image With Mask1
- /MorphologyEx Image1
Splitter Ratio: 0.5
Tree Height: 848
- Class: rviz/Selection
Name: Selection
- Class: rviz/Tool Properties
Expanded:
- /2D Pose Estimate1
- /2D Nav Goal1
- /Publish Point1
Name: Tool Properties
Splitter Ratio: 0.5886790156364441
- Class: rviz/Views
Expanded:
- /Current View1
Name: Views
Splitter Ratio: 0.5
- Class: rviz/Time
Experimental: false
Name: Time
SyncMode: 0
SyncSource: Blob Detection Demo
Preferences:
PromptSaveOnExit: true
Toolbars:
toolButtonStyle: 2
Visualization Manager:
Class: ""
Displays:
- Alpha: 0.5
Cell Size: 1
Class: rviz/Grid
Color: 160; 160; 164
Enabled: true
Line Style:
Line Width: 0.029999999329447746
Value: Lines
Name: Grid
Normal Cell Count: 0
Offset:
X: 0
Y: 0
Z: 0
Plane: XY
Plane Cell Count: 10
Reference Frame: <Fixed Frame>
Value: true
- Class: rviz/Image
Enabled: true
Image Topic: /blob_detection/image
Max Value: 1
Median window: 5
Min Value: 0
Name: Blob Detection Demo
Normalize Range: true
Queue Size: 2
Transport Hint: raw
Unreliable: false
Value: true
- Class: rviz/Image
Enabled: true
Image Topic: /blob_detection/thresholded_image
Max Value: 1
Median window: 5
Min Value: 0
Name: Thresholded Image
Normalize Range: true
Queue Size: 2
Transport Hint: raw
Unreliable: false
Value: true
- Class: rviz/Image
Enabled: true
Image Topic: /blob_detection/thresholded_image_with_mask
Max Value: 1
Median window: 5
Min Value: 0
Name: Thresholded Image With Mask
Normalize Range: true
Queue Size: 2
Transport Hint: raw
Unreliable: false
Value: true
- Class: rviz/Image
Enabled: true
Image Topic: /blob_detection/morphology_ex_image
Max Value: 1
Median window: 5
Min Value: 0
Name: MorphologyEx Image
Normalize Range: true
Queue Size: 2
Transport Hint: raw
Unreliable: false
Value: true
Enabled: true
Global Options:
Background Color: 48; 48; 48
Default Light: true
Fixed Frame: map
Frame Rate: 30
Name: root
Tools:
- Class: rviz/Interact
Hide Inactive Objects: true
- Class: rviz/MoveCamera
- Class: rviz/Select
- Class: rviz/FocusCamera
- Class: rviz/Measure
- Class: rviz/SetInitialPose
Theta std deviation: 0.2617993950843811
Topic: /initialpose
X std deviation: 0.5
Y std deviation: 0.5
- Class: rviz/SetGoal
Topic: /move_base_simple/goal
- Class: rviz/PublishPoint
Single click: true
Topic: /clicked_point
Value: true
Views:
Current:
Class: rviz/Orbit
Distance: 10
Enable Stereo Rendering:
Stereo Eye Separation: 0.05999999865889549
Stereo Focal Distance: 1
Swap Stereo Eyes: false
Value: false
Focal Point:
X: 0
Y: 0
Z: 0
Focal Shape Fixed Size: true
Focal Shape Size: 0.05000000074505806
Invert Z Axis: false
Name: Current View
Near Clip Distance: 0.009999999776482582
Pitch: 0.8353979587554932
Target Frame: <Fixed Frame>
Value: Orbit (rviz)
Yaw: 0.7603980302810669
Saved: ~
Window Geometry:
Blob Detection Demo:
collapsed: false
Displays:
collapsed: false
Height: 1472
Hide Left Dock: false
Hide Right Dock: true
MorphologyEx Image:
collapsed: false
QMainWindow State: 000000ff00000000fd00000004000000000000026b00000482fc020000000efb0000001200530065006c0065006300740069006f006e00000001e10000009b000000da00fffffffb0000001e0054006f006f006c002000500072006f007000650072007400690065007302000001ed000001df00000185000000dafb000000120056006900650077007300200054006f006f02000001df000002110000018500000122fb000000200054006f006f006c002000500072006f0070006500720074006900650073003203000002880000011d000002210000017afb000000100044006900730070006c006100790073010000008600000482000001de00fffffffb0000002000730065006c0065006300740069006f006e00200062007500660066006500720200000138000000aa0000023a00000294fb00000014005700690064006500530074006500720065006f02000000e6000000d2000003ee0000030bfb0000000c004b0069006e0065006300740200000186000001060000030c00000261fb0000000a0049006d00610067006502000004b7000003880000026b000001d6fb0000000a0049006d00610067006502000005cf000002400000026b000000e2fb000000260042006c006f006200200044006500740065006300740069006f006e002000440065006d006f030000038500000140000002e800000206fb00000022005400680072006500730068006f006c00640065006400200049006d00610067006503000006ae00000142000002da00000204fb00000036005400680072006500730068006f006c00640065006400200049006d006100670065002000570069007400680020004d00610073006b030000038600000374000002ee000001f7fb00000024004d006f007200700068006f006c006f006700790045007800200049006d00610067006503000006b000000374000002de000001f800000001000001b400000482fc0200000003fb0000001e0054006f006f006c002000500072006f00700065007200740069006500730100000041000000780000000000000000fb0000000a005600690065007700730000000086000004820000017800fffffffb0000001200530065006c0065006300740069006f006e010000025a000000b20000000000000000000000020000097a000000a9fc0100000002fb0000000a0049006d00610067006502000003ce0000016600000280000001e0fb0000000a00560069006500770073030000004e00000080000002e100000197000000030000097a00000073fc0100000002fb0000000800540069006d006501000000000000097a000006de00fffffffb0000000800540069006d00650100000000000004500000000000000000000007000000048200000004000000040000000800000008fc0000000100000002000000010000000a0054006f006f006c00730100000000ffffffff0000000000000000
Selection:
collapsed: false
Thresholded Image:
collapsed: false
Thresholded Image With Mask:
collapsed: false
Time:
collapsed: false
Tool Properties:
collapsed: false
Views:
collapsed: true
Width: 2426
X: 134
Y: 68
86 changes: 86 additions & 0 deletions config/blob_detection_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
blob_color: 255
debug_view: true
filter_by_area: true
filter_by_circularity: false
filter_by_color: true
filter_by_convexity: false
filter_by_inertia: false
hue_lower_limit: 0
hue_upper_limit: 179
image:
compressed:
format: jpeg
jpeg_quality: 80
png_level: 9
compressedDepth:
depth_max: 10.0
depth_quantization: 100.0
png_level: 9
theora:
keyframe_frequency: 64
optimize_for: 1
quality: 31
target_bitrate: 800000
max_area: 40000.0
max_area_upper_limit: 40000
max_circularity: 1.0
max_convexity: 1.0
max_inertia_ratio: 1.0
min_area: 0.0
min_area_upper_limit: 40000
min_circularity: 0.0
min_convexity: 0.0
min_dist_between_blobs: 0.0
min_dist_between_blobs_upper_limit: 200
min_inertia_ratio: 0.0
morphology_ex_image:
compressed:
format: jpeg
jpeg_quality: 80
png_level: 9
compressedDepth:
depth_max: 10.0
depth_quantization: 100.0
png_level: 9
theora:
keyframe_frequency: 64
optimize_for: 1
quality: 31
target_bitrate: 800000
morphology_ex_kernel_size: 3
morphology_ex_type: 'off'
num_worker_threads: 1
queue_size: 3
sat_lower_limit: 0
sat_upper_limit: 255
thresholded_image:
compressed:
format: jpeg
jpeg_quality: 80
png_level: 9
compressedDepth:
depth_max: 10.0
depth_quantization: 100.0
png_level: 9
theora:
keyframe_frequency: 64
optimize_for: 1
quality: 31
target_bitrate: 800000
thresholded_image_with_mask:
compressed:
format: jpeg
jpeg_quality: 80
png_level: 9
compressedDepth:
depth_max: 10.0
depth_quantization: 100.0
png_level: 9
theora:
keyframe_frequency: 64
optimize_for: 1
quality: 31
target_bitrate: 800000
use_camera_info: false
val_lower_limit: 0
val_upper_limit: 255
Loading