ROS与javascript入门教程-mjpegcanvasjs-单视频显示
ROS与javascript入门教程-mjpegcanvasjs-单视频显示
说明:
- 介绍如何通过mjpegcanvasjs显示单视频
步骤:
- 新建Single-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.Viewer({
divID : 'mjpeg',
host : 'localhost',
width : 640,
height : 480,
topic : '/wide_stereo/left/image_color'
});
}
</script>
</head>
<body onload="init()">
<h1>Simple MJPEG Canvas Example</h1>
<div id="mjpeg"></div>
</body>
</html>
代码解析:
- 代码段:
var viewer = new MJPEGCANVAS.Viewer({
divID : 'mjpeg',
host : 'localhost',
width : 640,
height : 480,
topic : '/wide_stereo/left/image_color'
});
- 解释:
- 创建MJPEGCANVAS.Viewer对象,用于放置图片
- 显示/wide_stereo/left/image_color话题内容
运行:
- 需要pr2_simulator and mjpeg_server包
- 服务器,新终端,运行
roslaunch pr2_gazebo pr2_empty_world.launch
- 服务器,新终端,运行
rosrun mjpeg_server mjpeg_server
- 浏览器访问Single-Stream.html
参考:
- http://wiki.ros.org/mjpegcanvasjs/Tutorials/CreatingASingleStreamCanvas
获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号