在Jetson Nano上实现单目相机 apritag_ros识别

一,apritag_ros安装

最开始采用克隆源码编译的方式进行安装,后来在Jetson nano上有opencv4与opencv3的依赖问题,后来索性直接采用二进制安装:

sudo apt-get install ros-melodic-apriltag-ros

二,单目相机数据读取

这里使用的是uvc_camera包:
launch文件:
这里使用了命名空间head_camera
head_camera为相机标定参数存放位置

  
  
    
	
	
	
    
	
	
	 
	
   
 

三,单目相机标定

安装标定包:

sudo apt-get install ros-melodic-camera-calibration

标定命令:

rosrun camera_calibration cameracalibrator.py --size 7x5 --square 0.0245 image:=/image_raw camera:=/camera --no-service-check

(1)–size 7x5 为棋盘内部角点的个数,方格几列几行(需要减1),比如我的标定板方格是8X6,则siez为7x5。
(2)–square 0.0245为每个棋盘格的边长
(3)image:=/image_raw 为当前订阅的图像来自名为/image_raw的topic
(4)camera:=/head_camera为摄像机名 主要用于COMMIT时自动更新内参参数

  1. 移动标定板:

为了达到良好的标定效果,需要在摄像机周围移动标定板,并完成以下基本需求:
(1)移动标定板到画面的最左、右,最上、下方。
(2)移动标定板到视野的最近和最远处。
(3)移动标定板使其充满整个画面。
(4)保持标定板倾斜状态并使其移动到画面的最左、右,最上、下方 。
当标定板移动到画面的最左、右方时,此时,窗口的x会达到最小或满值。同理,y指示标定板的在画面的上下位置,size表示标定板在视野中的距离,也可以理解为标定板离摄像头的远近。skew为标定板在视野中的倾斜位置。每次移动之后,请保持标定板不动直到窗口出现高亮提示。
直到条形变为绿色。当calibration按钮亮起时,代表已经有足够的数据进行摄像头的标定,此时请按下calibration并等待一分钟左右,标定界面会变成灰色,无法进行操作,属于正常情况。

在Jetson Nano上实现单目相机 apritag_ros识别_第1张图片

界面灰色恢复后,点击save,就会自动保存在tmp目录:

在这里插入图片描述

进入tmp目录解压:

在这里插入图片描述

解压出的ost.yaml即为标定结果
接着转换格式:

rosrun camera_calibration_parsers convert ost.yaml camera.yaml

在这里插入图片描述
转换出的camera.yaml即为标准的ROS内参格式
接着填入内参yaml参数:
需要注意的是我这里使用的uvc_camera功能包貌似只支持的camera_name 为camera的单目相机类型,写为front_camera或back_camera均会报错

image_width: 640
image_height: 480
camera_name: camera
camera_matrix:
  rows: 3
  cols: 3
  data: [626.3262036036353, 0, 300.5591565230002, 0, 627.3720075547461, 244.4302177150301, 0, 0, 1]
distortion_model: plumb_bob
distortion_coefficients:
  rows: 1
  cols: 5
  data: [0.1367930342496266, -0.1715444663163723, 0.001436032994469869, -0.00732797305912324, 0]
rectification_matrix:
  rows: 3
  cols: 3
  data: [1, 0, 0, 0, 1, 0, 0, 0, 1]
projection_matrix:
  rows: 3
  cols: 4
  data: [643.0006713867188, 0, 296.6836730995783, 0, 0, 648.4296875, 244.9678966293577, 0, 0, 0, 1, 0]

四,apriltag识别:

启动功能包:

roslaunch apriltag_ros continuous_detection.launch

查看launch内容,发现需要配置如下:
修改camera_name与image_topic为自己实际使用的


   
  
  
  

  
  
  
  
  
    
    
    

          
  

其中还要修改两个识别配置文件:
找到apriltag的安装目录,更改config:

在这里插入图片描述

settings.yaml:
我这里打印的为tag36h11类型的

tag_family:        'tag36h11' # options: tagStandard52h13, tagStandard41h12, tag36h11, tag25h9, tag16h5, tagCustom48h12, tagCircle21h7, tagCircle49h12  #支持单一标签类型
tag_threads:       2          # default: 2           # 设置Tag_Threads允许核心APRILTAG 2算法的某些部分运行并行计算。 典型的多线程优点和限制适用
tag_decimate:      1.0        # default: 1.0       #减小图像分辨率
tag_blur:          0.0        # default: 0.0            #设置tag_blur> 0模糊图像,tag_blur  < 0锐化图像
tag_refine_edges:  1          # default: 1       #增强了计算精度,但消耗了算力
tag_debug:         0          # default: 0            #1为保存中间图像到~/.ros
max_hamming_dist:  2          # default: 2 (Tunable parameter with 2 being a good choice - values >=3 consume large amounts of memory. Choose the largest value possible.)
# Other parameters
publish_tf:        true       # default: false       #发布tf坐标

tags.yaml
standalone_tags中需要依次填入所有需要识别的tag对应的id与size,size的话填边长,需要尽量准确,可以提高识别准确率

standalone_tags:
  [
    {id: 0, size: 0.033,name: "home"},   #size对应标签的大小
    {id: 1, size: 0.066},
    {id: 2, size: 0.04},
    {id: 3, size: 0.07},
    {id: 4, size: 0.045}
  ]
tag_bundles:
  [
  ]

接下来运行launch,即可进行识别

参考:
https://blog.csdn.net/lemonxiaoxiao/article/details/107719348
https://blog.csdn.net/qq_25241325/article/details/82705003

你可能感兴趣的:(ROS机器人,自动驾驶,视觉检测,人工智能)