Skip to content

Object detection

Christopher Strøm edited this page Sep 30, 2021 · 6 revisions

Setting up Darknet ROS w/ ZED camera

Stereolabs ZED camera can be integrated for use with Darknet ROS package for object detection and distance estimation.

Prerequisites:

  • ZED SDK setup
  • Nvidia CUDA setup

ZED ROS Wrapper Setup

  1. Create catkin workspace:
mkdir ~/zed_ros_wrapper
cd ~/darknet_ws
mkdir src

  1. Clone ZED ROS wrapper:
cd src
git clone https://github.com/stereolabs/zed-ros-wrapper

  1. Get ROS dependencies:
cd ..
rosdep install --from-paths src --ignore-src -r -y


  1. Build catkin workspace:
catkin build

  1. Source catkin workspace:
source ./devel/setup.bash


Darknet ROS ZED Setup

  1. Create catkin workspace:
mkdir ~/darknet_ws
cd ~/darknet_ws
mkdir src

  1. Clone ZED Darknet ROS wrapper:
cd src
git clone --recursive https://github.com/leoll2/darknet_ros_zed.git

  1. Update (CUDA) compute capability (version) of your GPU:
    Nvidia GPUs support different compute versions according to its model, which needs to be taken into account for compiling the workspace. Find your GPU in the list of supported GPUs in CUDA and edit darknet_ros/CMakeLists.txt with the appropriate compute version.
    Example for Nvidia GTX 1070 (compute version 6.1):
    1. Go to darknet_ros/CMakeLists.txt
cd ~/darknet_ws/src/darknet_ros_zed/darknet_ros
nano CMakeLists.txt

    1. Delete lines 24-30
    -O3
    -gencode arch=compute_30,code=sm_30
    -gencode arch=compute_35,code=sm_35
    -gencode arch=compute_50,code=[sm_50,compute_50]
    -gencode arch=compute_52,code=[sm_52,compute_52]
    -gencode arch=compute_61,code=sm_61
    -gencode arch=compute_62,code=sm_62
    1. Add compute version 6.1
    -O3 -gencode arch=compute_61,code=sm_61

  1. Build workspace with catkin:
cd ~/darknet_ws
catkin build

  1. Source workspace:
source devel/setup.bash

  1. Enable ZED camera in ROS launch:
# line 16 in /darknet_ros/launch/darknet_ros.launch
<arg name="zed"    default="true"/>

  1. Change subscribed topics in darknet ROS config to match published topics from ZED camera:
# line 4 in /darknet_ros/config/ros.yaml
topic: /zed2/zed_node/stereo_raw/image_raw_color

# line 6
dmap_topic: /zed2/zed_node/depth/depth_registered

  1. Download weights:
cd darknet_ws/src/darknet_ros_zed/darknet_ros/yolo_network_config/weights/
wget http://pjreddie.com/media/files/yolov2.weights
wget http://pjreddie.com/media/files/yolov2-tiny.weights
wget http://pjreddie.com/media/files/yolov2-voc.weights
wget http://pjreddie.com/media/files/yolov2-tiny-voc.weights

  1. (Optional) Use your own detection objects
    In order to use your own detection objects you need to provide your weights and your cfg file inside the directories:
darknet_ws/src/darknet_ros_zed/darknet_ros/yolo_network_config/weights/
darknet_ws/src/darknet_ros_zed/darknet_ros/yolo_network_config/cfg/

In addition, you need to create your config file for ROS where you define the names of the detection objects. You need to include it inside:

catkin_workspace/src/darknet_ros/darknet_ros/config/

Then in the launch file you have to point to your new config file in the line:

<rosparam command="load" ns="darknet_ros" file="$(find darknet_ros)/config/your_config_file.yaml"/>

  1. (Optional) Unit Tests
    Run the unit tests using the Catkin Command Line Tools:
catkin build darknet_ros --no-deps --verbose --catkin-make-args run_tests

You will (maybe) see an image popping up.

  1. Run Darknet using ROS launch:
roslaunch darknet_ros darknet_ros.launch

YOLO online

https://colab.research.google.com/drive/1xdjyBiY75MAVRSjgmiqI7pbRLn58VrbE?usp=sharing#scrollTo=M_btEC1N-YkS

Clone this wiki locally