首页 > 代码库 > ros下单目相机校正
ros下单目相机校正
1. 安装对应的驱动与程序包。
图像对应包 http://wiki.ros.org/camera_calibration 在gitbub下载image_pipeline : https://github.com/ros-perception/image_pipeline
安装对应的驱动
1)uvc_camera /camera_umd sudo apt-get install ros-indigo-xxxxx ( camera_umd jpeg_streamer uvc_camera )
2)usb_cam http://wiki.ros.org/usb_cam /usb_cam
2. 相机校正的步骤
1) 启动相机 uvc_camera 或者 usb_cam
roslaunch usb_cam camera.launch (个人的 camera.launch) rviz 详细文件见后。(也能够自己先打开rviz 加入topic后保存,以后直接调用保存的.rviz就可以)
camera.launch
<launch> <node pkg="rviz" type="rviz" name="rviz" args="-d $(find usb_cam)/launch/camera.rviz"/> <node name="usb_cam" pkg="usb_cam" type="usb_cam_node" respawn="false" output="log"> <param name="video_device" type="string" value="http://www.mamicode.com/dev/video0"/> <param name="camera_frame_id" type="string" value="http://www.mamicode.com/usb_cam"/> <param name="framerate" type="int" value="http://www.mamicode.com/30"/> <param name="io_method" type="string" value="http://www.mamicode.com/mmap"/> <param name="image_width" type="int" value="http://www.mamicode.com/640"/> <param name="image_height" type="int" value="http://www.mamicode.com/480"/> <param name="pixel_format" type="string" value="http://www.mamicode.com/yuyv"/> </node> </launch>
2) 启动校正程序
參见教程 http://wiki.ros.org/camera_calibration/Tutorials/MonocularCalibration
yhzhao@yhzhao:~$ rostopic list /usb_cam/camera_info /usb_cam/image_raw ################################ /usb_cam/image_raw/compressed /usb_cam/image_raw/compressed/parameter_descriptions /usb_cam/image_raw/compressed/parameter_updates /usb_cam/image_raw/compressedDepth
rosrun camera_calibration cameracalibrator.py --size 8x6 --square 0.0245 image:=/usb_cam/image_raw camera:=/camera
出错:例如以下
(‘Waiting for service‘, ‘/camera/set_camera_info‘, ‘...‘)
Service not found
执行例如以下语句: 角点数 棋盘格大小 topic映射
rosrun camera_calibration cameracalibrator.py --size 8x6 --square 0.0245 image:=/usb_cam/image_raw camera:=/camera --no-service-check
注意:校正採集的角点图像要多。数量达到一定效果时,calibration button会变亮,点击就可以进行校正运算。结果在终端有显示,也能够选择保存。
校正输出结果:
(‘D = ‘, [-0.1976212648687889, 0.1688022413942262, 0.0124442419926021, 0.005870906198680583, 0.0]) (‘K = ‘, [485.5897704187133, 0.0, 297.2537641560215, 0.0, 491.6813624489518, 296.2003190013238, 0.0, 0.0, 1.0]) (‘R = ‘, [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0]) (‘P = ‘, [462.4408874511719, 0.0, 301.47298442859574, 0.0, 0.0, 469.7864074707031, 301.54598383033044, 0.0, 0.0, 0.0, 1.0, 0.0]) None # oST version 5.0 parameters [image] width 640 height 480 [narrow_stereo] camera matrix 485.589770 0.000000 297.253764 0.000000 491.681362 296.200319 0.000000 0.000000 1.000000 distortion -0.197621 0.168802 0.012444 0.005871 0.000000 rectification 1.000000 0.000000 0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 1.000000 projection 462.440887 0.000000 301.472984 0.000000 0.000000 469.786407 301.545984 0.000000 0.000000 0.000000 1.000000 0.000000
3. 启动 ros 相机相应节点公布图像topic
carmera_haved_calibrated.launch
<launch> <node pkg="rviz" type="rviz" name="rviz" args="-d $(find usb_cam)/launch/camera.rviz"/> <node name="usb_cam" pkg="usb_cam" type="usb_cam_node" respawn="false" output="log"> <param name="video_device" type="string" value="http://www.mamicode.com/dev/video0"/> <param name="camera_frame_id" type="string" value="http://www.mamicode.com/usb_cam"/> <param name="io_method" type="string" value="http://www.mamicode.com/mmap"/> <param name="image_width" type="int" value="http://www.mamicode.com/640"/> <param name="image_height" type="int" value="http://www.mamicode.com/480"/> <param name="pixel_format" type="string" value="http://www.mamicode.com/yuyv"/> <rosparam param="D">[-0.1976212648687889, 0.1688022413942262, 0.0124442419926021, 0.005870906198680583, 0.0]</rosparam> <rosparam param="K">[485.5897704187133, 0.0, 297.2537641560215, 0.0, 491.6813624489518, 296.2003190013238, 0.0, 0.0, 1.0]</rosparam> <rosparam param="R">[1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0]</rosparam> <rosparam param="P">[462.4408874511719, 0.0, 301.47298442859574, 0.0, 0.0, 469.7864074707031, 301.54598383033044, 0.0, 0.0, 0.0, 1.0, 0.0]</rosparam> </node> </launch>
<pre name="code" class="html">$(find usb_cam)/launch/camera.rviz文件
Panels: - Class: rviz/Displays Help Height: 78 Name: Displays Property Tree Widget: Expanded: ~ Splitter Ratio: 0.5 Tree Height: 144 - Class: rviz/Selection Name: Selection - Class: rviz/Tool Properties Expanded: - /2D Pose Estimate1 - /2D Nav Goal1 - /Publish Point1 Name: Tool Properties Splitter Ratio: 0.588679 - Class: rviz/Views Expanded: - /Current View1 Name: Views Splitter Ratio: 0.5 - Class: rviz/Time Experimental: false Name: Time SyncMode: 0 SyncSource: Image Visualization Manager: Class: "" Displays: - Alpha: 0.5 Cell Size: 1 Class: rviz/Grid Color: 160; 160; 164 Enabled: true Line Style: Line Width: 0.03 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 - Class: rviz/Image Enabled: true Image Topic: /usb_cam/image_raw Max Value: 1 Median window: 5 Min Value: 0 Name: Image Normalize Range: true Queue Size: 2 Transport Hint: raw Value: true - Class: rviz/Image Enabled: true Image Topic: /slam/raw_flip_image Max Value: 1 Median window: 5 Min Value: 0 Name: Image Normalize Range: true Queue Size: 2 Transport Hint: raw Value: true - Class: rviz/Image Enabled: true Image Topic: /detect_qr/qr_img Max Value: 1 Median window: 5 Min Value: 0 Name: Image Normalize Range: true Queue Size: 2 Transport Hint: raw Value: true - Class: rviz/Image Enabled: true Image Topic: /slam/qrslam/slam_map Max Value: 1 Median window: 5 Min Value: 0 Name: Image Normalize Range: true Queue Size: 2 Transport Hint: raw Value: true Enabled: true Global Options: Background Color: 48; 48; 48 Fixed Frame: odom 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 Topic: /initialpose - 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: 15.7352 Enable Stereo Rendering: Stereo Eye Separation: 0.06 Stereo Focal Distance: 1 Swap Stereo Eyes: false Value: false Focal Point: X: 0 Y: 0 Z: 0 Name: Current View Near Clip Distance: 0.01 Pitch: 0.825398 Target Frame: <Fixed Frame> Value: Orbit (rviz) Yaw: 1.5604 Saved: ~ Window Geometry: Displays: collapsed: false Height: 718 Hide Left Dock: false Hide Right Dock: false Image: collapsed: false QMainWindow State: 000000ff00000000fd00000004000000000000039d00000247fc0200000009fb0000001200530065006c0065006300740069006f006e00000001e10000009b0000006400fffffffb0000001e0054006f006f006c002000500072006f007000650072007400690065007302000001ed000001df00000185000000a3fb000000120056006900650077007300200054006f006f02000001df000002110000018500000122fb000000200054006f006f006c002000500072006f0070006500720074006900650073003203000002880000011d000002210000017afc000000280000011f000000dd00fffffffa000000010100000002fb0000000a0049006d00610067006502000007ce000001680000073200000279fb000000100044006900730070006c00610079007301000000000000039d0000010f00fffffffb0000002000730065006c0065006300740069006f006e00200062007500660066006500720200000138000000aa0000023a00000294fb00000014005700690064006500530074006500720065006f02000000e6000000d2000003ee0000030bfb0000000c004b0069006e0065006300740200000186000001060000030c00000261fb0000000a0049006d006100670065010000014d000001220000001600ffffff000000010000037600000247fc0200000005fb0000001e0054006f006f006c002000500072006f00700065007200740069006500730100000041000000780000000000000000fb0000000a005600690065007700730100000028000000b0000000b000fffffffb0000000a0049006d00610067006501000000de000000c60000001600fffffffb0000000a0049006d00610067006501000001aa000000c50000001600fffffffb0000001200530065006c0065006300740069006f006e010000025a000000b2000000000000000000000002000004b0000000a9fc0100000001fb0000000a00560069006500770073030000004e00000080000002e100000197000000030000073f0000003bfc0100000002fb0000000800540069006d006501000000000000073f000002f600fffffffb0000000800540069006d00650100000000000004500000000000000000000000200000024700000004000000040000000800000008fc0000000100000002000000010000000a0054006f006f006c00730100000000ffffffff0000000000000000 Selection: collapsed: false Time: collapsed: false Tool Properties: collapsed: false Views: collapsed: false Width: 1855 X: 90 Y: 153
ros下单目相机校正