visionkit.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. /**
  2. * @license
  3. * Visual Blocks Editor
  4. *
  5. * Copyright 2012 Google Inc.
  6. * https://developers.google.com/blockly/
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. */
  20. /**
  21. * @fileoverview Colour blocks for Blockly.
  22. * @author fraser@google.com (Neil Fraser)
  23. */
  24. 'use strict';
  25. goog.provide('Blockly.Blocks.visionkit');
  26. goog.require('Blockly.Blocks');
  27. /**
  28. * Common HSV hue for all blocks in this category.
  29. */
  30. Blockly.Blocks.visionkit.HUE = "#2c4fc9";
  31. Blockly.Blocks['visionkit_setup'] = {
  32. /**
  33. * Block for log setup.
  34. * @this Blockly.Block
  35. */
  36. init: function() {
  37. this.setColour(Blockly.Blocks.visionkit.HUE);
  38. this.appendDummyInput()
  39. // .appendField(new Blockly.FieldImage("./../blockly/media/google_aiy_vision_kit_setup_header.png", 140, 60, "0"));
  40. .appendField(new Blockly.FieldImage("./blockly/media/google_aiy_vision_kit_setup.png", 140, 60, "0"));//staging
  41. this.appendDummyInput()
  42. .appendField(Blockly.Msg.VISIONKIT_SETUP);
  43. // this.setInputsInline(false);
  44. // this.setOutput(true);
  45. // this.setPreviousStatement(true);
  46. // this.setNextStatement(true);
  47. },
  48. };
  49. Blockly.Blocks['visionkit_demo'] = {
  50. /**
  51. * Block for log setup.
  52. * @this Blockly.Block
  53. */
  54. init: function() {
  55. this.setColour(Blockly.Blocks.visionkit.HUE);
  56. this.appendDummyInput()
  57. // .appendField(new Blockly.FieldImage("./../blockly/media/google_aiy_vision_kit_setup_header.png", 140, 60, "0"));
  58. .appendField(new Blockly.FieldImage("./blockly/media/google_aiy_vision_joy_demo.png", 140, 60, "0"));//staging
  59. this.appendDummyInput()
  60. .appendField(Blockly.Msg.VISIONKIT_JOY_DETECT);
  61. this.appendDummyInput()
  62. .appendField(Blockly.Msg.VISIONKIT_CLOUDEVENT_API)
  63. .appendField(new Blockly.FieldTextInput("yourCloudEventAPI"),"API")
  64. // this.setInputsInline(false);
  65. // this.setOutput(true);
  66. // this.setPreviousStatement(true);
  67. // this.setNextStatement(true);
  68. },
  69. };
  70. /*
  71. * vision kit
  72. * import block from
  73. */
  74. Blockly.Blocks['visionkit_import'] = {
  75. /**
  76. * Block for import.
  77. * @this Blockly.Block
  78. */
  79. init: function() {
  80. this.setColour(Blockly.Blocks.visionkit.HUE);
  81. this.appendValueInput("IMPORT")
  82. .appendField(Blockly.Msg.VISIONKIT_IMPORT)
  83. .appendField(new Blockly.FieldDropdown([
  84. ["AIY.Vision.Inference","aiy.vision.inference"],
  85. ["AIY.Vision.Models","aiy.vision.models"],
  86. ["AIY.Vision.Annotator","aiy.vision.annotator"]
  87. ]), "FROM")
  88. // this.setInputsInline(false);
  89. // this.setOutput(true);
  90. this.setPreviousStatement(true);
  91. this.setNextStatement(true);
  92. },
  93. };
  94. /*
  95. * vision kit
  96. * import block annotator
  97. */
  98. Blockly.Blocks['visionkit_import_annotator'] = {
  99. /**
  100. * Block for import.
  101. * @this Blockly.Block
  102. */
  103. init: function() {
  104. this.setColour(Blockly.Blocks.visionkit.HUE);
  105. this.appendDummyInput()
  106. .appendField(Blockly.Msg.VISIONKIT_IMPORT_ANNOTATOR)
  107. .appendField(new Blockly.FieldDropdown([
  108. ["Annotator","Annotator"]
  109. ]), "IMPORT")
  110. // this.setInputsInline(false);
  111. this.setOutput(true);
  112. // this.setPreviousStatement(true);
  113. // this.setNextStatement(true);
  114. },
  115. };
  116. /*
  117. * vision kit
  118. * import block models
  119. */
  120. Blockly.Blocks['visionkit_import_models'] = {
  121. /**
  122. * Block for import.
  123. * @this Blockly.Block
  124. */
  125. init: function() {
  126. this.setColour(Blockly.Blocks.visionkit.HUE);
  127. this.appendDummyInput()
  128. .appendField(Blockly.Msg.VISIONKIT_IMPORT_MODELS)
  129. .appendField(new Blockly.FieldDropdown([
  130. ["Face Detection","face_detection"]
  131. ]), "IMPORT")
  132. // this.setInputsInline(false);
  133. this.setOutput(true);
  134. // this.setPreviousStatement(true);
  135. // this.setNextStatement(true);
  136. },
  137. };
  138. /*
  139. * vision kit
  140. * import block inference
  141. */
  142. Blockly.Blocks['visionkit_import_inference'] = {
  143. /**
  144. * Block for import.
  145. * @this Blockly.Block
  146. */
  147. init: function() {
  148. this.setColour(Blockly.Blocks.visionkit.HUE);
  149. this.appendDummyInput()
  150. .appendField(Blockly.Msg.VISIONKIT_IMPORT_INFERENCE)
  151. .appendField(new Blockly.FieldDropdown([
  152. ["Camera Inference","CameraInference"]
  153. ]), "IMPORT")
  154. // this.setInputsInline(false);
  155. this.setOutput(true);
  156. // this.setPreviousStatement(true);
  157. // this.setNextStatement(true);
  158. },
  159. };
  160. /*
  161. * vision kit
  162. * camera inference block
  163. */
  164. Blockly.Blocks['visionkit_cameraInference'] = {
  165. /**
  166. * Block for import.
  167. * @this Blockly.Block
  168. */
  169. init: function() {
  170. this.setColour(Blockly.Blocks.visionkit.HUE);
  171. this.appendDummyInput()
  172. .appendField(Blockly.Msg.VISIONKIT_AIY_VISION_INFERENCE)
  173. this.appendDummyInput()
  174. .appendField(Blockly.Msg.VISIONKIT_CAMERA_INFERENCE)
  175. .appendField(new Blockly.FieldTextInput("inference"),"INFERENCE")
  176. this.appendDummyInput()
  177. .appendField(Blockly.Msg.VISIONKIT_USE_MODEL)
  178. .appendField(new Blockly.FieldDropdown([
  179. ["Face Detection","face_detection.model()"]
  180. ]), "USEMODEL")
  181. this.appendStatementInput("STACK")
  182. .appendField(Blockly.Msg.VISIONKIT_DO)
  183. // this.setInputsInline(false);
  184. // this.setOutput(true);
  185. this.setPreviousStatement(true);
  186. this.setNextStatement(true);
  187. },
  188. };
  189. /*
  190. * vision kit
  191. * run inference block
  192. */
  193. Blockly.Blocks['visionkit_runInference'] = {
  194. /**
  195. * Block for import.
  196. * @this Blockly.Block
  197. */
  198. init: function() {
  199. this.setColour(Blockly.Blocks.visionkit.HUE);
  200. this.appendValueInput("INPUT")
  201. .appendField(Blockly.Msg.VISIONKIT_RUN_INFERENCE)
  202. this.setInputsInline(true);
  203. this.setOutput(true);
  204. // this.setPreviousStatement(true);
  205. // this.setNextStatement(true);
  206. },
  207. };
  208. /*
  209. * vision kit
  210. * get inference block
  211. */
  212. Blockly.Blocks['visionkit_GetInference'] = {
  213. /**
  214. * Block for import.
  215. * @this Blockly.Block
  216. */
  217. init: function() {
  218. this.setColour(Blockly.Blocks.visionkit.HUE);
  219. this.appendDummyInput()
  220. .appendField(Blockly.Msg.VISIONKIT_GETINFERENCE)
  221. .appendField(new Blockly.FieldDropdown([
  222. ["Count","count"],
  223. ["Rate","rate"]
  224. ]),"INFERENCE")
  225. // this.setInputsInline(true);
  226. this.setOutput(true);
  227. // this.setPreviousStatement(true);
  228. // this.setNextStatement(true);
  229. },
  230. };
  231. /*
  232. * vision kit
  233. * get inference block
  234. */
  235. Blockly.Blocks['visionkit_faceDetection_operation'] = {
  236. /**
  237. * Block for import.
  238. * @this Blockly.Block
  239. */
  240. init: function() {
  241. this.setColour(Blockly.Blocks.visionkit.HUE);
  242. this.appendValueInput("INPUT")
  243. .appendField(Blockly.Msg.VISIONKIT_IMPORT)
  244. .appendField(new Blockly.FieldDropdown([
  245. ["Face Detection","face_detection"]
  246. ]),"MODEL")
  247. .appendField(Blockly.Msg.VISISONKIT_MODEL)
  248. .appendField(new Blockly.FieldDropdown([
  249. ["Get Faces","get_faces"]
  250. ]),"OPERATION")
  251. // this.setInputsInline(true);
  252. this.setOutput(true);
  253. // this.setPreviousStatement(true);
  254. // this.setNextStatement(true);
  255. },
  256. };
  257. /*
  258. * vision kit
  259. * get model block
  260. */
  261. Blockly.Blocks['visionkit_model_get'] = {
  262. /**
  263. * Block for import.
  264. * @this Blockly.Block
  265. */
  266. init: function() {
  267. this.setColour(Blockly.Blocks.visionkit.HUE);
  268. this.appendValueInput("INPUT")
  269. .appendField(Blockly.Msg.VISIONKIT_GETMODEL_MODEL)
  270. .appendField(new Blockly.FieldDropdown([
  271. ["Bounding Box","bounding_box"],
  272. ["Joy Score","joy_score"]
  273. ]),"MODEL")
  274. .appendField(Blockly.Msg.VISIONKIT_GETMODEL_OF)
  275. this.setInputsInline(true);
  276. this.setOutput(true);
  277. // this.setPreviousStatement(true);
  278. // this.setNextStatement(true);
  279. },
  280. };
  281. /*
  282. * vision kit
  283. * Use Annotator block
  284. */
  285. Blockly.Blocks['visionkit_Use_Annotator'] = {
  286. /**
  287. * Block for import.
  288. * @this Blockly.Block
  289. */
  290. init: function() {
  291. this.setColour(Blockly.Blocks.visionkit.HUE);
  292. this.appendDummyInput()
  293. .appendField(Blockly.Msg.VISIONKIT_ANNOTATOR)
  294. .appendField(new Blockly.FieldTextInput("camera"),"ANNOTATOR")
  295. .appendField(Blockly.Msg.VISIONKIT_ANNOTATOR_SETTING)
  296. .appendField(new Blockly.FieldTextInput("320"),"X-DIMEN")
  297. .appendField(",")
  298. .appendField(new Blockly.FieldTextInput("240"),"Y-DIMEN")
  299. // this.setInputsInline(true);
  300. // this.setOutput(true);
  301. this.setPreviousStatement(true);
  302. this.setNextStatement(true);
  303. },
  304. };
  305. Blockly.Blocks['visionkit_Use_Annotator_output'] = {
  306. /**
  307. * Block for import.
  308. * @this Blockly.Block
  309. */
  310. init: function() {
  311. this.setColour(Blockly.Blocks.visionkit.HUE);
  312. this.appendDummyInput()
  313. .appendField(Blockly.Msg.VISIONKIT_ANNOTATOR)
  314. .appendField(new Blockly.FieldTextInput("camera"),"ANNOTATOR")
  315. .appendField(Blockly.Msg.VISIONKIT_ANNOTATOR_SETTING)
  316. .appendField(new Blockly.FieldTextInput("320"),"X-DIMEN")
  317. .appendField(",")
  318. .appendField(new Blockly.FieldTextInput("240"),"Y-DIMEN")
  319. // this.setInputsInline(true);
  320. this.setOutput(true);
  321. // this.setPreviousStatement(true);
  322. // this.setNextStatement(true);
  323. },
  324. };
  325. /*
  326. * vision kit
  327. * Annotator clear/update block
  328. */
  329. Blockly.Blocks['visionkit_Annotator_operation'] = {
  330. /**
  331. * Block for import.
  332. * @this Blockly.Block
  333. */
  334. init: function() {
  335. this.setColour(Blockly.Blocks.visionkit.HUE);
  336. this.appendDummyInput()
  337. .appendField(Blockly.Msg.VISIONKIT_ANNOTATOR)
  338. .appendField(new Blockly.FieldDropdown([
  339. ["Clear","clear"],
  340. ["Update","update"]
  341. ]),"OPERATION")
  342. // this.setInputsInline(true);
  343. // this.setOutput(true);
  344. this.setPreviousStatement(true);
  345. this.setNextStatement(true);
  346. },
  347. };
  348. /*
  349. * vision kit
  350. * Annotator Bounding block
  351. */
  352. Blockly.Blocks['visionkit_Annotator_Bounding'] = {
  353. /**
  354. * Block for import.
  355. * @this Blockly.Block
  356. */
  357. init: function() {
  358. this.setColour(Blockly.Blocks.visionkit.HUE);
  359. this.appendDummyInput()
  360. .appendField(Blockly.Msg.VISIONKIT_ANNOTATOR_BOUNDING)
  361. this.appendValueInput("INPUT")
  362. .appendField(Blockly.Msg.VISIONKIT_ANNOTATOR_FILL)
  363. .appendField(new Blockly.FieldNumber("1"),"FILL")
  364. // this.setInputsInline(true);
  365. // this.setOutput(true);
  366. this.setPreviousStatement(true);
  367. this.setNextStatement(true);
  368. },
  369. };
  370. Blockly.Blocks['visionkit_myAssistant'] = {
  371. /**
  372. * Block for import.
  373. * @this Blockly.Block
  374. */
  375. init: function() {
  376. this.setColour(Blockly.Blocks.visionkit.HUE);
  377. this.appendDummyInput()
  378. .appendField("MyAssistant")
  379. // this.setInputsInline(true);
  380. this.setOutput(true);
  381. // this.setPreviousStatement(true);
  382. // this.setNextStatement(true);
  383. },
  384. }
  385. /************************************
  386. * Simplify *
  387. *************************************/
  388. Blockly.Blocks['visionkit_import_aiy'] = {
  389. /**
  390. * Block for import.
  391. * @this Blockly.Block
  392. */
  393. init: function() {
  394. this.setColour(Blockly.Blocks.visionkit.HUE);
  395. this.appendDummyInput()
  396. .appendField("import AIY Vision Kit Modules")
  397. // this.appendValueInput("INPUT")
  398. // .appendField("faces")
  399. // this.setInputsInline(true);
  400. this.setPreviousStatement(true);
  401. this.setNextStatement(true);
  402. },
  403. }
  404. Blockly.Blocks['visionkit_avg_joy_score'] = {
  405. /**
  406. * Block for import.
  407. * @this Blockly.Block
  408. */
  409. init: function() {
  410. this.setColour(Blockly.Blocks.visionkit.HUE);
  411. this.appendDummyInput()
  412. .appendField("Define Average Joy Score Demo")
  413. // this.appendValueInput("INPUT")
  414. // .appendField("faces")
  415. // this.setInputsInline(true);
  416. this.setPreviousStatement(true);
  417. this.setNextStatement(true);
  418. },
  419. }
  420. Blockly.Blocks['visionkit_annotator_camera'] = {
  421. init:function() {
  422. this.setColour(Blockly.Blocks.visionkit.HUE);
  423. this.appendDummyInput()
  424. .appendField("Annotator(camera,dimensions=(")
  425. .appendField(new Blockly.FieldTextInput("320"),"X")
  426. .appendField(",")
  427. .appendField(new Blockly.FieldTextInput("240"),"Y")
  428. .appendField(")")
  429. this.appendDummyInput()
  430. .appendField("Scale_x")
  431. .appendField(new Blockly.FieldTextInput("1640"),"SCALE_X")
  432. .appendField("Scale_y")
  433. .appendField(new Blockly.FieldTextInput("1232"),"SCALE_Y")
  434. this.setPreviousStatement(true);
  435. this.setNextStatement(true);
  436. }
  437. }
  438. Blockly.Blocks['visionkit_transform_boundingBox'] = {
  439. init:function() {
  440. this.setColour(Blockly.Blocks.visionkit.HUE);
  441. this.appendDummyInput()
  442. .appendField("Define Bounding Box Transform")
  443. this.setPreviousStatement(true);
  444. this.setNextStatement(true);
  445. }
  446. }
  447. Blockly.Blocks['visionkit_CameraInference'] = {
  448. init:function() {
  449. this.setColour(Blockly.Blocks.visionkit.HUE)
  450. this.appendDummyInput()
  451. // .appendField("with CameraInference as inference")
  452. .appendField("Camera Inference set ")
  453. .appendField(new Blockly.FieldDropdown([
  454. ["Face Detection","Face Detection"]
  455. ]),"SETTING")
  456. this.appendStatementInput("STACK")
  457. this.setPreviousStatement(true);
  458. this.setNextStatement(true);
  459. }
  460. }
  461. Blockly.Blocks['visionkit_avg_joy_score_num'] = {
  462. init:function() {
  463. this.setColour(Blockly.Blocks.visionkit.HUE)
  464. this.appendDummyInput()
  465. .appendField("avg_joy_score(")
  466. .appendField(new Blockly.FieldTextInput("faces"),"FACE")
  467. .appendField(")")
  468. this.setOutput(true);
  469. }
  470. }
  471. Blockly.Blocks['visionkit_face'] = {
  472. init:function() {
  473. this.setColour(Blockly.Blocks.visionkit.HUE)
  474. this.appendDummyInput()
  475. .appendField("faces")
  476. this.setOutput(true)
  477. }
  478. }