misc.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 # BSD 3-Clause License
3 
4 # Copyright (c) 2019, Noam C. Golombek
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 are met:
9 
10 # 1. Redistributions of source code must retain the above copyright notice, this
11 # list of conditions and the following disclaimer.
12 
13 # 2. Redistributions in binary form must reproduce the above copyright notice,
14 # this list of conditions and the following disclaimer in the documentation
15 # and/or other materials provided with the distribution.
16 
17 # 3. Neither the name of the copyright holder nor the names of its
18 # contributors may be used to endorse or promote products derived from
19 # this software without specific prior written permission.
20 
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 
32 
33 
34 import rospy
35 import roslib
36 import cv2
37 
38 def exit_handler(camera, video_out, statistics_engine):
39  """Hadle when the program exits. calculate the statistics and close any open cv2 device
40  Inputs:
41  camera (Camera) the Camera being used
42  video_out (VideoSaver) the VideoSaver being used
43  statistics_engine (StatisticsEngine) the StatisticsEngine being used"""
44  if "cv2" in camera.camera_type and camera.video_source.isOpened():
45  camera.video_source.release()
46 
47  if (video_out is not None and
48  video_out.h_video_out is not None and
49  video_out.h_video_out.isOpened()):
50  video_out.h_video_out.release()
51  stat_string = statistics_engine.process_statistics()
52  rospy.logerr(stat_string)
53  cv2.destroyAllWindows()
54 
55 
56 def str2bool(s, return_string=False):
57  """
58  This function is not too correct if the argument is not any of True/False case
59  """
60  s = str(s)
61  if s.lower() in ('yes', 'true', 't', 'y', '1'):
62  return True
63  elif s.lower() in ('no', 'false', 'f', 'n', '0'):
64  return False
65  elif s is None:
66  return None
67  elif return_string:
68  return s
69  else:
70  return None
def str2bool(s, return_string=False)
Definition: misc.py:56
def exit_handler(camera, video_out, statistics_engine)
Definition: misc.py:38


cnn_bridge
Author(s): Noam C. Golombek , Alexander Beringolts
autogenerated on Mon Jun 10 2019 12:53:26