Skip to content

Commit 07c35db

Browse files
committed
1 parent e313986 commit 07c35db

File tree

10 files changed

+632
-0
lines changed

10 files changed

+632
-0
lines changed

CMakeLists.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ generate_dynamic_reconfigure_options(
6666
cfg/HSVColorFilter.cfg
6767
cfg/LabColorFilter.cfg
6868
cfg/WatershedSegmentation.cfg
69+
#
70+
cfg/Tracking.cfg
6971
)
7072

7173
## Generate messages in the 'msg' folder
@@ -107,6 +109,7 @@ add_message_files(
107109
add_service_files(
108110
FILES
109111
FaceRecognitionTrain.srv
112+
SetImages.srv
110113
)
111114

112115
## Generate added messages and services with any dependencies listed here
@@ -327,6 +330,36 @@ opencv_apps_add_nodelet(segment_objects src/nodelet/segment_objects_nodelet.cpp)
327330
# ./videostab.cpp
328331
opencv_apps_add_nodelet(watershed_segmentation src/nodelet/watershed_segmentation_nodelet.cpp) # ./watershed.cpp
329332

333+
# contrib modules (https://docs.opencv.org/4.x/d3/d81/tutorial_contrib_root.html)
334+
# alphamat. Information Flow Alpha Matting
335+
# aruco. ArUco marker detection (aruco module)
336+
# barcode. Tutorials for barcode module
337+
# bgsegm. Tutorials for bgsegm module
338+
# bioinspired. Discovering the human retina and its use for image processing
339+
# ccalib. Multi-camera Calibration
340+
# ccalib. Omnidirectional Camera Calibration
341+
# cvv. Interactive Visual Debugging of Computer Vision applications
342+
# dnn_objdetect. Object Detection using CNNs
343+
# dnn_superres. Super Resolution using CNNs
344+
# face. Tutorials for face module
345+
# face. Tutorial on Facial Landmark Detector API
346+
# fuzzy. Fuzzy image processing tutorials
347+
# hdf. The Hierarchical Data Format (hdf) I/O
348+
# julia. Introduction to Julia OpenCV Binding
349+
# line_descriptor. Line Features Tutorial
350+
# mcc. Color Correction Model
351+
# mcc. ColorChecker Detection
352+
# phase_unwrapping. Phase Unwrapping tutorial
353+
# sfm. Structure From Motion
354+
# stereo. Quasi Dense Stereo (stereo module)
355+
# structured_light. Structured Light tutorials
356+
# text. Text module
357+
# tracking. Customizing the CN Tracker
358+
if(OpenCV_VERSION VERSION_GREATER "4.0")
359+
opencv_apps_add_nodelet(tracking src/nodelet/tracking_nodelet.cpp) # tracking. Introduction to OpenCV Tracker
360+
endif()
361+
# tracking. Using MultiTracker
362+
330363
# ros examples
331364
opencv_apps_add_nodelet(simple_example src/nodelet/simple_example_nodelet.cpp)
332365
opencv_apps_add_nodelet(simple_compressed_example src/nodelet/simple_compressed_example_nodelet.cpp)
@@ -387,6 +420,9 @@ if(CATKIN_ENABLE_TESTING)
387420
message(WARNING "roslaunch_add_file check fails with unsupported doc attributes ${roslaunch_VERSION}")
388421
else()
389422
file(GLOB LAUNCH_FILES launch/*.launch)
423+
if(NOT OpenCV_VERSION VERSION_GREATER "4.0")
424+
list(REMOVE_ITEM LAUNCH_FILES ${CMAKE_CURRENT_SOURCE_DIR}/launch/tracking.launch)
425+
endif()
390426
foreach(LAUNCH_FILE ${LAUNCH_FILES})
391427
roslaunch_add_file_check(${LAUNCH_FILE})
392428
endforeach()

cfg/Tracking.cfg

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#! /usr/bin/env python
2+
3+
PACKAGE = "opencv_apps"
4+
5+
from dynamic_reconfigure.parameter_generator_catkin import *
6+
7+
gen = ParameterGenerator()
8+
9+
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)
10+
11+
tracking_algorithm = gen.enum([gen.const("MIL", int_t, 0, "MIL (Multiple Instance Learning) tracker"),
12+
gen.const("BOOSTING", int_t, 1, "On-line version of the AdaBoost tracker"),
13+
gen.const("MEDIANFLOW", int_t, 2, "Median Flow tracker"),
14+
gen.const("TLD", int_t, 3, "TLD (Tracking, learning and detection) tracker"),
15+
gen.const("KCF", int_t, 4, "KCF (Kernelized Correlation Filter) tracker"),
16+
gen.const("GOTURN", int_t, 5, "GOTURN (Generic Object Tracking Using Regression Networks) tracker"),
17+
gen.const("MOSSE", int_t, 6, "MOSSE (Minimum Output Sum of Squared Error) tracker"),],
18+
"An enum for Tracking Algorithms")
19+
20+
gen.add("tracking_algorithm", int_t, 0, "Tracking Algorithm", 4, 0, 6, edit_method=tracking_algorithm)
21+
22+
exit(gen.generate(PACKAGE, "tracking", "Tracking"))
23+

launch/tracking.launch

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<launch>
2+
<arg name="node_name" default="tracking" />
3+
<arg name="image" default="image" doc="The image topic. Should be remapped to the name of the real image topic." />
4+
5+
<arg name="use_camera_info" default="false" doc="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." />
6+
<arg name="debug_view" default="true" doc="Specify whether the node displays a window to show edge image" />
7+
<arg name="queue_size" default="3" doc="Specigy queue_size of input image subscribers" />
8+
9+
<arg name="tracking_algorithm" default="4" doc="Tracking algorithm 0: MIL, 1: Boosting, 2: Medianflow, 3: TLD, 4: KCF, 5: GOTURN, 6: MOSSE" />
10+
11+
<!-- threshold.cpp -->
12+
<node name="$(arg node_name)" pkg="opencv_apps" type="tracking" output="screen">
13+
<remap from="image" to="$(arg image)" />
14+
<param name="use_camera_info" value="$(arg use_camera_info)" />
15+
<param name="debug_view" value="$(arg debug_view)" />
16+
<param name="queue_size" value="$(arg queue_size)" />
17+
<param name="tracking_algorithm" value="$(arg tracking_algorithm)" />
18+
</node>
19+
20+
</launch>

nodelet_plugins.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@
127127
<description>Nodelet for histogram equalization</description>
128128
</class>
129129

130+
<class name="opencv_apps/tracking" type="opencv_apps::TrackingNodelet" base_class_type="nodelet::Nodelet">
131+
<description>Nodelet for tracking</description>
132+
</class>
133+
130134
<!--
131135
for backward compatibility, can be removed in M-turtle
132136
-->

scripts/set_image.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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+
from __future__ import print_function
36+
37+
try:
38+
input = raw_input
39+
except:
40+
pass
41+
42+
import argparse
43+
import cv2
44+
import cv_bridge
45+
import os
46+
import sys
47+
import time
48+
import rospy
49+
50+
from opencv_apps.msg import Rect
51+
from opencv_apps.srv import SetImages, SetImagesRequest
52+
53+
54+
if __name__ == '__main__':
55+
parser = argparse.ArgumentParser(description='Send ROI (and template image) to the tracker')
56+
parser.add_argument('center_x', type=int, help='X coordinates of center of ROI')
57+
parser.add_argument('center_y', type=int, help='Y coordinates of center of ROI')
58+
parser.add_argument('width', type=int, help='Width of ROI')
59+
parser.add_argument('height', type=int, help='Height of ROI')
60+
parser.add_argument('image_file_name', nargs='?', help='File name of template image')
61+
parser.add_argument('--debug-view', action='store_true', help='Display input_file with ROI')
62+
args, unknown = parser.parse_known_args();
63+
64+
rospy.init_node("set_image")
65+
rospy.wait_for_service('set_roi')
66+
set_roi = rospy.ServiceProxy('set_roi', SetImages)
67+
68+
req = SetImagesRequest()
69+
70+
# set roi
71+
rospy.loginfo("Set ROI({},{}, {}, {})".format(args.center_x, args.center_y, args.width, args.height))
72+
rect = Rect(x=args.center_x, y=args.center_y, width=args.width, height=args.height)
73+
req.rects=[rect]
74+
75+
# set images
76+
if args.image_file_name:
77+
fname = args.image_file_name
78+
if os.path.exists(fname):
79+
im = cv2.imread(fname)
80+
im_msg = cv_bridge.CvBridge().cv2_to_imgmsg(im, "bgr8")
81+
rospy.loginfo("Set Image{} from {}".format(im.shape, fname))
82+
req.images = [im_msg]
83+
if args.debug_view:
84+
cv2.rectangle(im,
85+
(int(rect.x - rect.width/2), int(rect.y - rect.height/2)),
86+
(int(rect.x + rect.width/2), int(rect.y + rect.height/2)),
87+
(0, 255, 0), 3)
88+
cv2.imshow('template image', im)
89+
cv2.waitKey(100)
90+
else:
91+
rospy.logerr("{} not found exitting".format(fname))
92+
sys.exit(1)
93+
94+
ret = set_roi(images=req.images, rects=req.rects)
95+
rospy.loginfo("'set_roi' returns\n {}".format(ret))
96+
if args.debug_view:
97+
time.sleep(2)
98+
cv2.destroyAllWindows()

0 commit comments

Comments
 (0)