ROS与javascript入门教程-mjpegcanvasjs-多视频显示
ROS与javascript入门教程-mjpegcanvasjs-多视频显示
说明:
- 介绍如何通过mjpegcanvasjs实现多视频显示
步骤:
- 新建Multi-Stream.html
- 代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script type="text/javascript" src="http://cdn.robotwebtools.org/EventEmitter2/current/eventemitter2.min.js"></script>
<script type="text/javascript" src="http://cdn.robotwebtools.org/mjpegcanvasjs/current/mjpegcanvas.min.js"></script>
<script type="text/javascript" type="text/javascript">
/**
* Setup all visualization elements when the page is loaded.
*/
function init() {
// Create the main viewer.
var viewer = new MJPEGCANVAS.MultiStreamViewer({
divID : 'mjpeg',
host : 'localhost',
width : 640,
height : 480,
topics : [ '/wide_stereo/left/image_color', '/l_forearm_cam/image_color', '/r_forearm_cam/image_color' ],
labels : [ 'Robot View', 'Left Arm View', 'Right Arm View' ]
});
}
</script>
</head>
<body onload="init()">
<h1>Multi-Stream MJPEG Canvas Example</h1>
<div id="mjpeg"></div>
</body>
</html>
代码解析:
- 代码段:
var viewer = new MJPEGCANVAS.MultiStreamViewer({
divID : 'mjpeg',
host : 'localhost',
width : 640,
height : 480,
topics : [ '/wide_stereo/left/image_color', '/l_forearm_cam/image_color', '/r_forearm_cam/image_color' ],
labels : [ 'Robot View', 'Left Arm View', 'Right Arm View' ]
});
- 解释:
- 创建MJPEGCANVAS.MultiStreamViewer对象,用于显示多个图像话题
- 分别显示 /wide_stereo/left/image_color和/l_forearm_cam/image_color和/r_forearm_cam/image_color
运行:
需要 pr2_simulator 和mjpeg_server包
服务器,新终端,运行
roslaunch pr2_gazebo pr2_empty_world.launch
- 服务器,新终端,运行
rosrun mjpeg_server mjpeg_server
- 浏览器访问Multi-Stream.html
参考:
- http://wiki.ros.org/mjpegcanvasjs/Tutorials/CreatingAMultiStreamCanvas
获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号