|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="ja"> |
| 3 | + <head> |
| 4 | + <title>Hello Stack-chan</title> |
| 5 | + <meta name="viewport" content="width=device-width,initial-scale=1.0"> |
| 6 | + <meta charset="utf-8"> |
| 7 | + |
| 8 | + <script type="text/javascript" src="js/joy.min.js"></script> |
| 9 | + <script type="text/javascript"> |
| 10 | + async function get_camera_image(){ |
| 11 | + const res = await fetch('/get_camera_image', { |
| 12 | + method: "POST", body: "" |
| 13 | + }); |
| 14 | + const { width, height, data } = await res.json(); |
| 15 | + const canvas = document.getElementById('canvas'); |
| 16 | + canvas.width = width; |
| 17 | + canvas.height = height; |
| 18 | + const ctx = canvas.getContext('2d'); |
| 19 | + const imageData = ctx.createImageData(width, height); |
| 20 | + |
| 21 | + const binary = atob(data); // Base64 → binary |
| 22 | + const buffer = new Uint8Array(binary.length); |
| 23 | + for (let i = 0; i < binary.length; i++) { |
| 24 | + buffer[i] = binary.charCodeAt(i); |
| 25 | + } |
| 26 | + |
| 27 | + for (let i = 0, j = 0; i < buffer.length; i += 2, j += 4) { |
| 28 | + const value = (buffer[i] << 8) | buffer[i + 1]; |
| 29 | + |
| 30 | + // RGB565 → 8bit RGB変換 |
| 31 | + const r = ((value >> 11) & 0x1F) << 3; |
| 32 | + const g = ((value >> 5) & 0x3F) << 2; |
| 33 | + const b = (value & 0x1F) << 3; |
| 34 | + |
| 35 | + imageData.data[j] = r; |
| 36 | + imageData.data[j + 1] = g; |
| 37 | + imageData.data[j + 2] = b; |
| 38 | + imageData.data[j + 3] = 255; // Alpha |
| 39 | + } |
| 40 | + |
| 41 | + ctx.putImageData(imageData, 0, 0); |
| 42 | + } |
| 43 | + |
| 44 | + async function move(){ |
| 45 | + var pn = document.getElementById('pan').value; |
| 46 | + var tlt = document.getElementById('tilt').value; |
| 47 | + |
| 48 | + const res = await fetch('/move', { |
| 49 | + method: "POST", |
| 50 | + body: "[" + pn + "," + tlt +"]" |
| 51 | + }); |
| 52 | + } |
| 53 | + |
| 54 | + async function move_angle(x, y){ |
| 55 | + var pn = Math.trunc(x * 0.6); |
| 56 | + var tlt = Math.trunc(Math.max(Math.min(-y*0.3, 5), -25)); |
| 57 | + const res = await fetch('/move', { |
| 58 | + method: "POST", |
| 59 | + body: "[" + pn + "," + tlt +"]" |
| 60 | + }); |
| 61 | + } |
| 62 | + |
| 63 | + async function face(){ |
| 64 | + var face_ = document.getElementById('face').value; |
| 65 | + const res = await fetch('/face', { |
| 66 | + method: "POST", |
| 67 | + body: face_ |
| 68 | + }); |
| 69 | + } |
| 70 | + |
| 71 | + </script> |
| 72 | + </head> |
| 73 | + <body> |
| 74 | + <h1>アールティ版<br>スタックチャンの操作</h1> |
| 75 | + <h3>首振り操作</h3> |
| 76 | + <div > |
| 77 | + 水平方向:<input id="joyX" type="text" value="0"/></br> |
| 78 | + 垂直方向:<input id="joyY" type="text" value="0"/> |
| 79 | + </div> |
| 80 | + <div id="joyDiv" style="width:200px;height:200px;margin:10px;"></div> |
| 81 | + |
| 82 | + <script type="text/javascript"> |
| 83 | + var joyX = document.getElementById("joyX"); |
| 84 | + var joyY = document.getElementById("joyY"); |
| 85 | + |
| 86 | + var joyParam = { "title": "joystick", "autoReturnToCenter": false }; |
| 87 | + var Joy = new JoyStick('joyDiv', joyParam); |
| 88 | + |
| 89 | + setInterval(function(){ |
| 90 | + if (joyX.value != Joy.GetX() || joyY.value != Joy.GetY()){ |
| 91 | + move_angle(Joy.GetX(), Joy.GetY()); |
| 92 | + } |
| 93 | + joyX.value=Joy.GetX(); |
| 94 | + joyY.value=Joy.GetY(); |
| 95 | + }, 1000); |
| 96 | + </script> |
| 97 | + <h3>Face</h3> |
| 98 | + 顔の表情: |
| 99 | + <select id="face" onchange="face()"> |
| 100 | + <option value="normal">通常(瞬きあり)</option> |
| 101 | + <option value="smile">笑い</option> |
| 102 | + <option value="anger">怒り</option> |
| 103 | + <option value="unhappy">悲しみ</option> |
| 104 | + <option value="surprise">驚き</option> |
| 105 | + <option value="wink_r">ウィンク(右)</option> |
| 106 | + <option value="wink_l">ウィンク(左)</option> |
| 107 | + <option value="look_r">右を見る</option> |
| 108 | + <option value="look_l">左を見る</option> |
| 109 | + <option value="look_u">見上げる</option> |
| 110 | + <option value="look_d">見下ろす</option> |
| 111 | + </select><br> |
| 112 | + <!-- <img src="images/face.png" > --> |
| 113 | + <button onclick="get_camera_image()">カメラで撮影</button><br> |
| 114 | + <canvas id="canvas"></canvas> |
| 115 | + |
| 116 | + <h3>リンク</h3> |
| 117 | + <ul> |
| 118 | + <li><a href="asr_tts.html">音声認識&音声合成</a></li> |
| 119 | + </ul> |
| 120 | + |
| 121 | + |
| 122 | + </body> |
| 123 | +</html> |
0 commit comments