草莓干 发表于 2020-12-10 16:21:12

在 Scratch 中玩转机器人:Python、Deep Learning、Posenet and Robot!

本帖最后由 草莓干 于 2020-12-10 16:21 编辑 <br /><br /><p style="margin-bottom: 10px; text-align: center;"><strong><span style="font-family: 微软雅黑, Microsoft YaHei;">开场视频:先打个响指(打响指控制机器人)</span></strong><br/></p><p>https://v.qq.com/txp/iframe/player.html?vid=g0874rc7rwx <br/></p><p><br/></p><p><br/></p><section style="margin: 20px 5px 5px;padding: 5px; border: 2px solid #f05454; border-radius: 4px;"><section style="display:flex;justify-content: center;"><section style="margin-top: -20px; padding: 0 25px;background-color:rgb(254, 254, 254); "><p class="title active" style="color:#f05454; font-size:18px;min-width:1em;">Codelab-Scratch3 与 Python</p></section></section><section style="padding: 20px;"><p style="line-height: 1.75em; margin-bottom: 10px;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">Scratch 是一门编程语言,上榜过编程语言 Top 20,实际它是一门<strong><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px; color: rgb(0, 112, 192);">少儿编程语言</span></strong>(如果你成年了请先不要急着走)。Scratch 基于图形化的编程,通过拖拉搭积木的方式进行编程,整个过程就像是在玩乐高积木,其实 Scratch 项目受到乐高的赞助,乐高与 Scratch 之间可以说是互相影响。</span></p><p style="line-height: 1.75em; margin-bottom: 10px;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">一个正经的程序员,在看到 Scratch 的卡通界面和图形化编程风格时,可能会嗤之以鼻,认为它看上去<strong><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px; color: rgb(0, 112, 192);">不像是严肃的编程语言,低龄化或者太简单了</span></strong>。刚开始我对 Scratch 的认知亦是如此。</span></p><p style="line-height: 1.75em; margin-bottom: 10px;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">@wwj718 在 Scratch3 上做了大量出色的工作,Scratch3 原本不支持运行 Python,利用 Scratch3 原生的插件拓展机制,采用 Websocket 来传递消息,这就像一个间谍,负责 Scratch 内部与外部的通信。消息源源不断地以话题/订阅的方式在网络中传播,这就让 Scratch 不再受限于浏览器网页中。我终于意识到,Scratch 可以做任何事!</span></p><p style="line-height: 1.75em; margin-bottom: 10px; text-align: center;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;"></span></p><p style="line-height: 1.75em; margin-bottom: 10px;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;"></span></p><p style="line-height: 1.75em;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">从上图看出,整个系统可以看做是三个部分:</span></p><p style="line-height: 1.75em; margin-top: 5px; margin-bottom: 5px;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">· Scratch3:负责 Block 代码生成与运行,通过 websocket 传输消息;</span></p><p style="line-height: 1.75em; margin-top: 5px; margin-bottom: 5px;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">· Codelab-Adapter:响应 Scratch 消息,Python 插件管理;</span></p><p style="line-height: 1.75em; margin-top: 5px; margin-bottom: 5px;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">· Python 插件集合:负责连接万物!</span></p><p style="line-height: 1.75em; margin-top: 10px;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">按照这样的设计,Scratch 获得了 Python 的能力,可以将 Python 丰富的生态和库统统接入 Scratch,比如 TensorFlow、ML、DL,甚至可以是树莓派、灯泡、门锁、空调、机器人、游戏 ...</span></p><p style="line-height: 1.75em; margin-top: 10px;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;"></span></p><section style="width: 100%;" data-width="100%"><section style="width: 100%;border-left: dashed 2px #534a47;background:#f5f5f5;box-sizing: border-box;" data-width="100%"><section class="135brush" style="font-size: 14px;text-align: justify;letter-spacing: 1.5px;line-height: 1.75em;color: rgb(63,62,63);padding:0.5em 0.5em;">理解并预测量化世界的能力不应该只属于那些能够熟练运用抽象数学符号的人。</section><section class="135brush" data-brushtype="text" style="font-size: 14px;text-align: right;letter-spacing: 1.5px;line-height: 1.75em;color: rgb(63,62,63);padding: 0em 0.8em 1em 0.8em;">——Bret Victor 《Kill Math》</section></section><section style="display: flex;justify-content: flex-end;margin-top: -20px;"><section style="width: 0;height: 0;border-bottom:20px solid rgb(255,255,255);border-left:20px solid transparent;"></section></section></section><p style="line-height: 1.75em; margin-top: 10px; margin-bottom: 5px;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">而现在编程的能力也不应该只掌握在程序员的手上,不是所有人都要去学编程,在 Codelab-Scratch 中,用户可以快速和轻松地使用这些能力。</span></p><p style="line-height: 1.75em; margin-top: 10px;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">为了向你证明这一切,下面是我在 Scratch3 中做的一个演示。</span></p></section></section><p><br/></p><section style="margin: 20px 5px 5px;padding: 5px; border: 2px solid #f05454; border-radius: 4px;"><section style="display:flex;justify-content: center;"><section style="margin-top: -20px; padding: 0 25px;background-color:rgb(254, 254, 254); "><p class="title active" style="color:#f05454; font-size:18px;min-width:1em;">人体姿态估计:Posenet</p></section></section><section style="padding: 20px;"><p style="line-height: 1.75em;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">Javascript 版 PoseNet 是 TensorFlow 与谷歌创意实验室合作一款机器学习模型,可以在浏览器中实时估计人体姿态。只要电脑或手机有摄像头,就可以直接在网页浏览器中体验这一有趣的技术。Scratch3 也是纯网页端的,所以将 PoseNet 做成插件的话,Scratch 积木块就具有视觉的能力!</span></p><p style="line-height: 1.75em; text-align: center;"></p><p style="line-height: 1.75em;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">对PoseNet,@wwj718 已经在 Codelab-Scratch3 中接入了,智能硬件接口开放的话,接入 Scratch 中,就可以让原本功能单一的产品很容易地获得视觉能力。我相信这就是为我今天的演示所准备的,做一个 Scratch 版本的机甲猎人!</span></p><p style="line-height: 1.75em; text-align: center;"></p><p style="line-height: 1.75em;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;"><br/></span></p><p style="line-height: 1.75em; text-align: center;"><strong><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">接入机器人到 Scratch3</span></strong></p><p style="line-height: 1.75em;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">首先硬件设备需要有开放的接口,比如开放的蓝牙协议、串口协议或者 Wi-Fi 协议等,Python 有非常成熟的库可以对这些接口进行调用(不开放也没关系,可以 Hack)。</span></p><p style="line-height: 1.75em; margin-top: 10px;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">我已提交 Aelos 机器人 Adapter 插件,感兴趣的可以参考我的 PR</span></p><p style="line-height: 1.75em;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">·codelab_adapter_extensions/pull/13</span></p><p style="line-height: 1.75em;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">·codelab_adapter_extensions/pull/14</span></p></section></section><p><br/></p><section style="margin: 20px 5px 5px;padding: 5px; border: 2px solid #f05454; border-radius: 4px;"><section style="display:flex;justify-content: center;"><section style="margin-top: -20px; padding: 0 25px;background-color:rgb(254, 254, 254); "><p class="title active" style="color:#f05454; font-size:18px;min-width:1em;">手势控制演示</p></section></section><section style="padding: 20px;"><p style="color: rgb(121, 121, 121); font-size: 14px; min-width: 1em; text-align: center; margin-bottom: 10px;"><span style="font-family: 微软雅黑, Microsoft YaHei; color: rgb(0, 0, 0);">手势控制机器人前后左右翻滚</span></p><p class="brush" style="color: rgb(121, 121, 121); font-size: 14px; min-width: 1em; text-align: center;"><span style="font-family: 微软雅黑, Microsoft YaHei; color: rgb(0, 0, 0);"></span></p><p class="brush" style="color: rgb(121,121,121); font-size: 14px;min-width:1em;"><span style="font-family: 微软雅黑, Microsoft YaHei; color: rgb(0, 0, 0);"><br/></span></p><p style="color: rgb(121, 121, 121); font-size: 14px; min-width: 1em; text-align: center; margin-bottom: 10px;"><span style="font-family: 微软雅黑, Microsoft YaHei; color: rgb(0, 0, 0);">翻跟斗演示视频</span></p><p class="brush" style="color: rgb(121, 121, 121); font-size: 14px; min-width: 1em;"><span style="font-family: 微软雅黑, Microsoft YaHei; color: rgb(0, 0, 0);">https://v.qq.com/txp/iframe/player.html?vid=q087453zq2i <br/></span></p></section></section><p><br/></p><section style="margin: 20px 5px 5px;padding: 5px; border: 2px solid #f05454; border-radius: 4px;"><section style="display:flex;justify-content: center;"><section style="margin-top: -20px; padding: 0 25px;background-color:rgb(254, 254, 254); "><p class="title active" style="color:#f05454; font-size:18px;min-width:1em;">姿态模仿演示</p></section></section><section style="padding: 20px;"><p class="brush" style="color: rgb(121, 121, 121); font-size: 14px; min-width: 1em; text-align: center;"></p><p style="line-height: 1.75em; text-align: center;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">下面是姿态模仿演示,请大家忽略我羞耻又沙雕的动作,和不协调的肢体</span></p><p style="line-height: 1.75em; text-align: center;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">姿态模仿演示视频</span></p><p class="brush" style="color: rgb(121,121,121); font-size: 14px;min-width:1em;">https://v.qq.com/txp/iframe/player.html?vid=k0874r1m246 <br/></p></section></section><p><br/></p><p><strong><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">文章来源:</span></strong><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">乐聚机器人 王松博士</span></p><section style="border: 0px none; margin-top: 0.5em; margin-bottom: 0.5em; overflow: hidden; padding: 0px;margin-top:20px;" class="WcnEditor"><section style="width: 0px; height: 0px; clear: both;"></section></section><p style="line-height: 1.75em;"><strong><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">相关链接</span></strong></p><p style="line-height: normal;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">Kill-Math</span></p><p style="line-height: normal;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">Aelos Edu Robot</span></p><p style="line-height: normal;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">scratch3.codelab.club</span></p><p style="line-height: normal;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">codelab-adapter-docs.codelab.club</span></p><p style="line-height: normal;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">Pose Detection in the Browser</span></p><p style="line-height: normal;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">codelab_adapter_extensions/pull/13</span></p><p style="line-height: normal;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">codelab_adapter_extensions/pull/14</span></p><p style="line-height: 1.75em;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">&nbsp;</span></p><p style="line-height: 1.75em;"><strong><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">鸣谢</span></strong></p><p style="line-height: normal;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">@jinbo 的 OSMO;</span></p><p style="line-height: normal;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">@yucong 的手抖式拍摄;</span></p><p style="line-height: normal;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">@jianhong 的专业动作调试;</span></p><p style="line-height: normal;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">@dongming 的无线 Dongle;</span></p><p style="line-height: normal;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">@carlos 的响指(我打不响,囧);</span></p><p><br/></p><p><br/></p><link rel="stylesheet" href="//bbs.lejurobot.com/source/plugin/wcn_editor/public/wcn_editor_fit.css?v134_kKx" id="wcn_editor_css"/>
页: [1]
查看完整版本: 在 Scratch 中玩转机器人:Python、Deep Learning、Posenet and Robot!