functionFan2.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977
  1. <template>
  2. <div style="width: 100%; height: calc(100%); background: #fff; display: flex">
  3. <div class="ablockly">
  4. <div id="blocklyDiv"></div>
  5. <xml id="toolbox" style="display: none">
  6. <category name="逻辑" colour="%{BKY_LOGIC_HUE}">
  7. <block type="controls_if"></block>
  8. <block type="logic_compare"></block>
  9. <block type="logic_operation"></block>
  10. <block type="logic_negate"></block>
  11. <block type="logic_boolean"></block>
  12. <block type="logic_number"></block>
  13. </category>
  14. <sep></sep>
  15. <category name="循环" colour="#5ba55b">
  16. <block type="controls_repeat_forever"></block>
  17. <block type="controls_whileUntil"></block>
  18. <block type="controls_for"></block>
  19. </category>
  20. <sep></sep>
  21. <category id="catIOTScreen" name="屏幕" colour="#5cb2d6">
  22. <block type="iot_lcd_screeninit"></block>
  23. </category>
  24. <sep></sep>
  25. <category id="cat" name="人脸识别" colour="#ee783a">
  26. <block type="iot_lcd_faceinit"></block>
  27. </category>
  28. <sep></sep>
  29. <category id="police" name="电子警察组件" colour="#1b5873">
  30. <block type="iot_lcd_policeinit"></block>
  31. </category>
  32. <sep></sep>
  33. <category id="police" name="AI组件" colour="#935ba5">
  34. <block type="ai_gesture"></block>
  35. <block type="ai_motor"></block>
  36. </category>
  37. </xml>
  38. </div>
  39. <div class="container">
  40. <div class="img">
  41. <div class="left" style="width: 120px"></div>
  42. <div class="controlZ">
  43. <div id="fan" ref="fan">
  44. <img :src="img[0]" alt />
  45. </div>
  46. <div id="fanB">
  47. <img :src="img[6]" alt />
  48. </div>
  49. <div id="motor">
  50. <img :src="img[1]" alt />
  51. </div>
  52. <div id="base">
  53. <img :src="img[2]" alt />
  54. </div>
  55. <div id="a4">
  56. <img :src="img[3]" alt />
  57. </div>
  58. <div id="screan">
  59. <img :src="img[4]" alt />
  60. <!--图片展示-->
  61. <video
  62. ref="video"
  63. id="video_cam"
  64. width="178"
  65. height="142.4"
  66. class="face"
  67. autoplay
  68. v-show="isCamera"
  69. ></video>
  70. <canvas
  71. ref="canvasDOM"
  72. width="178"
  73. height="142.4"
  74. class="kuang"
  75. v-show="isCamera"
  76. ></canvas>
  77. </div>
  78. <div id="line">
  79. <img :src="img[5]" alt />
  80. </div>
  81. </div>
  82. <div class="cameraZ">
  83. <!--开启摄像头-->
  84. <div class="cameraBtn">
  85. <div class="open" @click="start()" v-if="!isZuan">
  86. <img src="../assets/img/fan/icon.png" alt />
  87. </div>
  88. <div class="close" @click="closeCamera()" v-else>
  89. <img src="../assets/img/fan/icon2.png" alt />
  90. </div>
  91. </div>
  92. <!--确认-->
  93. <div v-show="false" class="isPhoto">
  94. <!--canvas截取流-->
  95. <canvas
  96. ref="canvas"
  97. width="300"
  98. height="240"
  99. v-show="false"
  100. ></canvas>
  101. </div>
  102. </div>
  103. </div>
  104. </div>
  105. </div>
  106. </template>
  107. <style>
  108. .as {
  109. animation: myfirst 1s linear infinite;
  110. }
  111. .asn {
  112. transform: rotate(0deg);
  113. }
  114. @keyframes myfirst {
  115. 0% {
  116. transform: rotate(0deg);
  117. }
  118. 100% {
  119. transform: rotate(360deg);
  120. }
  121. }
  122. @-webkit-keyframes myfirst /* Safari and Chrome */ {
  123. 0% {
  124. transform: rotate(0deg);
  125. }
  126. 100% {
  127. transform: rotate(360deg);
  128. }
  129. }
  130. .ass {
  131. animation: myfirst 3s linear infinite;
  132. }
  133. </style>
  134. <script>
  135. import * as handPoseDetection from "@tensorflow-models/hand-pose-detection";
  136. import "@tensorflow/tfjs-backend-webgl";
  137. import * as mpHands from "@mediapipe/hands";
  138. // 引入Blockly
  139. import Blockly from "blockly";
  140. // 引入想要转换的语言,语言有php python dart lua javascript
  141. import * as JavaScript from "blockly/javascript";
  142. import * as Blocks from "blockly/blocks";
  143. // 引入语言包并使用
  144. import * as hans from "blockly/msg/zh-hans";
  145. Blockly.setLocale(hans);
  146. //引入媒体文件:我是在github上下载的blockly源码,将源码中的media文件放入我项目中的public文件夹下
  147. //忽略被vue错认为组件的blockly中的标签,不止以下这些,请发现一个忽略一个
  148. import Vue from "vue";
  149. Vue.config.ignoredElements.push("xml");
  150. Vue.config.ignoredElements.push("block");
  151. Vue.config.ignoredElements.push("field");
  152. Vue.config.ignoredElements.push("category");
  153. Vue.config.ignoredElements.push("sep");
  154. Vue.config.ignoredElements.push("value");
  155. Vue.config.ignoredElements.push("statement");
  156. Vue.config.ignoredElements.push("mutation");
  157. export default {
  158. data() {
  159. return {
  160. that: this,
  161. img: [
  162. require("../assets/img/fan/fan.png"),
  163. require("../assets/img/fan/2.png"),
  164. require("../assets/img/fan/3.png"),
  165. require("../assets/img/fan/4.png"),
  166. require("../assets/img/fan/5.png"),
  167. require("../assets/img/fan/6.png"),
  168. require("../assets/img/fan/fanB.png"),
  169. ],
  170. shibieImg: require("../assets/img/face.png"),
  171. isCamera: false,
  172. isZuan: false,
  173. count: 0,
  174. change: 0,
  175. closeUpdateMessage: false,
  176. updateMessage: false,
  177. upName: "",
  178. number: 0,
  179. isdetected: "请您保持脸部在画面中央",
  180. videoEl: {},
  181. canvasEL: {},
  182. formLabelWidth: "100px",
  183. resultImg: {
  184. img: [],
  185. name: "",
  186. },
  187. // 预设样本图,支持本地,网络,beas64
  188. sampleArr: [
  189. // {
  190. // name: "编号1",
  191. // img: []
  192. // }
  193. ],
  194. // 匹配图,支持本地,网络,beas64
  195. detArr: [
  196. //"" 图片1
  197. ],
  198. numberOne: 0,
  199. // 匹配结果
  200. resultArr: [],
  201. // 人脸匹配矩阵数组对象转码结果
  202. faceMatcher: null,
  203. rotate: 0,
  204. timer: null,
  205. detector: null,
  206. hand: 0,
  207. isC: false,
  208. f:null,
  209. };
  210. },
  211. methods: {
  212. cancel() {
  213. this.updateMessage = false;
  214. this.sampleArr[this.sampleArr.length - 1].name = "编号:" + this.number;
  215. if (this.sampleArr.length > 0) {
  216. // var a = document.getElementsByClassName("spot");
  217. // a[0].style.display = "block";
  218. this.fnsample();
  219. }
  220. },
  221. async start() {
  222. this.isZuan = true;
  223. this.isCamera = true;
  224. let video = this.$refs["video"];
  225. var that = this;
  226. if (this.detector == null) {
  227. await this.fnInit();
  228. }
  229. that.f = window.requestAnimationFrame(function () {
  230. window.cancelAnimationFrame(that.f);
  231. setTimeout(function () {
  232. that.handsFind(video);
  233. that.start();
  234. }, 3000);
  235. });
  236. // setInterval(() => {
  237. // this.handsFind(video);
  238. // // window.requestAnimationFrame(this.start);
  239. // }, 1000);
  240. },
  241. zhuan() {
  242. var _fan = this.$refs.fan;
  243. _fan.className = "asn as";
  244. clearInterval(this.timer);
  245. this.timer = setInterval(function () {
  246. _fan.className = "asn";
  247. setTimeout(function () {
  248. _fan.className = "as";
  249. }, 0);
  250. }, 1000);
  251. },
  252. zhuann() {
  253. var _fan = this.$refs.fan;
  254. this.$refs.fan.className = "asn ass";
  255. clearInterval(this.timer);
  256. this.timer = setInterval(function () {
  257. _fan.className = "asn";
  258. setTimeout(function () {
  259. _fan.className = "ass";
  260. }, 0);
  261. }, 3000);
  262. },
  263. update() {
  264. this.change = 1;
  265. this.number = this.number + 1;
  266. if (this.change == 1) {
  267. if (this.sampleArr.length > 0) {
  268. this.sampleArr[this.sampleArr.length - 1].name = this.upName;
  269. this.isdetected = "已识别到" + this.resultImg.name + "的图片";
  270. }
  271. }
  272. if (this.sampleArr.length > 0) {
  273. // var a = document.getElementsByClassName("spot");
  274. // a[0].style.display = "block";
  275. this.fnsample();
  276. }
  277. this.updateMessage = false;
  278. },
  279. async handsFind(video) {
  280. let hands = [];
  281. try {
  282. hands = await this.detector.estimateHands(video, {
  283. flipHorizontal: false,
  284. });
  285. } catch (e) {
  286. console.log(e);
  287. this.detector.dispose();
  288. this.detector = null;
  289. }
  290. console.log(hands);
  291. if (hands.length > 0 && this.isCamera) {
  292. let handsA = hands[0].keypoints;
  293. let _58y = handsA[5].y / handsA[8].y;
  294. let _912y = handsA[9].y / handsA[12].y;
  295. let _1316y = handsA[13].y / handsA[16].y;
  296. let _1720y = handsA[17].y / handsA[20].y;
  297. /*石头剪刀布的转速 */
  298. let buNum = 100;
  299. let sNum = 0;
  300. let jNum = 50;
  301. /**1布2石头3剪刀 */
  302. if (_58y > 1 && _912y > 1 && _1316y > 1 && _1720y > 1) {
  303. console.log("布");
  304. if (this.hand == 1) {
  305. return;
  306. }
  307. this.hand = 1;
  308. // this.zhuan();
  309. this.$refs.fan.className = "as";
  310. } else if (_58y < 1 && _912y < 1 && _1316y < 1 && _1720y < 1) {
  311. console.log("石头");
  312. if (this.hand == 2) {
  313. return;
  314. }
  315. this.hand = 2;
  316. //clearInterval(this.timer);
  317. this.$refs.fan.className = "asn";
  318. } else if (_58y > 1 && _912y > 1 && _1316y < 1 && _1720y < 1) {
  319. console.log("剪刀");
  320. if (this.hand == 3) {
  321. return;
  322. }
  323. this.hand = 3;
  324. this.$refs.fan.className = "ass";
  325. // this.zhuann();
  326. }
  327. }
  328. },
  329. // 调用摄像头
  330. callCamera() {
  331. const loading = this.$loading.service({
  332. background: "rgba(255, 255, 255, 0.7)",
  333. target: document.body,
  334. });
  335. let _this = this;
  336. // H5调用电脑摄像头API
  337. window.navigator.mediaDevices
  338. .getUserMedia({
  339. video: true,
  340. })
  341. .then((success) => {
  342. // 摄像头开启成功
  343. _this.$refs["video"].srcObject = success;
  344. // 实时拍照效果
  345. _this.$refs["video"].play();
  346. loading.close();
  347. })
  348. .catch((error) => {
  349. // console.error("摄像头开启失败,请检查摄像头是否可用!");
  350. _this.isC = false;
  351. _this.$message.error("摄像头开启失败,请检查摄像头是否可用!");
  352. loading.close();
  353. });
  354. },
  355. // 拍照
  356. photograph() {
  357. let ctx = this.$refs["canvas"].getContext("2d");
  358. // 把当前视频帧内容渲染到canvas上
  359. ctx.drawImage(this.$refs["video"], 0, 0, 300, 240);
  360. // 转base64格式、图片格式转换、图片质量压缩
  361. let imgBase64 = this.$refs["canvas"].toDataURL("image/jpeg", 0.7); // 由字节转换为KB 判断大小
  362. let str = imgBase64.replace("data:image/jpeg;base64,", "");
  363. let strLength = str.length;
  364. let fileLength = parseInt(strLength - (strLength / 8) * 2); // 图片尺寸 用于判断
  365. let size = (fileLength / 1024).toFixed(2);
  366. console.log(size); // 上传拍照信息 调用接口上传图片 .........
  367. // this.detArr.push(imgBase64);
  368. var json = { name: "", img: [] };
  369. this.number = this.number + 1;
  370. this.upName = "";
  371. json.img.push(imgBase64);
  372. this.sampleArr.push(json);
  373. this.updateMessage = true;
  374. },
  375. // 关闭摄像头
  376. closeCamera() {
  377. // if (!this.$refs["video"].srcObject) {
  378. // this.isCamera = false;
  379. // return;
  380. // }
  381. // let stream = this.$refs["video"].srcObject;
  382. // let tracks = stream.getTracks();
  383. // tracks.forEach((track) => {
  384. // track.stop();
  385. // });
  386. // this.$refs["video"].srcObject = null;
  387. this.isCamera = false;
  388. window.cancelAnimationFrame(this.f);
  389. this.isZuan = false;
  390. clearInterval(this.timer);
  391. this.$refs.fan.className = "asn";
  392. this.timer = null;
  393. this.hand = 0;
  394. },
  395. async fnInit() {
  396. const model = handPoseDetection.SupportedModels.MediaPipeHands;
  397. const detectorConfig = {
  398. runtime: "mediapipe", // or 'tfjs'
  399. modelType: "full",
  400. // solutionPath: `https://cdn.jsdelivr.net/npm/@mediapipe/hands@${mpHands.VERSION}`,
  401. solutionPath: `/static/hands`,
  402. };
  403. this.detector = await handPoseDetection.createDetector(
  404. model,
  405. detectorConfig
  406. );
  407. },
  408. async fnsample() {
  409. const labeledFaceDescriptors = await Promise.all(
  410. this.sampleArr.map(async (item) => {
  411. // 临时图片转码数据,将图片对象转数据矩阵对象
  412. let descriptors = [];
  413. for (let image of item.img) {
  414. const imageEl = await faceapi.fetchImage(image);
  415. descriptors.push(await faceapi.computeFaceDescriptor(imageEl));
  416. }
  417. // 返回图片用户和图片转码数组
  418. return new faceapi.LabeledFaceDescriptors(item.name, descriptors);
  419. })
  420. );
  421. // 人脸匹配矩阵数组对象转码结果
  422. this.faceMatcher = new faceapi.FaceMatcher(labeledFaceDescriptors);
  423. },
  424. // 执行遍历识别匹配图片,数值误差越小越精确
  425. fnRun() {
  426. let ctx = this.$refs["canvas"].getContext("2d");
  427. // 把当前视频帧内容渲染到canvas上
  428. ctx.drawImage(this.$refs["video"], 0, 0, 300, 240);
  429. // 转base64格式、图片格式转换、图片质量压缩
  430. let imgBase64 = this.$refs["canvas"].toDataURL("image/jpeg", 0.7); // 由字节转换为KB 判断大小
  431. this.detArr = [];
  432. this.detArr.push(imgBase64);
  433. this.detArr.forEach(async (img) => {
  434. let ts = Date.now();
  435. // 将图片对象转数据矩阵对象,进行匹配
  436. const inputEl = await faceapi.fetchImage(img);
  437. const inputDescriptor = await faceapi.computeFaceDescriptor(inputEl);
  438. const bestMatch = await this.faceMatcher.findBestMatch(inputDescriptor);
  439. // 结果
  440. this.resultArr = [];
  441. this.resultArr.push({
  442. target: img,
  443. result: bestMatch.toString(),
  444. time: Date.now() - ts + "ms",
  445. fps: Math.round(1000 / (Date.now() - ts)),
  446. });
  447. console.log(this.resultArr);
  448. var a = document.getElementsByClassName("pFace");
  449. for (var i = 0; i < this.sampleArr.length; i++) {
  450. if (this.sampleArr[i].name == bestMatch.label) {
  451. // this.closeUpdateMessage = true;
  452. // if (this.change == 1) {
  453. // this.resultImg.name = this.upName;
  454. // } else {
  455. // this.resultImg.name = this.sampleArr[i].name;
  456. // }
  457. this.isdetected = "已识别到" + this.sampleArr[i].name + "的图片";
  458. this.shibieImg = this.sampleArr[i].img[0];
  459. if (this.shibieImg.length > 0) {
  460. a[0].style.width = "300px";
  461. }
  462. this.resultImg.img[0] = this.sampleArr[i].img[0];
  463. }
  464. }
  465. });
  466. },
  467. handleClose(done) {
  468. done();
  469. },
  470. // 更换匹配图
  471. async fnChange(e) {
  472. if (!e.target.files.length) return;
  473. this.detArr = [];
  474. this.resultArr = [];
  475. // 将文件显示为图像并识别
  476. e.target.files.forEach(async (file) => {
  477. let ts = Date.now();
  478. let img = await faceapi.bufferToImage(file);
  479. const inputDescriptor = await faceapi.computeFaceDescriptor(img);
  480. const bestMatch = await this.faceMatcher.findBestMatch(inputDescriptor);
  481. // 结果
  482. this.detArr.push(img.src);
  483. this.resultArr.push({
  484. target: file.name,
  485. result: bestMatch.toString(),
  486. time: Date.now() - ts + "ms",
  487. fps: Math.round(1000 / (Date.now() - ts)),
  488. });
  489. });
  490. },
  491. blocklyInit() {
  492. this.workspace = Blockly.inject("blocklyDiv", {
  493. //工具栏
  494. toolbox: document.getElementById("toolbox"),
  495. //网格效果
  496. grid: { spacing: 20, length: 3, colour: "#ccc", snap: true },
  497. //媒体资源
  498. media: "../assets/img/",
  499. //垃圾桶
  500. trashcan: true,
  501. });
  502. //工作区监听代码生成器
  503. this.workspace.addChangeListener(this.myUpdateFunction);
  504. Blockly.Blocks["iot_lcd_screeninit"] = {
  505. init: function () {
  506. this.appendDummyInput().appendField(
  507. new Blockly.FieldImage(
  508. require("../assets/img/screen_init_header.png"),
  509. 45,
  510. 45
  511. )
  512. );
  513. this.appendDummyInput().appendField("LCD屏幕打开");
  514. this.setInputsInline(false);
  515. this.setPreviousStatement(true);
  516. this.setNextStatement(true);
  517. this.setColour("#5cb2d6");
  518. this.setTooltip("");
  519. this.setHelpUrl("");
  520. },
  521. };
  522. Blockly.JavaScript.iot_lcd_screeninit = function (block) {
  523. var _code = "screen=1;";
  524. return _code;
  525. };
  526. Blockly.Blocks["iot_lcd_faceinit"] = {
  527. init: function () {
  528. this.appendDummyInput().appendField(
  529. new Blockly.FieldImage(
  530. require("../assets/img/face_recognition_header.png"),
  531. 45,
  532. 45
  533. )
  534. );
  535. this.appendDummyInput().appendField("人脸辨识");
  536. this.setInputsInline(false);
  537. this.setPreviousStatement(true);
  538. this.setNextStatement(true);
  539. this.setColour("#ee783a");
  540. this.setTooltip("");
  541. this.setHelpUrl("");
  542. },
  543. };
  544. Blockly.JavaScript.iot_lcd_faceinit = function (block) {
  545. var _code = "face=1;";
  546. return _code;
  547. };
  548. Blockly.Blocks["iot_lcd_policeinit"] = {
  549. init: function () {
  550. this.appendDummyInput().appendField(
  551. new Blockly.FieldImage(
  552. require("../assets/img/screen_init_header.png"),
  553. 45,
  554. 45
  555. )
  556. );
  557. this.appendDummyInput().appendField("电子警察组件");
  558. this.setInputsInline(false);
  559. this.setPreviousStatement(true);
  560. this.setNextStatement(true);
  561. this.setColour("#1b5873");
  562. this.setTooltip("");
  563. this.setHelpUrl("");
  564. },
  565. };
  566. Blockly.JavaScript.iot_lcd_policeinit = function (block) {
  567. var _code = "police=1;";
  568. return _code;
  569. };
  570. Blockly.Blocks["logic_loop"] = {
  571. init: function () {
  572. this.appendStatementInput("NAME")
  573. .setCheck(null)
  574. .appendField("重复执行");
  575. this.setPreviousStatement(true, null);
  576. this.setNextStatement(true, null);
  577. this.setColour("#5b80a5");
  578. this.setTooltip("");
  579. this.setHelpUrl("");
  580. },
  581. };
  582. Blockly.JavaScript["logic_loop"] = function (block) {
  583. var statements_name = Blockly.JavaScript.statementToCode(block, "NAME");
  584. // TODO: Assemble JavaScript into code variable.
  585. var code = "for;\n";
  586. return code;
  587. };
  588. Blockly.Blocks.controls_repeat_forever = {
  589. init: function () {
  590. this.jsonInit({
  591. message0: Blockly.Msg.CONTROLS_REPEAT_FOREVER,
  592. previousStatement: null,
  593. nextStatement: null,
  594. colour: "#5ba55b",
  595. tooltip: Blockly.Msg.CONTROLS_REPEAT_FOREVER_TOOLTIP,
  596. helpUrl: Blockly.Msg.CONTROLS_REPEAT_HELPURL,
  597. });
  598. this.appendStatementInput("DO").appendField(
  599. Blockly.Msg.CONTROLS_REPEAT_INPUT_DO
  600. );
  601. },
  602. };
  603. Blockly.JavaScript.controls_repeat_forever = function (a) {
  604. var d = Blockly.JavaScript.statementToCode(a, "DO");
  605. d = Blockly.JavaScript.addLoopTrap(d, a);
  606. return "while (true) {\n" + d + "}\n";
  607. };
  608. Blockly.Blocks["logic_number"] = {
  609. init: function () {
  610. this.appendDummyInput().appendField(
  611. new Blockly.FieldTextInput("0"),
  612. "number"
  613. );
  614. this.setInputsInline(true);
  615. this.setOutput(true, "Number");
  616. this.setColour("#5b80a5");
  617. this.setTooltip("");
  618. this.setHelpUrl("");
  619. },
  620. };
  621. Blockly.JavaScript["logic_number"] = function (block) {
  622. var text_number = block.getFieldValue("number");
  623. // TODO: Assemble JavaScript into code variable.
  624. var code = text_number;
  625. // TODO: Change ORDER_NONE to the correct strength.
  626. return [code, Blockly.JavaScript.ORDER_NONE];
  627. };
  628. Blockly.Blocks["ai_gesture"] = {
  629. init: function () {
  630. this.appendDummyInput()
  631. .appendField("AI手势识别")
  632. .appendField(new Blockly.FieldDropdown([["ID", "ID"]]), "ID");
  633. this.setInputsInline(true);
  634. this.setOutput(true, null);
  635. this.setColour(285);
  636. this.setTooltip("");
  637. this.setHelpUrl("");
  638. },
  639. };
  640. Blockly.JavaScript["ai_gesture"] = function (block) {
  641. var dropdown_id = block.getFieldValue("ID");
  642. // TODO: Assemble JavaScript into code variable.
  643. var code = "hands";
  644. // TODO: Change ORDER_NONE to the correct strength.
  645. return [code, Blockly.JavaScript.ORDER_NONE];
  646. };
  647. Blockly.Blocks["ai_motor"] = {
  648. init: function () {
  649. this.appendDummyInput()
  650. .appendField("马达")
  651. .appendField(new Blockly.FieldDropdown([["M1", "M1"]]), "motor")
  652. .appendField("以速度")
  653. .appendField(new Blockly.FieldTextInput("0"), "speed")
  654. .appendField("转动");
  655. this.setPreviousStatement(true, null);
  656. this.setNextStatement(true, null);
  657. this.setColour(285);
  658. this.setTooltip("");
  659. this.setHelpUrl("");
  660. },
  661. };
  662. Blockly.JavaScript["ai_motor"] = function (block) {
  663. var dropdown_motor = block.getFieldValue("motor");
  664. var text_speed = block.getFieldValue("speed");
  665. // TODO: Assemble JavaScript into code variable.
  666. var code = "motor=" + text_speed;
  667. // TODO: Change ORDER_NONE to the correct strength.
  668. return code;
  669. };
  670. },
  671. },
  672. mounted() {
  673. this.blocklyInit();
  674. this.fnInit();
  675. this.callCamera();
  676. this.videoEl = this.$refs.video;
  677. this.canvasEL = this.$refs.canvasDOM;
  678. },
  679. };
  680. </script>
  681. <style scoped>
  682. html,
  683. body {
  684. margin: 0;
  685. padding: 0;
  686. width: 100%;
  687. }
  688. .dialog_diy >>> .el-form-item__label {
  689. width: 50px !important;
  690. margin-left: 35px !important;
  691. }
  692. .dialog_diy >>> .el-form-item__content {
  693. margin-left: 0 !important;
  694. }
  695. .update {
  696. margin-left: 20%;
  697. font-size: 16px !important;
  698. }
  699. .tip {
  700. margin: 25px 0 30px 20px;
  701. }
  702. #fan > img,
  703. #fanB > img,
  704. #motor > img,
  705. #base > img,
  706. #line > img,
  707. .right > img,
  708. #a4 > img,
  709. #screan > img {
  710. width: 100%;
  711. height: 100%;
  712. user-select: none;
  713. }
  714. .img {
  715. display: flex;
  716. flex-direction: row;
  717. justify-content: flex-start;
  718. justify-content: center;
  719. width: 100%;
  720. height: 500px;
  721. position: relative;
  722. }
  723. #fan {
  724. width: 425px;
  725. position: absolute;
  726. z-index: 5;
  727. left: 150px;
  728. top: 0;
  729. transition: all 0.5s;
  730. transform: rotate(0deg);
  731. }
  732. #fanB {
  733. width: 116.6px;
  734. position: absolute;
  735. z-index: 4;
  736. left: 300px;
  737. top: 155px;
  738. }
  739. #base {
  740. width: 423.33px;
  741. position: absolute;
  742. z-index: 4;
  743. top: 295px;
  744. left: 0;
  745. }
  746. #motor {
  747. width: 134.16px;
  748. position: absolute;
  749. z-index: 3;
  750. left: 292px;
  751. top: 175px;
  752. }
  753. #a4 {
  754. width: 210px;
  755. position: absolute;
  756. z-index: 5;
  757. top: 517px;
  758. left: 111px;
  759. }
  760. #screan {
  761. width: 178.33px;
  762. position: absolute;
  763. left: -19px;
  764. top: 126px;
  765. }
  766. #line {
  767. width: 470.83px;
  768. position: absolute;
  769. z-index: 2;
  770. top: 245px;
  771. left: -113px;
  772. }
  773. .button {
  774. color: #fff;
  775. background: #8ca1de;
  776. width: 550px;
  777. height: 55px;
  778. font-size: 20px;
  779. text-align: center;
  780. line-height: 55px;
  781. position: absolute;
  782. bottom: 10%;
  783. left: 50%;
  784. transform: translateX(-50%);
  785. user-select: none;
  786. }
  787. .right {
  788. width: 40px;
  789. position: absolute;
  790. left: 55%;
  791. top: 70%;
  792. display: none;
  793. }
  794. .dark {
  795. background: #5b79d0;
  796. cursor: pointer;
  797. }
  798. .controlZ {
  799. width: 560px;
  800. height: 620px;
  801. /* margin-left: calc(50% - (490px / 2)); */
  802. position: relative;
  803. }
  804. .cameraZ {
  805. display: flex;
  806. height: 340px;
  807. flex-direction: column;
  808. flex-wrap: nowrap;
  809. width: 300px;
  810. }
  811. .cameraBtn {
  812. display: flex;
  813. flex-direction: column;
  814. align-items: center;
  815. }
  816. .cameraBtn button {
  817. margin: 0 0 10px 0;
  818. }
  819. .face {
  820. position: absolute;
  821. z-index: 9999;
  822. padding: 5px 0px;
  823. left: 0;
  824. top: 37px;
  825. }
  826. .kuang {
  827. position: absolute;
  828. z-index: 10000;
  829. padding: 26.5px 0;
  830. left: 0;
  831. top: 37px;
  832. }
  833. .pFace {
  834. /* width: 300px; */
  835. /* height: 240px; */
  836. width: 150px;
  837. margin: 0 auto;
  838. margin-top: 220px;
  839. }
  840. .close > img,
  841. .save > img,
  842. .pFace > img,
  843. .open > img,
  844. .spotPhoto > img {
  845. width: 100%;
  846. height: 100%;
  847. cursor: pointer;
  848. }
  849. .cameraBtn {
  850. margin-top: 80px;
  851. }
  852. .close {
  853. margin-bottom: 25px;
  854. }
  855. .isPhoto {
  856. height: 410px;
  857. padding: 80px 0 0 0;
  858. box-sizing: border-box;
  859. background: #fff;
  860. }
  861. .isPhoto > span {
  862. font-size: 25px;
  863. color: #ccc;
  864. margin-left: 10px;
  865. }
  866. .nav {
  867. text-align: center;
  868. font-size: 32px;
  869. color: #ccc;
  870. }
  871. .spot {
  872. background: #64ff64;
  873. color: #fff;
  874. width: 140px;
  875. height: 40px;
  876. text-align: center;
  877. line-height: 40px;
  878. border-radius: 20px;
  879. margin-top: 25px;
  880. cursor: pointer;
  881. display: none;
  882. }
  883. .spotNumber {
  884. text-align: center;
  885. margin: 0 auto;
  886. font-size: 20px;
  887. color: #8c8c8c;
  888. }
  889. .spotPhoto {
  890. width: 300px;
  891. height: 245px;
  892. }
  893. .spotPhoto {
  894. margin-top: 20px;
  895. font-size: 20px;
  896. }
  897. .gdt {
  898. display: flex;
  899. flex-direction: column;
  900. }
  901. .ablockly,
  902. #blocklyDiv {
  903. height: 100%;
  904. width: 100%;
  905. }
  906. .blocklySvg {
  907. height: 905px !important;
  908. }
  909. .ablockly {
  910. position: relative;
  911. }
  912. .container {
  913. width: 50%;
  914. height: 100%;
  915. min-width: 960px;
  916. }
  917. </style>