From 255593aac9a58e8c457c90f04053fac1c33f764d Mon Sep 17 00:00:00 2001 From: Koki Shinjo Date: Tue, 9 Nov 2021 14:07:44 +0900 Subject: [PATCH 1/8] [jsk_image_capture] add jsk_image_capture pacakge --- jsk_image_capture/CMakeLists.txt | 22 ++++++ .../euslisp/jsk-image-capture-utils.l | 11 +++ jsk_image_capture/launch/demo.launch | 21 ++++++ jsk_image_capture/node_scripts/image_capture | 40 +++++++++++ .../node_scripts/image_capture_server | 16 +++++ .../sample_image_capture_client.py | 23 +++++++ jsk_image_capture/package.xml | 23 +++++++ jsk_image_capture/setup.py | 9 +++ .../src/jsk_image_capture/__init__.py | 0 .../jsk_image_capture/jsk_image_capture.py | 69 +++++++++++++++++++ jsk_image_capture/srv/Capture.srv | 5 ++ 11 files changed, 239 insertions(+) create mode 100644 jsk_image_capture/CMakeLists.txt create mode 100644 jsk_image_capture/euslisp/jsk-image-capture-utils.l create mode 100644 jsk_image_capture/launch/demo.launch create mode 100755 jsk_image_capture/node_scripts/image_capture create mode 100755 jsk_image_capture/node_scripts/image_capture_server create mode 100755 jsk_image_capture/node_scripts/sample_image_capture_client.py create mode 100644 jsk_image_capture/package.xml create mode 100644 jsk_image_capture/setup.py create mode 100644 jsk_image_capture/src/jsk_image_capture/__init__.py create mode 100644 jsk_image_capture/src/jsk_image_capture/jsk_image_capture.py create mode 100644 jsk_image_capture/srv/Capture.srv diff --git a/jsk_image_capture/CMakeLists.txt b/jsk_image_capture/CMakeLists.txt new file mode 100644 index 000000000..50f3e6d71 --- /dev/null +++ b/jsk_image_capture/CMakeLists.txt @@ -0,0 +1,22 @@ +cmake_minimum_required(VERSION 3.0.2) +project(jsk_image_capture) + +find_package(catkin REQUIRED COMPONENTS + roscpp + rospy + message_generation +) + +catkin_python_setup() + +add_service_files( + FILES + Capture.srv +) + +generate_messages( + DEPENDENCIES +) + +catkin_package( +) diff --git a/jsk_image_capture/euslisp/jsk-image-capture-utils.l b/jsk_image_capture/euslisp/jsk-image-capture-utils.l new file mode 100644 index 000000000..a4d71aa3d --- /dev/null +++ b/jsk_image_capture/euslisp/jsk-image-capture-utils.l @@ -0,0 +1,11 @@ +(ros::load-ros-manifest "jsk_image_capture") + +(defparameter *jsk-image-capture-service-name* "/image_capture_server/capture") + +(defun capture-image (image-topic file-name) + (let (res (req (instance jsk_image_capture::CaptureRequest :init))) + (send req :image_topic image-topic) + (send req :file_name file-name) + (setq res (ros::service-call *jsk-image-capture-service-name* req t)) + (send res :success) + )) diff --git a/jsk_image_capture/launch/demo.launch b/jsk_image_capture/launch/demo.launch new file mode 100644 index 000000000..5d432572b --- /dev/null +++ b/jsk_image_capture/launch/demo.launch @@ -0,0 +1,21 @@ + + + + + + + image_height: $(arg video_height) + image_width: $(arg video_width) + framerate: $(arg video_framerate) + pixel_format: yuyv + + + + + + + + image_topic: /usb_cam_node/image_raw + + + diff --git a/jsk_image_capture/node_scripts/image_capture b/jsk_image_capture/node_scripts/image_capture new file mode 100755 index 000000000..db250b743 --- /dev/null +++ b/jsk_image_capture/node_scripts/image_capture @@ -0,0 +1,40 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- + +import rospy +from jsk_image_capture.jsk_image_capture import capture_image +import sys +import argparse +from cv_bridge import CvBridge + + +def main(): + + myargv = rospy.myargv(argv=sys.argv) + parser = argparse.ArgumentParser() + parser.add_argument('image_topic', help='Image topic to save an image.') + parser.add_argument('file_name', help='Filename of saved image.') + args = parser.parse_args(args=myargv) + + rospy.init_node('image_capture', anonymous=True) + cv_bridge = CvBridge() + success, message = capture_image( + args.image_topic, + args.file_name, + cv_bridge + ) + + if success: + rospy.loginfo('Successfully saved image from {} to {}.'.format( + args.image_topic, + args.file_name + )) + else: + rospy.logerr('Failed to save image from {} to {}.'.format( + args.image_topic, + args.file_name + )) + + +if __name__ == '__main__': + main() diff --git a/jsk_image_capture/node_scripts/image_capture_server b/jsk_image_capture/node_scripts/image_capture_server new file mode 100755 index 000000000..216104099 --- /dev/null +++ b/jsk_image_capture/node_scripts/image_capture_server @@ -0,0 +1,16 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- + +import rospy +from jsk_image_capture.jsk_image_capture import ImageCaptureServer + + +def main(): + + rospy.init_node('image_capture_server') + server = ImageCaptureServer() + rospy.spin() + + +if __name__ == '__main__': + main() diff --git a/jsk_image_capture/node_scripts/sample_image_capture_client.py b/jsk_image_capture/node_scripts/sample_image_capture_client.py new file mode 100755 index 000000000..cee857f59 --- /dev/null +++ b/jsk_image_capture/node_scripts/sample_image_capture_client.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- + +import rospy +from jsk_image_capture.jsk_image_capture import ImageCaptureClient + + +def main(): + + rospy.init_node('sample_image_capture_client') + image_topic = rospy.get_param('~image_topic') + directory = rospy.get_param('~directory', '/tmp') + client = ImageCaptureClient() + rate = rospy.Rate(1) + for index in range(10): + rate.sleep() + file_name = directory + '/sample_image_{}.jpg'.format(index) + client.capture(image_topic, file_name) + rospy.loginfo('Capturing image from {} to {}'.format(image_topic, file_name)) + + +if __name__ == '__main__': + main() diff --git a/jsk_image_capture/package.xml b/jsk_image_capture/package.xml new file mode 100644 index 000000000..49d9170e5 --- /dev/null +++ b/jsk_image_capture/package.xml @@ -0,0 +1,23 @@ + + + jsk_image_capture + 2.2.11 + The jsk_image_capture package + + Koki Shinjo + Koki Shinjo + + BSD + + catkin + + message_generation + roscpp + rospy + + message_runtime + rospy + + + + diff --git a/jsk_image_capture/setup.py b/jsk_image_capture/setup.py new file mode 100644 index 000000000..a798279a6 --- /dev/null +++ b/jsk_image_capture/setup.py @@ -0,0 +1,9 @@ +from distutils.core import setup +from catkin_pkg.python_setup import generate_distutils_setup + +d = generate_distutils_setup( + packages=['jsk_image_capture'], + package_dir={'': 'src'} +) + +setup(**d) diff --git a/jsk_image_capture/src/jsk_image_capture/__init__.py b/jsk_image_capture/src/jsk_image_capture/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/jsk_image_capture/src/jsk_image_capture/jsk_image_capture.py b/jsk_image_capture/src/jsk_image_capture/jsk_image_capture.py new file mode 100644 index 000000000..f25821972 --- /dev/null +++ b/jsk_image_capture/src/jsk_image_capture/jsk_image_capture.py @@ -0,0 +1,69 @@ +# -*- encoding: utf-8 -*- + +import rospy +from cv_bridge import CvBridge +from sensor_msgs.msg import Image +import cv2 + +from .srv import Capture, CaptureRequest, CaptureResponse + + +def capture_image(image_topic, file_name, cv_bridge): + duration_timeout = rospy.get_param('~duration_timeout', 10.0) + try: + msg = rospy.wait_for_message( + image_topic, + Image, + timeout=rospy.Duration(duration_timeout) + ) + image = cv_bridge.imgmsg_to_cv2(msg, desired_encoding='bgr8') + cv2.imwrite(file_name, image) + return True, 'Success' + except rospy.ROSException as e: + rospy.loginfo('Error: {]'.format(e)) + return False, 'Error: {}'.format(e) + + +class ImageCaptureServer: + + def __init__(self): + self.cv_bridge = CvBridge() + self.srv = rospy.Service( + '~capture', + Capture, + self.handler) + + def handler(self, req): + success, message = capture_image( + req.image_topic, + req.file_name, + self.cv_bridge + ) + res = CaptureResponse() + res.success = success + res.message = message + return res + + +class ImageCaptureClient: + + def __init__(self): + + rospy.wait_for_service( + '/image_capture_server/capture', + rospy.Duration(10) + ) + self.client = rospy.ServiceProxy( + '/image_capture_server/capture', + Capture + ) + + def capture(self, + image_topic, + file_name + ): + req = CaptureRequest() + req.image_topic = image_topic + req.file_name = file_name + ret = self.client(req) + return ret.success, ret.message diff --git a/jsk_image_capture/srv/Capture.srv b/jsk_image_capture/srv/Capture.srv new file mode 100644 index 000000000..166a7e517 --- /dev/null +++ b/jsk_image_capture/srv/Capture.srv @@ -0,0 +1,5 @@ +string image_topic +string file_name +--- +bool success +string message From f9166138711aa97ee0cb87f0209ceadcc11fbf95 Mon Sep 17 00:00:00 2001 From: Koki Shinjo Date: Wed, 10 Nov 2021 13:39:44 +0900 Subject: [PATCH 2/8] [jsk_image_capture] add message_runtime to CATKIN_DEPENDS --- jsk_image_capture/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jsk_image_capture/CMakeLists.txt b/jsk_image_capture/CMakeLists.txt index 50f3e6d71..1bcbd28c5 100644 --- a/jsk_image_capture/CMakeLists.txt +++ b/jsk_image_capture/CMakeLists.txt @@ -19,4 +19,6 @@ generate_messages( ) catkin_package( + CATKIN_DEPENDS + message_runtime ) From 2ec6bcae27bd65edea5d6cba8a8add85fdec0f06 Mon Sep 17 00:00:00 2001 From: Koki Shinjo Date: Wed, 10 Nov 2021 14:15:43 +0900 Subject: [PATCH 3/8] [jsk_image_capture] rename library name --- jsk_image_capture/node_scripts/image_capture | 2 +- jsk_image_capture/node_scripts/image_capture_server | 2 +- jsk_image_capture/node_scripts/sample_image_capture_client.py | 2 +- .../{jsk_image_capture.py => image_capture_utils.py} | 4 +++- 4 files changed, 6 insertions(+), 4 deletions(-) rename jsk_image_capture/src/jsk_image_capture/{jsk_image_capture.py => image_capture_utils.py} (93%) diff --git a/jsk_image_capture/node_scripts/image_capture b/jsk_image_capture/node_scripts/image_capture index db250b743..a58b1c798 100755 --- a/jsk_image_capture/node_scripts/image_capture +++ b/jsk_image_capture/node_scripts/image_capture @@ -2,7 +2,7 @@ # -*- encoding: utf-8 -*- import rospy -from jsk_image_capture.jsk_image_capture import capture_image +from jsk_image_capture.image_capture_utils import capture_image import sys import argparse from cv_bridge import CvBridge diff --git a/jsk_image_capture/node_scripts/image_capture_server b/jsk_image_capture/node_scripts/image_capture_server index 216104099..a5f041e2c 100755 --- a/jsk_image_capture/node_scripts/image_capture_server +++ b/jsk_image_capture/node_scripts/image_capture_server @@ -2,7 +2,7 @@ # -*- encoding: utf-8 -*- import rospy -from jsk_image_capture.jsk_image_capture import ImageCaptureServer +from jsk_image_capture.image_capture_utils import ImageCaptureServer def main(): diff --git a/jsk_image_capture/node_scripts/sample_image_capture_client.py b/jsk_image_capture/node_scripts/sample_image_capture_client.py index cee857f59..6bfaa14f7 100755 --- a/jsk_image_capture/node_scripts/sample_image_capture_client.py +++ b/jsk_image_capture/node_scripts/sample_image_capture_client.py @@ -2,7 +2,7 @@ # -*- encoding: utf-8 -*- import rospy -from jsk_image_capture.jsk_image_capture import ImageCaptureClient +from jsk_image_capture.image_capture_utils import ImageCaptureClient def main(): diff --git a/jsk_image_capture/src/jsk_image_capture/jsk_image_capture.py b/jsk_image_capture/src/jsk_image_capture/image_capture_utils.py similarity index 93% rename from jsk_image_capture/src/jsk_image_capture/jsk_image_capture.py rename to jsk_image_capture/src/jsk_image_capture/image_capture_utils.py index f25821972..a9297831e 100644 --- a/jsk_image_capture/src/jsk_image_capture/jsk_image_capture.py +++ b/jsk_image_capture/src/jsk_image_capture/image_capture_utils.py @@ -5,7 +5,9 @@ from sensor_msgs.msg import Image import cv2 -from .srv import Capture, CaptureRequest, CaptureResponse +from jsk_image_capture.srv import Capture +from jsk_image_capture.srv import CaptureRequest +from jsk_image_capture.srv import CaptureResponse def capture_image(image_topic, file_name, cv_bridge): From cd69ce459cb436a0413b40b92f11a2fc5e2b6e26 Mon Sep 17 00:00:00 2001 From: Koki Shinjo Date: Wed, 10 Nov 2021 13:11:48 +0900 Subject: [PATCH 4/8] [image_view2] move source files to include/ and src/ directory and refactor CMakeLists.txt to reduce warnings --- jsk_ros_patch/image_view2/CMakeLists.txt | 38 +++++++++++-------- .../image_view2/{ => include}/image_view2.h | 0 .../image_view2/{ => src}/image_view2.cpp | 0 .../{ => src}/image_view2_node.cpp | 0 .../{ => src}/points_rectangle_extractor.cpp | 0 5 files changed, 22 insertions(+), 16 deletions(-) rename jsk_ros_patch/image_view2/{ => include}/image_view2.h (100%) rename jsk_ros_patch/image_view2/{ => src}/image_view2.cpp (100%) rename jsk_ros_patch/image_view2/{ => src}/image_view2_node.cpp (100%) rename jsk_ros_patch/image_view2/{ => src}/points_rectangle_extractor.cpp (100%) diff --git a/jsk_ros_patch/image_view2/CMakeLists.txt b/jsk_ros_patch/image_view2/CMakeLists.txt index c9509c3c9..68eea0b86 100644 --- a/jsk_ros_patch/image_view2/CMakeLists.txt +++ b/jsk_ros_patch/image_view2/CMakeLists.txt @@ -19,6 +19,12 @@ endif() find_package(catkin REQUIRED COMPONENTS roscpp dynamic_reconfigure cv_bridge std_msgs sensor_msgs geometry_msgs image_transport tf image_geometry message_filters message_generation std_srvs pcl_ros) +find_package(PCL REQUIRED) + +find_package(OpenCV REQUIRED) + +find_package(Boost REQUIRED COMPONENTS) + generate_dynamic_reconfigure_options( cfg/ImageView2.cfg ) @@ -31,31 +37,31 @@ add_service_files( FILES ChangeMode.srv ) -include_directories(include ${catkin_INCLUDE_DIRS}) +generate_messages(DEPENDENCIES geometry_msgs std_msgs) + +catkin_package( + DEPENDS OpenCV PCL + CATKIN_DEPENDS roscpp cv_bridge std_msgs sensor_msgs geometry_msgs image_transport tf image_geometry message_filters + INCLUDE_DIRS include +) + +include_directories( + include + ${catkin_INCLUDE_DIRS} + ${PCL_INCLUDE_DIRS} + ${Boost_INCLUDE_DIRS} +) # Image viewers -find_package(OpenCV REQUIRED) -add_executable(image_view2 image_view2.cpp image_view2_node.cpp) +add_executable(image_view2 src/image_view2.cpp src/image_view2_node.cpp) target_link_libraries(image_view2 ${OpenCV_LIBS} ${catkin_LIBRARIES}) add_dependencies(image_view2 ${PROJECT_NAME}_gencpp ${PROJECT_NAME}_gencfg) # Point Rectangle Extractor -add_executable(points_rectangle_extractor points_rectangle_extractor.cpp) -find_package(Boost REQUIRED COMPONENTS) -include_directories(${Boost_INCLUDE_DIRS}) -find_package(PCL REQUIRED) -include_directories(${PCL_INCLUDE_DIRS}) +add_executable(points_rectangle_extractor src/points_rectangle_extractor.cpp) target_link_libraries(points_rectangle_extractor ${Boost_LIBRARIES} ${catkin_LIBRARIES}) add_dependencies(points_rectangle_extractor ${PROJECT_NAME}_gencpp) -generate_messages(DEPENDENCIES geometry_msgs std_msgs) - -catkin_package( - DEPENDS OpenCV PCL - CATKIN_DEPENDS roscpp cv_bridge std_msgs sensor_msgs geometry_msgs image_transport tf image_geometry message_filters - INCLUDE_DIRS # TODO include - LIBRARIES # TODO -) # From https://github.com/jsk-ros-pkg/jsk_recognition/pull/2345 # Install header files directly into ${CATKIN_PACKAGE_INCLUDE_DESTINATION}. diff --git a/jsk_ros_patch/image_view2/image_view2.h b/jsk_ros_patch/image_view2/include/image_view2.h similarity index 100% rename from jsk_ros_patch/image_view2/image_view2.h rename to jsk_ros_patch/image_view2/include/image_view2.h diff --git a/jsk_ros_patch/image_view2/image_view2.cpp b/jsk_ros_patch/image_view2/src/image_view2.cpp similarity index 100% rename from jsk_ros_patch/image_view2/image_view2.cpp rename to jsk_ros_patch/image_view2/src/image_view2.cpp diff --git a/jsk_ros_patch/image_view2/image_view2_node.cpp b/jsk_ros_patch/image_view2/src/image_view2_node.cpp similarity index 100% rename from jsk_ros_patch/image_view2/image_view2_node.cpp rename to jsk_ros_patch/image_view2/src/image_view2_node.cpp diff --git a/jsk_ros_patch/image_view2/points_rectangle_extractor.cpp b/jsk_ros_patch/image_view2/src/points_rectangle_extractor.cpp similarity index 100% rename from jsk_ros_patch/image_view2/points_rectangle_extractor.cpp rename to jsk_ros_patch/image_view2/src/points_rectangle_extractor.cpp From 1cfca2d40164d6feb33250c8bea21a33cdd7154f Mon Sep 17 00:00:00 2001 From: Koki Shinjo Date: Wed, 10 Nov 2021 14:35:31 +0900 Subject: [PATCH 5/8] [jsk_image_capture][image_view2] merge jsk_image_capture to image_view2 --- jsk_image_capture/CMakeLists.txt | 24 ------------------- .../euslisp/jsk-image-capture-utils.l | 11 --------- jsk_image_capture/package.xml | 23 ------------------ jsk_ros_patch/image_view2/CMakeLists.txt | 18 ++++++++++++-- .../image_view2/euslisp/image-capture-utils.l | 9 +++++++ .../image_view2}/node_scripts/image_capture | 2 +- .../node_scripts/image_capture_server | 2 +- .../sample_image_capture_client.py | 2 +- jsk_ros_patch/image_view2/package.xml | 3 +++ .../sample/sample_image_capture.launch | 4 ++-- .../image_view2}/setup.py | 2 +- .../image_view2/src/image_view2}/__init__.py | 0 .../src/image_view2}/image_capture_utils.py | 6 ++--- .../image_view2}/srv/Capture.srv | 0 14 files changed, 37 insertions(+), 69 deletions(-) delete mode 100644 jsk_image_capture/CMakeLists.txt delete mode 100644 jsk_image_capture/euslisp/jsk-image-capture-utils.l delete mode 100644 jsk_image_capture/package.xml create mode 100644 jsk_ros_patch/image_view2/euslisp/image-capture-utils.l rename {jsk_image_capture => jsk_ros_patch/image_view2}/node_scripts/image_capture (94%) rename {jsk_image_capture => jsk_ros_patch/image_view2}/node_scripts/image_capture_server (75%) rename {jsk_image_capture => jsk_ros_patch/image_view2}/node_scripts/sample_image_capture_client.py (89%) rename jsk_image_capture/launch/demo.launch => jsk_ros_patch/image_view2/sample/sample_image_capture.launch (69%) rename {jsk_image_capture => jsk_ros_patch/image_view2}/setup.py (82%) rename {jsk_image_capture/src/jsk_image_capture => jsk_ros_patch/image_view2/src/image_view2}/__init__.py (100%) rename {jsk_image_capture/src/jsk_image_capture => jsk_ros_patch/image_view2/src/image_view2}/image_capture_utils.py (93%) rename {jsk_image_capture => jsk_ros_patch/image_view2}/srv/Capture.srv (100%) diff --git a/jsk_image_capture/CMakeLists.txt b/jsk_image_capture/CMakeLists.txt deleted file mode 100644 index 1bcbd28c5..000000000 --- a/jsk_image_capture/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -cmake_minimum_required(VERSION 3.0.2) -project(jsk_image_capture) - -find_package(catkin REQUIRED COMPONENTS - roscpp - rospy - message_generation -) - -catkin_python_setup() - -add_service_files( - FILES - Capture.srv -) - -generate_messages( - DEPENDENCIES -) - -catkin_package( - CATKIN_DEPENDS - message_runtime -) diff --git a/jsk_image_capture/euslisp/jsk-image-capture-utils.l b/jsk_image_capture/euslisp/jsk-image-capture-utils.l deleted file mode 100644 index a4d71aa3d..000000000 --- a/jsk_image_capture/euslisp/jsk-image-capture-utils.l +++ /dev/null @@ -1,11 +0,0 @@ -(ros::load-ros-manifest "jsk_image_capture") - -(defparameter *jsk-image-capture-service-name* "/image_capture_server/capture") - -(defun capture-image (image-topic file-name) - (let (res (req (instance jsk_image_capture::CaptureRequest :init))) - (send req :image_topic image-topic) - (send req :file_name file-name) - (setq res (ros::service-call *jsk-image-capture-service-name* req t)) - (send res :success) - )) diff --git a/jsk_image_capture/package.xml b/jsk_image_capture/package.xml deleted file mode 100644 index 49d9170e5..000000000 --- a/jsk_image_capture/package.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - jsk_image_capture - 2.2.11 - The jsk_image_capture package - - Koki Shinjo - Koki Shinjo - - BSD - - catkin - - message_generation - roscpp - rospy - - message_runtime - rospy - - - - diff --git a/jsk_ros_patch/image_view2/CMakeLists.txt b/jsk_ros_patch/image_view2/CMakeLists.txt index 68eea0b86..91563d3ed 100644 --- a/jsk_ros_patch/image_view2/CMakeLists.txt +++ b/jsk_ros_patch/image_view2/CMakeLists.txt @@ -25,6 +25,8 @@ find_package(OpenCV REQUIRED) find_package(Boost REQUIRED COMPONENTS) +catkin_python_setup() + generate_dynamic_reconfigure_options( cfg/ImageView2.cfg ) @@ -34,14 +36,14 @@ add_message_files( ) add_service_files( - FILES ChangeMode.srv + FILES ChangeMode.srv Capture.srv ) generate_messages(DEPENDENCIES geometry_msgs std_msgs) catkin_package( DEPENDS OpenCV PCL - CATKIN_DEPENDS roscpp cv_bridge std_msgs sensor_msgs geometry_msgs image_transport tf image_geometry message_filters + CATKIN_DEPENDS roscpp cv_bridge std_msgs sensor_msgs geometry_msgs image_transport tf image_geometry message_filters message_runtime INCLUDE_DIRS include ) @@ -82,6 +84,18 @@ install(TARGETS image_view2 points_rectangle_extractor LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} ) +catkin_install_python( + PROGRAMS node_scripts/image_capture node_scripts/image_capture_server node_scripts/sample_image_capture_client.py + DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} +) +install(DIRECTORY euslisp + DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} + USE_SOURCE_PERMISSIONS +) +install(DIRECTORY sample + DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} + USE_SOURCE_PERMISSIONS +) if(CATKIN_ENABLE_TESTING) find_package(rostest REQUIRED) diff --git a/jsk_ros_patch/image_view2/euslisp/image-capture-utils.l b/jsk_ros_patch/image_view2/euslisp/image-capture-utils.l new file mode 100644 index 000000000..58ccff135 --- /dev/null +++ b/jsk_ros_patch/image_view2/euslisp/image-capture-utils.l @@ -0,0 +1,9 @@ +(ros::load-ros-manifest "image_view2") + +(defun capture-image (image-topic file-name) + (let (res (req (instance image_view2::CaptureRequest :init))) + (send req :image_topic image-topic) + (send req :file_name file-name) + (setq res (ros::service-call "/image_capture_server/capture" req t)) + (send res :success) + )) diff --git a/jsk_image_capture/node_scripts/image_capture b/jsk_ros_patch/image_view2/node_scripts/image_capture similarity index 94% rename from jsk_image_capture/node_scripts/image_capture rename to jsk_ros_patch/image_view2/node_scripts/image_capture index a58b1c798..fb2c48bbc 100755 --- a/jsk_image_capture/node_scripts/image_capture +++ b/jsk_ros_patch/image_view2/node_scripts/image_capture @@ -2,7 +2,7 @@ # -*- encoding: utf-8 -*- import rospy -from jsk_image_capture.image_capture_utils import capture_image +from image_view2.image_capture_utils import capture_image import sys import argparse from cv_bridge import CvBridge diff --git a/jsk_image_capture/node_scripts/image_capture_server b/jsk_ros_patch/image_view2/node_scripts/image_capture_server similarity index 75% rename from jsk_image_capture/node_scripts/image_capture_server rename to jsk_ros_patch/image_view2/node_scripts/image_capture_server index a5f041e2c..93dc6f010 100755 --- a/jsk_image_capture/node_scripts/image_capture_server +++ b/jsk_ros_patch/image_view2/node_scripts/image_capture_server @@ -2,7 +2,7 @@ # -*- encoding: utf-8 -*- import rospy -from jsk_image_capture.image_capture_utils import ImageCaptureServer +from image_view2.image_capture_utils import ImageCaptureServer def main(): diff --git a/jsk_image_capture/node_scripts/sample_image_capture_client.py b/jsk_ros_patch/image_view2/node_scripts/sample_image_capture_client.py similarity index 89% rename from jsk_image_capture/node_scripts/sample_image_capture_client.py rename to jsk_ros_patch/image_view2/node_scripts/sample_image_capture_client.py index 6bfaa14f7..0bde17d01 100755 --- a/jsk_image_capture/node_scripts/sample_image_capture_client.py +++ b/jsk_ros_patch/image_view2/node_scripts/sample_image_capture_client.py @@ -2,7 +2,7 @@ # -*- encoding: utf-8 -*- import rospy -from jsk_image_capture.image_capture_utils import ImageCaptureClient +from image_view2.image_capture_utils import ImageCaptureClient def main(): diff --git a/jsk_ros_patch/image_view2/package.xml b/jsk_ros_patch/image_view2/package.xml index 0c39fe811..1c8b369a3 100644 --- a/jsk_ros_patch/image_view2/package.xml +++ b/jsk_ros_patch/image_view2/package.xml @@ -22,6 +22,7 @@ message_generation pcl_ros roscpp + rospy rostest sensor_msgs std_msgs @@ -37,10 +38,12 @@ message_runtime pcl_ros roscpp + rospy sensor_msgs std_msgs std_srvs tf + usb_cam python-numpy python3-numpy diff --git a/jsk_image_capture/launch/demo.launch b/jsk_ros_patch/image_view2/sample/sample_image_capture.launch similarity index 69% rename from jsk_image_capture/launch/demo.launch rename to jsk_ros_patch/image_view2/sample/sample_image_capture.launch index 5d432572b..d9dce86b8 100644 --- a/jsk_image_capture/launch/demo.launch +++ b/jsk_ros_patch/image_view2/sample/sample_image_capture.launch @@ -11,9 +11,9 @@ - + - + image_topic: /usb_cam_node/image_raw diff --git a/jsk_image_capture/setup.py b/jsk_ros_patch/image_view2/setup.py similarity index 82% rename from jsk_image_capture/setup.py rename to jsk_ros_patch/image_view2/setup.py index a798279a6..8e0740340 100644 --- a/jsk_image_capture/setup.py +++ b/jsk_ros_patch/image_view2/setup.py @@ -2,7 +2,7 @@ from catkin_pkg.python_setup import generate_distutils_setup d = generate_distutils_setup( - packages=['jsk_image_capture'], + packages=['image_view2'], package_dir={'': 'src'} ) diff --git a/jsk_image_capture/src/jsk_image_capture/__init__.py b/jsk_ros_patch/image_view2/src/image_view2/__init__.py similarity index 100% rename from jsk_image_capture/src/jsk_image_capture/__init__.py rename to jsk_ros_patch/image_view2/src/image_view2/__init__.py diff --git a/jsk_image_capture/src/jsk_image_capture/image_capture_utils.py b/jsk_ros_patch/image_view2/src/image_view2/image_capture_utils.py similarity index 93% rename from jsk_image_capture/src/jsk_image_capture/image_capture_utils.py rename to jsk_ros_patch/image_view2/src/image_view2/image_capture_utils.py index a9297831e..270284f28 100644 --- a/jsk_image_capture/src/jsk_image_capture/image_capture_utils.py +++ b/jsk_ros_patch/image_view2/src/image_view2/image_capture_utils.py @@ -5,9 +5,9 @@ from sensor_msgs.msg import Image import cv2 -from jsk_image_capture.srv import Capture -from jsk_image_capture.srv import CaptureRequest -from jsk_image_capture.srv import CaptureResponse +from image_view2.srv import Capture +from image_view2.srv import CaptureRequest +from image_view2.srv import CaptureResponse def capture_image(image_topic, file_name, cv_bridge): diff --git a/jsk_image_capture/srv/Capture.srv b/jsk_ros_patch/image_view2/srv/Capture.srv similarity index 100% rename from jsk_image_capture/srv/Capture.srv rename to jsk_ros_patch/image_view2/srv/Capture.srv From 1c1e55b995727cec654faacd9ed1b01a04fbcee1 Mon Sep 17 00:00:00 2001 From: Koki Shinjo Date: Thu, 11 Nov 2021 17:40:13 +0900 Subject: [PATCH 6/8] [image_view2] capture image asynchronously --- .../node_scripts/image_capture_server | 2 +- .../src/image_view2/image_capture_utils.py | 20 +++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/jsk_ros_patch/image_view2/node_scripts/image_capture_server b/jsk_ros_patch/image_view2/node_scripts/image_capture_server index 93dc6f010..17a4bee8f 100755 --- a/jsk_ros_patch/image_view2/node_scripts/image_capture_server +++ b/jsk_ros_patch/image_view2/node_scripts/image_capture_server @@ -9,7 +9,7 @@ def main(): rospy.init_node('image_capture_server') server = ImageCaptureServer() - rospy.spin() + server.spin() if __name__ == '__main__': diff --git a/jsk_ros_patch/image_view2/src/image_view2/image_capture_utils.py b/jsk_ros_patch/image_view2/src/image_view2/image_capture_utils.py index 270284f28..01a16a490 100644 --- a/jsk_ros_patch/image_view2/src/image_view2/image_capture_utils.py +++ b/jsk_ros_patch/image_view2/src/image_view2/image_capture_utils.py @@ -9,6 +9,8 @@ from image_view2.srv import CaptureRequest from image_view2.srv import CaptureResponse +from queue import Queue + def capture_image(image_topic, file_name, cv_bridge): duration_timeout = rospy.get_param('~duration_timeout', 10.0) @@ -30,20 +32,30 @@ class ImageCaptureServer: def __init__(self): self.cv_bridge = CvBridge() + self.task_queue = Queue() self.srv = rospy.Service( '~capture', Capture, self.handler) - def handler(self, req): - success, message = capture_image( + def spin(self): + + rate = rospy.Rate(1) + while not rospy.is_shutdown(): + rate.sleep() + if not self.task_queue.empty(): + req = self.task_queue.get() + success, message = capture_image( req.image_topic, req.file_name, self.cv_bridge ) + rospy.loginfo('Capture a image: {}, {}'.format(success, message)) + + def handler(self, req): + self.task_queue.put(req) res = CaptureResponse() - res.success = success - res.message = message + res.success = True return res From 3e43e601870d509c36f1a51dfe83db1533dd84ce Mon Sep 17 00:00:00 2001 From: Koki Shinjo Date: Fri, 26 Nov 2021 13:08:05 +0900 Subject: [PATCH 7/8] [image_view2] fix capture server --- .../image_view2/src/image_view2/image_capture_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jsk_ros_patch/image_view2/src/image_view2/image_capture_utils.py b/jsk_ros_patch/image_view2/src/image_view2/image_capture_utils.py index 01a16a490..e6da9ef6d 100644 --- a/jsk_ros_patch/image_view2/src/image_view2/image_capture_utils.py +++ b/jsk_ros_patch/image_view2/src/image_view2/image_capture_utils.py @@ -24,7 +24,7 @@ def capture_image(image_topic, file_name, cv_bridge): cv2.imwrite(file_name, image) return True, 'Success' except rospy.ROSException as e: - rospy.loginfo('Error: {]'.format(e)) + rospy.loginfo('Error: {}'.format(e)) return False, 'Error: {}'.format(e) From 794aec825d856fcfa39ac8aacb6d612b8e8b4cfe Mon Sep 17 00:00:00 2001 From: Koki Shinjo Date: Fri, 26 Nov 2021 14:12:17 +0900 Subject: [PATCH 8/8] [image_view2] add error print to image_capture_client --- jsk_ros_patch/image_view2/euslisp/image-capture-utils.l | 3 +++ 1 file changed, 3 insertions(+) diff --git a/jsk_ros_patch/image_view2/euslisp/image-capture-utils.l b/jsk_ros_patch/image_view2/euslisp/image-capture-utils.l index 58ccff135..7c0a5972c 100644 --- a/jsk_ros_patch/image_view2/euslisp/image-capture-utils.l +++ b/jsk_ros_patch/image_view2/euslisp/image-capture-utils.l @@ -5,5 +5,8 @@ (send req :image_topic image-topic) (send req :file_name file-name) (setq res (ros::service-call "/image_capture_server/capture" req t)) + (if (send res :success) + (ros::ros-info "Succeed to capture image from ~A to ~A" image-topic file-name) + (ros::ros-error "Failed to capture image from ~A to ~A : ~A" image-topic file-name (send res :message))) (send res :success) ))