ROS与javascript入门教程-mjpegcanvasjs-单视频显示

ROS1/一代机器人系统 少儿编程 489浏览 0评论
ROS与JS入门教程

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

您必须 登录 才能发表评论!