forked from zbw/yiliao2026
标定+USB摄像头启动
This commit is contained in:
30
src/car_usb_cam/config/usb_camera_calibration.yaml
Normal file
30
src/car_usb_cam/config/usb_camera_calibration.yaml
Normal file
@@ -0,0 +1,30 @@
|
||||
image_width: 1920
|
||||
image_height: 1080
|
||||
camera_name: usb_camera
|
||||
camera_matrix:
|
||||
rows: 3
|
||||
cols: 3
|
||||
data: [281.59527801, 0.0, 364.60571628,
|
||||
0.0, 285.67845685, 204.92614855,
|
||||
0.0, 0.0, 1.0]
|
||||
|
||||
distortion_model: plumb_bob
|
||||
|
||||
distortion_coefficients:
|
||||
rows: 1
|
||||
cols: 5
|
||||
data: [ 0.03532389,-0.05576607, 0.00027529, 0.00241747, 0.01024998]
|
||||
|
||||
rectification_matrix:
|
||||
rows: 3
|
||||
cols: 3
|
||||
data: [1.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0,
|
||||
0.0, 0.0, 1.0]
|
||||
|
||||
projection_matrix:
|
||||
rows: 3
|
||||
cols: 4
|
||||
data: [281.59527801, 0.0, 364.60571628, 0.0,
|
||||
0.0, 285.67845685, 204.92614855, 0.0,
|
||||
0.0, 0.0, 1.0, 0.0]
|
||||
Binary file not shown.
Binary file not shown.
93
src/car_usb_cam/launch/hobot_usb_cam.launch.py
Normal file
93
src/car_usb_cam/launch/hobot_usb_cam.launch.py
Normal file
@@ -0,0 +1,93 @@
|
||||
# Copyright (c) 2024,D-Robotics.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from launch import LaunchDescription
|
||||
from launch.actions import DeclareLaunchArgument
|
||||
from launch.substitutions import LaunchConfiguration, TextSubstitution
|
||||
from launch_ros.actions import Node
|
||||
from launch.actions import IncludeLaunchDescription
|
||||
from launch.launch_description_sources import PythonLaunchDescriptionSource
|
||||
from ament_index_python import get_package_share_directory
|
||||
from ament_index_python.packages import get_package_prefix
|
||||
import os
|
||||
|
||||
def generate_launch_description():
|
||||
config_file_path = os.path.join(
|
||||
get_package_prefix('hobot_usb_cam'),
|
||||
"/home/sunrise/yiliao_ws/src/car_usb_cam/config/usb_camera_calibration.yaml")
|
||||
print("config_file_path is ", config_file_path)
|
||||
|
||||
return LaunchDescription([
|
||||
DeclareLaunchArgument(
|
||||
'usb_camera_calibration_file_path',
|
||||
default_value=TextSubstitution(text=str(config_file_path)),
|
||||
description='camera calibration file path'),
|
||||
DeclareLaunchArgument(
|
||||
'usb_frame_id',
|
||||
default_value='default_usb_cam',
|
||||
description='image message frame_id'),
|
||||
DeclareLaunchArgument(
|
||||
'usb_framerate',
|
||||
default_value='30',
|
||||
description='framerate'),
|
||||
DeclareLaunchArgument(
|
||||
'usb_image_height',
|
||||
default_value='450',
|
||||
description='image height'),
|
||||
DeclareLaunchArgument(
|
||||
'usb_image_width',
|
||||
default_value='800',
|
||||
description='image width'),
|
||||
DeclareLaunchArgument(
|
||||
'usb_io_method',
|
||||
default_value='mmap',
|
||||
description='io_method, mmap/read/userptr'),
|
||||
DeclareLaunchArgument(
|
||||
'usb_pixel_format',
|
||||
default_value='yuyv2rgb',
|
||||
description='pixel format, mjpeg/yuyv2rgb'),
|
||||
DeclareLaunchArgument(
|
||||
'usb_video_device',
|
||||
default_value='/dev/video0',
|
||||
description='usb camera device'),
|
||||
DeclareLaunchArgument(
|
||||
'usb_zero_copy',
|
||||
default_value='False',
|
||||
description='use zero copy or not'),
|
||||
# 启动零拷贝环境配置node
|
||||
IncludeLaunchDescription(
|
||||
PythonLaunchDescriptionSource(
|
||||
os.path.join(
|
||||
get_package_share_directory('hobot_shm'),
|
||||
'launch/hobot_shm.launch.py'))
|
||||
),
|
||||
Node(
|
||||
package='hobot_usb_cam',
|
||||
executable='hobot_usb_cam',
|
||||
name='hobot_usb_cam',
|
||||
parameters=[
|
||||
{"camera_calibration_file_path": LaunchConfiguration(
|
||||
'usb_camera_calibration_file_path')},
|
||||
{"frame_id": LaunchConfiguration('usb_frame_id')},
|
||||
{"framerate": LaunchConfiguration('usb_framerate')},
|
||||
{"image_height": LaunchConfiguration('usb_image_height')},
|
||||
{"image_width": LaunchConfiguration('usb_image_width')},
|
||||
{"io_method": LaunchConfiguration('usb_io_method')},
|
||||
{"pixel_format": LaunchConfiguration('usb_pixel_format')},
|
||||
{"video_device": LaunchConfiguration('usb_video_device')},
|
||||
{"zero_copy": LaunchConfiguration('usb_zero_copy')}
|
||||
],
|
||||
arguments=['--ros-args', '--log-level', 'warn']
|
||||
)
|
||||
])
|
||||
94
src/car_usb_cam/launch/hobot_usb_cam_websocket.launch.py
Normal file
94
src/car_usb_cam/launch/hobot_usb_cam_websocket.launch.py
Normal file
@@ -0,0 +1,94 @@
|
||||
# Copyright (c) 2024,D-Robotics.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import os
|
||||
from launch import LaunchDescription
|
||||
from launch.actions import DeclareLaunchArgument
|
||||
from launch.substitutions import LaunchConfiguration
|
||||
from launch_ros.actions import Node
|
||||
|
||||
from launch.actions import IncludeLaunchDescription
|
||||
from launch.launch_description_sources import PythonLaunchDescriptionSource
|
||||
from ament_index_python import get_package_share_directory
|
||||
|
||||
|
||||
def generate_launch_description():
|
||||
camera_node = None
|
||||
|
||||
print("using usb camera")
|
||||
# using usb cam publish image
|
||||
usb_cam_device_arg = DeclareLaunchArgument(
|
||||
'device',
|
||||
default_value='/dev/video0',
|
||||
description='usb camera device')
|
||||
|
||||
usb_node = IncludeLaunchDescription(
|
||||
PythonLaunchDescriptionSource(
|
||||
os.path.join(
|
||||
get_package_share_directory('car_usb_cam'),
|
||||
'launch/hobot_usb_cam.launch.py')),
|
||||
launch_arguments={
|
||||
'usb_image_width': '800',
|
||||
'usb_image_height': '450',
|
||||
'usb_framerate': '30',
|
||||
'usb_pixel_format': 'yuyv2rgb',# yuyv2rgb
|
||||
'usb_zero_copy': 'False',
|
||||
'usb_video_device': LaunchConfiguration('device')
|
||||
}.items()
|
||||
)
|
||||
|
||||
# nv12->jpeg
|
||||
jpeg_codec_node = IncludeLaunchDescription(
|
||||
PythonLaunchDescriptionSource(
|
||||
os.path.join(
|
||||
get_package_share_directory('hobot_codec'),
|
||||
'launch/hobot_codec_encode.launch.py')),
|
||||
launch_arguments={
|
||||
#'codec_in_mode': 'shared_mem',
|
||||
'codec_in_mode': 'ros',
|
||||
'codec_in_format': 'rgb8',#rgb8
|
||||
'codec_out_mode': 'ros', #
|
||||
#'codec_sub_topic': '/hbmem_img',
|
||||
'codec_sub_topic': '/image',
|
||||
'codec_pub_topic': '/image_mjpeg' # 原image_mjpeg
|
||||
}.items()
|
||||
)
|
||||
# web
|
||||
web_node = IncludeLaunchDescription(
|
||||
PythonLaunchDescriptionSource(
|
||||
os.path.join(
|
||||
get_package_share_directory('websocket'),
|
||||
'launch/websocket.launch.py')),
|
||||
launch_arguments={
|
||||
'websocket_image_topic': '/image_mjpeg',
|
||||
'websocket_only_show_image': 'True'
|
||||
}.items()
|
||||
)
|
||||
|
||||
|
||||
return LaunchDescription([
|
||||
# 启动零拷贝环境配置node
|
||||
IncludeLaunchDescription(
|
||||
PythonLaunchDescriptionSource(
|
||||
os.path.join(
|
||||
get_package_share_directory('hobot_shm'),
|
||||
'launch/hobot_shm.launch.py'))
|
||||
),
|
||||
usb_cam_device_arg,
|
||||
usb_node,
|
||||
# image codec
|
||||
jpeg_codec_node,
|
||||
# web display
|
||||
# web_node
|
||||
])
|
||||
46
src/car_usb_cam/local_setup.bash
Normal file
46
src/car_usb_cam/local_setup.bash
Normal file
@@ -0,0 +1,46 @@
|
||||
# generated from ament_package/template/package_level/local_setup.bash.in
|
||||
|
||||
# source local_setup.sh from same directory as this file
|
||||
_this_path=$(builtin cd "`dirname "${BASH_SOURCE[0]}"`" && pwd)
|
||||
# provide AMENT_CURRENT_PREFIX to shell script
|
||||
AMENT_CURRENT_PREFIX=$(builtin cd "`dirname "${BASH_SOURCE[0]}"`/../.." && pwd)
|
||||
# store AMENT_CURRENT_PREFIX to restore it before each environment hook
|
||||
_package_local_setup_AMENT_CURRENT_PREFIX=$AMENT_CURRENT_PREFIX
|
||||
|
||||
# trace output
|
||||
if [ -n "$AMENT_TRACE_SETUP_FILES" ]; then
|
||||
echo "# . \"$_this_path/local_setup.sh\""
|
||||
fi
|
||||
. "$_this_path/local_setup.sh"
|
||||
unset _this_path
|
||||
|
||||
# unset AMENT_ENVIRONMENT_HOOKS
|
||||
# if not appending to them for return
|
||||
if [ -z "$AMENT_RETURN_ENVIRONMENT_HOOKS" ]; then
|
||||
unset AMENT_ENVIRONMENT_HOOKS
|
||||
fi
|
||||
|
||||
# restore AMENT_CURRENT_PREFIX before evaluating the environment hooks
|
||||
AMENT_CURRENT_PREFIX=$_package_local_setup_AMENT_CURRENT_PREFIX
|
||||
# list all environment hooks of this package
|
||||
|
||||
# source all shell-specific environment hooks of this package
|
||||
# if not returning them
|
||||
if [ -z "$AMENT_RETURN_ENVIRONMENT_HOOKS" ]; then
|
||||
_package_local_setup_IFS=$IFS
|
||||
IFS=":"
|
||||
for _hook in $AMENT_ENVIRONMENT_HOOKS; do
|
||||
# restore AMENT_CURRENT_PREFIX for each environment hook
|
||||
AMENT_CURRENT_PREFIX=$_package_local_setup_AMENT_CURRENT_PREFIX
|
||||
# restore IFS before sourcing other files
|
||||
IFS=$_package_local_setup_IFS
|
||||
. "$_hook"
|
||||
done
|
||||
unset _hook
|
||||
IFS=$_package_local_setup_IFS
|
||||
unset _package_local_setup_IFS
|
||||
unset AMENT_ENVIRONMENT_HOOKS
|
||||
fi
|
||||
|
||||
unset _package_local_setup_AMENT_CURRENT_PREFIX
|
||||
unset AMENT_CURRENT_PREFIX
|
||||
29
src/car_usb_cam/package.xml
Normal file
29
src/car_usb_cam/package.xml
Normal file
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0"?>
|
||||
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
|
||||
<package format="3">
|
||||
<name>car_usb_cam</name>
|
||||
<version>2.3.0</version>
|
||||
<description>TogetheROS hobot usb camera</description>
|
||||
<maintainer email="kairui.wang@d-robotics.cc">kairui</maintainer>
|
||||
<license>Apache License 2.0</license>
|
||||
|
||||
<buildtool_depend>ament_cmake</buildtool_depend>
|
||||
|
||||
<depend>rclcpp</depend>
|
||||
<depend>std_msgs</depend>
|
||||
<depend>std_srvs</depend>
|
||||
<depend>sensor_msgs</depend>
|
||||
<depend>hbm_img_msgs</depend>
|
||||
<depend>v4l-utils</depend>
|
||||
<depend>yaml_cpp_vendor</depend>
|
||||
<!-- Only required for MJPEG to RGB converison -->
|
||||
<depend>ffmpeg</depend>
|
||||
<member_of_group>rosidl_interface_packages</member_of_group>
|
||||
|
||||
<test_depend>ament_lint_auto</test_depend>
|
||||
<test_depend>ament_lint_common</test_depend>
|
||||
|
||||
<export>
|
||||
<build_type>ament_cmake</build_type>
|
||||
</export>
|
||||
</package>
|
||||
Reference in New Issue
Block a user