Skip to content

Commit dfd53aa

Browse files
committed
feat: update dependencies and enhance launch file to support virtual environment integration
1 parent 4519bee commit dfd53aa

4 files changed

Lines changed: 26 additions & 2 deletions

File tree

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,21 @@ ROS 2 wrap for YOLO models from [Ultralytics](https://github.com/ultralytics/ult
2828
## Installation
2929

3030
```shell
31+
# Clone this repo
3132
cd ~/ros2_ws/src
3233
git clone https://github.com/mgonzs13/yolo_ros.git
34+
35+
# Install uv and python dependencies
36+
curl -LsSf https://astral.sh/uv/install.sh | sh
37+
source ~/.bashrc
3338
cd yolo_ros
3439
uv sync
40+
41+
# Install rosdep dependencies and build
3542
cd ~/ros2_ws
3643
rosdep install --from-paths src --ignore-src -r -y
3744
colcon build
3845
source ~/ros2_ws/install/setup.bash
39-
source ~/ros2_ws/src/yolo_ros/.venv/bin/activate
4046
```
4147

4248
## Docker

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description = "ROS 2 wrap for YOLO models from Ultralytics"
55
requires-python = ">=3.10"
66
dependencies = [
77
"numpy<2",
8-
"opencv-python>=4.8.1.78",
8+
"opencv-python-headless>=4.8.1.78",
99
"typing-extensions>=4.4.0",
1010
"ultralytics==8.4.6",
1111
"lap>=0.5.12",

yolo_bringup/launch/yolo.launch.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@
1414
# along with this program. If not, see <https://www.gnu.org/licenses/>.
1515

1616

17+
import os
18+
import glob
19+
import subprocess
20+
1721
from launch import LaunchDescription, LaunchContext
1822
from launch.actions import DeclareLaunchArgument, OpaqueFunction
1923
from launch.substitutions import LaunchConfiguration, PythonExpression
2024
from launch_ros.actions import Node
2125
from launch.conditions import IfCondition
26+
from ament_index_python.packages import get_package_share_directory
2227

2328

2429
def generate_launch_description():
@@ -28,6 +33,14 @@ def run_yolo(context: LaunchContext, use_tracking, use_3d):
2833
use_tracking = eval(context.perform_substitution(use_tracking))
2934
use_3d = eval(context.perform_substitution(use_3d))
3035

36+
share_dir = get_package_share_directory("yolo_ros")
37+
subprocess.run(["uv", "sync", "--project", share_dir], check=True)
38+
venv_site_pkgs = glob.glob(
39+
os.path.join(share_dir, ".venv", "lib", "python*", "site-packages")
40+
)
41+
existing_pythonpath = os.environ.get("PYTHONPATH", "")
42+
new_pythonpath = ":".join(venv_site_pkgs + [existing_pythonpath]).strip(":")
43+
3144
model_type = LaunchConfiguration("model_type")
3245
model_type_cmd = DeclareLaunchArgument(
3346
"model_type",
@@ -231,6 +244,7 @@ def run_yolo(context: LaunchContext, use_tracking, use_3d):
231244
executable="yolo_node",
232245
name="yolo_node",
233246
namespace=namespace,
247+
additional_env={"PYTHONPATH": new_pythonpath},
234248
parameters=[
235249
{
236250
"model_type": model_type,
@@ -259,6 +273,7 @@ def run_yolo(context: LaunchContext, use_tracking, use_3d):
259273
executable="tracking_node",
260274
name="tracking_node",
261275
namespace=namespace,
276+
additional_env={"PYTHONPATH": new_pythonpath},
262277
parameters=[{"tracker": tracker, "image_reliability": image_reliability}],
263278
remappings=[("image_raw", input_image_topic)],
264279
condition=IfCondition(PythonExpression([str(use_tracking)])),
@@ -269,6 +284,7 @@ def run_yolo(context: LaunchContext, use_tracking, use_3d):
269284
executable="detect_3d_node",
270285
name="detect_3d_node",
271286
namespace=namespace,
287+
additional_env={"PYTHONPATH": new_pythonpath},
272288
parameters=[
273289
{
274290
"target_frame": target_frame,
@@ -290,6 +306,7 @@ def run_yolo(context: LaunchContext, use_tracking, use_3d):
290306
executable="debug_node",
291307
name="debug_node",
292308
namespace=namespace,
309+
additional_env={"PYTHONPATH": new_pythonpath},
293310
parameters=[{"image_reliability": image_reliability}],
294311
remappings=[
295312
("image_raw", input_image_topic),

yolo_ros/setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
data_files=[
1010
("share/ament_index/resource_index/packages", ["resource/" + package_name]),
1111
("share/" + package_name, ["package.xml"]),
12+
("share/" + package_name, ["../pyproject.toml"]),
1213
],
1314
install_requires=["setuptools"],
1415
zip_safe=True,

0 commit comments

Comments
 (0)