diff --git a/get_obj_dist/launch/node.launch b/get_obj_dist/launch/node.launch new file mode 100644 index 0000000000000000000000000000000000000000..ffc5dbe483d9b90839cc4faa4fc80734716a43e5 --- /dev/null +++ b/get_obj_dist/launch/node.launch @@ -0,0 +1,15 @@ +<?xml version="1.0"?> +<!-- --> +<launch> + + <arg name="node_name" default="objetc_to_distance"/> + <arg name="output" default="screen"/> + + <node pkg="get_obj_dist" + name="$(arg node_name)" + type="object_to_distance.py" + output="$(arg output)" + args=""> + </node> + +</launch> diff --git a/get_obj_dist/src/object_to_distance.py b/get_obj_dist/src/object_to_distance.py index fb682489b0172209281521f8ea88090409d5cf5a..e382af0ac5bc5d1999ade10a7cd9fd04ffdb3311 100755 --- a/get_obj_dist/src/object_to_distance.py +++ b/get_obj_dist/src/object_to_distance.py @@ -46,7 +46,7 @@ class obj_dist: ts.registerCallback(self.callback) def callback(self, bbx, image, depth): - print('working lol') + #print('working lol') if bbx.length: cv_depth = self.bridge.imgmsg_to_cv2(depth, 'passthrough') cv_image = self.bridge.imgmsg_to_cv2(image, 'bgr8') diff --git a/human_detection/launch/hdm_full.launch b/human_detection/launch/hdm_full.launch deleted file mode 100644 index 809a9d990bb71f37bfa309c2f7977ace425d2abf..0000000000000000000000000000000000000000 --- a/human_detection/launch/hdm_full.launch +++ /dev/null @@ -1,11 +0,0 @@ -<launch> - <arg name="debug" default="True"/> - <arg name="bag" default="/November\ 1/01.bag"/> - <arg name="path" default="/home/jerry/Documents/workspaces/human_detection/src/ROS_human_detection/rosbag"/> - - <group if="$(arg debug)"> - <node pkg="rosbag" type="play" args="-l -q $(arg path)$(arg bag)" output="screen" name="rosbag_playback"/> - </group> - - <node pkg="human_detection" type="webcam.py" name="webcam"/> -</launch> diff --git a/human_detection/launch/node.launch b/human_detection/launch/node.launch new file mode 100644 index 0000000000000000000000000000000000000000..f6149f428495187d7ccebcdfbbdc2c92b8572279 --- /dev/null +++ b/human_detection/launch/node.launch @@ -0,0 +1,16 @@ +<?xml version="1.0"?> +<!-- --> +<launch> + + <arg name="node_name" default="human_detection"/> + <arg name="virtual_env_path" default="$(env HOME)/iri-lab/virtualenv/raadical_venv"/> + <arg name="output" default="screen"/> + + <node pkg="human_detection" + name="$(arg node_name)" + type="human_detector.py" + output="$(arg output)" + args="--venv $(arg virtual_env_path)"> + </node> + +</launch> diff --git a/human_detection/launch/test_realsense.launch b/human_detection/launch/test_realsense.launch new file mode 100644 index 0000000000000000000000000000000000000000..7afacf9f0151f4ff52619aa1e834934a2dd20b4d --- /dev/null +++ b/human_detection/launch/test_realsense.launch @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?> +<launch> + + <arg name="virtual_env_path" default="$(env HOME)/iri-lab/virtualenv/raadical_venv"/> + <arg name="output" default="screen"/> + + <include file="$(find realsense2_camera)/launch/rs_rgbd.launch"> + </include> + + <include file="$(find human_detection)/launch/node.launch"> + <arg name="node_name" value="human_detection"/> + <arg name="virtual_env_path" value="$(arg virtual_env_path)"/> + <arg name="output" value="$(arg output)"/> + </include> + + <include file="$(find get_obj_dist)/launch/node.launch"> + <arg name="node_name" value="object_to_distance"/> + <arg name="output" value="$(arg output)"/> + </include> + + <node name="rviz" + pkg="rviz" + type="rviz" + args="-d $(find human_detection)/rviz/test.rviz"/> + +</launch> diff --git a/human_detection/rviz/test.rviz b/human_detection/rviz/test.rviz new file mode 100644 index 0000000000000000000000000000000000000000..5da8adfccee24438c6e640f2c41627890205e9af --- /dev/null +++ b/human_detection/rviz/test.rviz @@ -0,0 +1,218 @@ +Panels: + - Class: rviz/Displays + Help Height: 78 + Name: Displays + Property Tree Widget: + Expanded: + - /Global Options1 + - /Status1 + Splitter Ratio: 0.5 + Tree Height: 617 + - 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: PointCloud2 +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 + - Alpha: 1 + Autocompute Intensity Bounds: true + Autocompute Value Bounds: + Max Value: 10 + Min Value: -10 + Value: true + Axis: Z + Channel Name: intensity + Class: rviz/PointCloud2 + Color: 255; 255; 255 + Color Transformer: RGB8 + Decay Time: 0 + Enabled: true + Invert Rainbow: false + Max Color: 255; 255; 255 + Min Color: 0; 0; 0 + Name: PointCloud2 + Position Transformer: XYZ + Queue Size: 10 + Selectable: true + Size (Pixels): 3 + Size (m): 0.009999999776482582 + Style: Flat Squares + Topic: /camera/depth_registered/points + Unreliable: false + Use Fixed Frame: true + Use rainbow: true + Value: true + - Class: rviz/TF + Enabled: true + Frame Timeout: 15 + Frames: + All Enabled: true + camera_aligned_depth_to_color_frame: + Value: true + camera_color_frame: + Value: true + camera_color_optical_frame: + Value: true + camera_depth_frame: + Value: true + camera_depth_optical_frame: + Value: true + camera_link: + Value: true + Marker Scale: 1 + Name: TF + Show Arrows: true + Show Axes: true + Show Names: true + Tree: + camera_link: + camera_aligned_depth_to_color_frame: + camera_color_optical_frame: + {} + camera_color_frame: + {} + camera_depth_frame: + camera_depth_optical_frame: + {} + Update Interval: 0 + Value: true + - Class: rviz/Image + Enabled: true + Image Topic: /human_detected_image/image + Max Value: 1 + Median window: 5 + Min Value: 0 + Name: DetectionImage + Normalize Range: true + Queue Size: 2 + Transport Hint: raw + Unreliable: false + Value: true + - Class: rviz/Image + Enabled: true + Image Topic: /obj_to_dist/human_distance + Max Value: 1 + Median window: 5 + Min Value: 0 + Name: DetectionDistanceImage + Normalize Range: true + Queue Size: 2 + Transport Hint: raw + Unreliable: false + Value: true + - Class: rviz/MarkerArray + Enabled: true + Marker Topic: /obj_to_dist/show_people_marker_array + Name: MarkerArray + Namespaces: + "": true + Queue Size: 100 + Value: true + Enabled: true + Global Options: + Background Color: 48; 48; 48 + Default Light: true + Fixed Frame: camera_link + 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: 9.410797119140625 + Enable Stereo Rendering: + Stereo Eye Separation: 0.05999999865889549 + Stereo Focal Distance: 1 + Swap Stereo Eyes: false + Value: false + Focal Point: + X: 2.791478395462036 + Y: -0.4713762700557709 + Z: 1.070740818977356 + Focal Shape Fixed Size: true + Focal Shape Size: 0.05000000074505806 + Invert Z Axis: false + Name: Current View + Near Clip Distance: 0.009999999776482582 + Pitch: 1.5697963237762451 + Target Frame: <Fixed Frame> + Value: Orbit (rviz) + Yaw: 3.145402669906616 + Saved: ~ +Window Geometry: + DetectionDistanceImage: + collapsed: false + DetectionImage: + collapsed: false + Displays: + collapsed: false + Height: 846 + Hide Left Dock: false + Hide Right Dock: false + QMainWindow State: 000000ff00000000fd000000040000000000000156000002f4fc0200000008fb0000001200530065006c0065006300740069006f006e00000001e10000009b0000005c00fffffffb0000001e0054006f006f006c002000500072006f007000650072007400690065007302000001ed000001df00000185000000a3fb000000120056006900650077007300200054006f006f02000001df000002110000018500000122fb000000200054006f006f006c002000500072006f0070006500720074006900650073003203000002880000011d000002210000017afb000000100044006900730070006c006100790073010000003d000002f4000000c900fffffffb0000002000730065006c0065006300740069006f006e00200062007500660066006500720200000138000000aa0000023a00000294fb00000014005700690064006500530074006500720065006f02000000e6000000d2000003ee0000030bfb0000000c004b0069006e0065006300740200000186000001060000030c0000026100000001000001b3000002f4fc0200000005fb0000001e0054006f006f006c002000500072006f00700065007200740069006500730100000041000000780000000000000000fb0000001c0044006500740065006300740069006f006e0049006d006100670065010000003d000001780000001600fffffffb0000002c0044006500740065006300740069006f006e00440069007300740061006e006300650049006d00610067006501000001bb000001760000001600fffffffb0000000a0056006900650077007300000000ff000001ee000000a400fffffffb0000001200530065006c0065006300740069006f006e010000025a000000b200000000000000000000000200000490000000a9fc0100000001fb0000000a00560069006500770073030000004e00000080000002e10000019700000003000006510000003efc0100000002fb0000000800540069006d0065000000000000000651000004f300fffffffb0000000800540069006d006501000000000000045000000000000000000000033c000002f400000004000000040000000800000008fc0000000100000002000000010000000a0054006f006f006c00730100000000ffffffff0000000000000000 + Selection: + collapsed: false + Time: + collapsed: false + Tool Properties: + collapsed: false + Views: + collapsed: false + Width: 1617 + X: 67 + Y: 0 diff --git a/human_detection/src/webcam.py b/human_detection/src/human_detector.py similarity index 92% rename from human_detection/src/webcam.py rename to human_detection/src/human_detector.py index 61b84c999557fad8e195dc2dd839e2e2b4d489d1..ccefd91c7b15d2bc67a6240e73c6f8ca0ba74e24 100755 --- a/human_detection/src/webcam.py +++ b/human_detection/src/human_detector.py @@ -1,4 +1,8 @@ #!/usr/bin/env python + +from venv_utils import activate_virtual_env +venv_status = activate_virtual_env() + import time import sys import os @@ -139,17 +143,6 @@ class human_detector: coordinates.ymax = int(boxes[0, counter, 2] * screen_height) coordinates.xmax = int(boxes[0, counter, 3] * screen_width) bbx_list.people_list.append(coordinates) - rospy.wait_for_service('return_to_home') - try: - if spotted is False: - rospy.loginfo("Human spotted! Returning home") - return_to_home = rospy.ServiceProxy('return_to_home', Trigger) - status = return_to_home() - rospy.loginfo(status.message) - spotted = True - - except: - print("Service call failed: %s") counter += 1 diff --git a/human_detection/src/venv_utils.py b/human_detection/src/venv_utils.py new file mode 100755 index 0000000000000000000000000000000000000000..7332366b4b33595aaf969404c76aa3bcfbe4df20 --- /dev/null +++ b/human_detection/src/venv_utils.py @@ -0,0 +1,32 @@ +import sys + + +def activate_virtual_env(path=None, arg='--venv'): + """ + Activate Python Virtual Environment (virtualenv) within other python interpreter /or default interperter + @param path: An absolute path to virtual environment folder. + @param arg: an argument to parse virtual environment's absolute path, not used if param path is specified + @return: True if activation success, False otherwise + """ + activate_this = "/bin/activate_this.py" + path_to_venv = None + + if path is not None or len(sys.argv) > 1: + try: + # Non-restrict arg parse + args = sys.argv[1:] + path_to_venv = path.rstrip('/') if path is not None else args[args.index(arg) + 1].rstrip('/') + activate_this = path_to_venv + activate_this + print "Activate Python Virtual Environment at: " + str(path_to_venv) + execfile(activate_this, dict(__file__=activate_this)) + return True + except ValueError: + print "WARNING: No input path to Virtual ENV, will use default python" + return False + except IOError: + print "WARNING: Wrong Input Path to Virtual ENV, will use default python" + return False + else: + print "WARNING: No input path to Virtual ENV, will use default python" + return False +