Skip to content

Commit

Permalink
update: iotcam node
Browse files Browse the repository at this point in the history
  • Loading branch information
rootkwak528 committed Oct 5, 2021
1 parent 4c9cb98 commit ef2a06b
Show file tree
Hide file tree
Showing 419 changed files with 66,517 additions and 30 deletions.
2 changes: 1 addition & 1 deletion hand-detection-iotcam.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
outputs: 1,
icon: "font-awesome/fa-hand-paper-o",
label: function() {
return this.name||"hands detection iotcam"
return this.name||"hands-detection-iotcam"
},
oneditprepare: function() {
},
Expand Down
12 changes: 6 additions & 6 deletions hand-detection-iotcam.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ module.exports = function(RED) {
/* hands motion capture used timer if sucess regist*/
function onCapture(motionName){
setTimeout(() => {
captureCtx.drawImage(canvasElement, 0, 0, captureElement.width, captureElement.height);
captureCtx.drawImage(outputElement, 0, 0, captureElement.width, captureElement.height);
let detail = "";
const fixed = 5;
Expand Down Expand Up @@ -312,7 +312,7 @@ module.exports = function(RED) {
document.getElementById("regist-btn").addEventListener('click', function () {
document.getElementById("motion-result-message").style.color = "green";
document.getElementById("motion-result-message").textContent = "[" + handMotionName.value + "] Data sent successfully! Check out the registration results!";
ws.send(JSON.stringify(poseDataResult));
dataWebSocket.send(JSON.stringify(poseDataResult));
})
Expand Down Expand Up @@ -342,9 +342,9 @@ module.exports = function(RED) {
/* keypoint rendering function */
function onResults(results) {
outputCtx.save()
outputCtx.clearRect(0, 0, canvasElement.width, canvasElement.height)
outputCtx.clearRect(0, 0, outputElement.width, outputElement.height)
outputCtx.globalCompositeOperation = 'destination-atop'
outputCtx.drawImage(results.image, 0, 0, canvasElement.width, canvasElement.height)
outputCtx.drawImage(results.image, 0, 0, outputElement.width, outputElement.height)
outputCtx.globalCompositeOperation = 'source-over'
if (results.multiHandLandmarks) {
for (const landmarks of results.multiHandLandmarks) {
Expand All @@ -353,7 +353,7 @@ module.exports = function(RED) {
drawLandmarks(outputCtx, landmarks, {color: '#b2a1f4', lineWidth: 1});
results.regist = false;
results.poseName = null;
ws.send(JSON.stringify(results));
dataWebSocket.send(JSON.stringify(results));
poseData = results;
}
}
Expand Down Expand Up @@ -387,7 +387,7 @@ module.exports = function(RED) {
/* async rendering function */
async function render() {
await hands.send({ image: videoElement })
await hands.send({ image: inputElement })
}
Expand Down
11 changes: 5 additions & 6 deletions hand-detection-webcam.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
defaults: {
name: {value: ""},
serverUrl: {value: 'localhost'},
monitorPort: {value: 1881, validate:RED.validators.number()},
monitorPort: {value: 1883, validate:RED.validators.number()},
dataSocketUrl: {value: 'ws://localhost:1880/ws/data'},
},
inputs: 1,
outputs: 1,
icon: "font-awesome/fa-hand-paper-o",
paletteLabel: "hand detect",
label: function() {
return this.name||"hands detection"
return this.name||"hands-detection-webcam"
},
oneditprepare: function() {
const inputVideo = document.getElementById('input-video')
Expand All @@ -37,7 +36,7 @@
})
</script>

<script type="text/html" data-template-name="pose-detection-webcam">
<script type="text/html" data-template-name="hand-detection-webcam">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
Expand All @@ -50,7 +49,7 @@

<div class="form-row">
<label for="node-input-monitorPort"><i class="fa fa-tag"></i> Monitor Port</label>
<input type="text" id="node-input-monitorPort" placeholder="(default) 1881">
<input type="text" id="node-input-monitorPort" placeholder="(default) 1883">
</div>

<div class="form-row">
Expand All @@ -67,7 +66,7 @@
</div>
</script>

<script type="text/html" data-help-name="hand-detection-iotcam">
<script type="text/html" data-help-name="hand-detection-webcam">
<p>A simple node that recognizes and visualizes hand posture using a webcam.</p>

<h3>Inputs</h3>
Expand Down
32 changes: 16 additions & 16 deletions hand-detection-webcam.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ module.exports = function(RED) {
// DOM 엘리먼트
const inputElement = document.getElementById('input-canvas')
const inputElement = document.getElementById('input-video')
const outputElement = document.getElementById('output-canvas')
const captureElement = document.getElementById('capture-canvas')
const outputCtx = outputElement.getContext('2d')
Expand Down Expand Up @@ -261,7 +261,7 @@ module.exports = function(RED) {
/* hands motion capture used timer if sucess regist*/
function onCapture(motionName){
setTimeout(() => {
captureCtx.drawImage(canvasElement, 0, 0, captureElement.width, captureElement.height);
captureCtx.drawImage(outputElement, 0, 0, captureElement.width, captureElement.height);
let detail = "";
const fixed = 5;
Expand Down Expand Up @@ -300,7 +300,7 @@ module.exports = function(RED) {
document.getElementById("regist-btn").addEventListener('click', function () {
document.getElementById("motion-result-message").style.color = "green";
document.getElementById("motion-result-message").textContent = "[" + handMotionName.value + "] Data sent successfully! Check out the registration results!";
ws.send(JSON.stringify(poseDataResult));
dataWebSocket.send(JSON.stringify(poseDataResult));
})
Expand Down Expand Up @@ -329,23 +329,23 @@ module.exports = function(RED) {
/* keypoint rendering function */
function onResults(results) {
canvasCtx.save()
canvasCtx.clearRect(0, 0, canvasElement.width, canvasElement.height)
canvasCtx.globalCompositeOperation = 'destination-atop'
canvasCtx.drawImage(results.image, 0, 0, canvasElement.width, canvasElement.height)
canvasCtx.globalCompositeOperation = 'source-over'
outputCtx.save()
outputCtx.clearRect(0, 0, outputElement.width, outputElement.height)
outputCtx.globalCompositeOperation = 'destination-atop'
outputCtx.drawImage(results.image, 0, 0, outputElement.width, outputElement.height)
outputCtx.globalCompositeOperation = 'source-over'
if (results.multiHandLandmarks) {
for (const landmarks of results.multiHandLandmarks) {
drawConnectors(canvasCtx, landmarks, HAND_CONNECTIONS,
drawConnectors(outputCtx, landmarks, HAND_CONNECTIONS,
{color: '#f2d6ae', lineWidth: 5});
drawLandmarks(canvasCtx, landmarks, {color: '#b2a1f4', lineWidth: 1});
drawLandmarks(outputCtx, landmarks, {color: '#b2a1f4', lineWidth: 1});
results.regist = false;
results.poseName = null;
ws.send(JSON.stringify(results));
dataWebSocket.send(JSON.stringify(results));
poseData = results;
}
}
canvasCtx.restore();
outputCtx.restore();
// transport <canvas> data in form of blob. (I referenced the link below)
// 캔버스 데이터를 블롭화하여 미러링 노드로 전송 (아래 링크 참고하였음)
Expand Down Expand Up @@ -375,7 +375,7 @@ module.exports = function(RED) {
/* async rendering function */
async function render() {
await hands.send({ image: videoElement })
await hands.send({ image: inputElement })
}
Expand All @@ -387,9 +387,9 @@ module.exports = function(RED) {
navigator.mediaDevices.getUserMedia(mediaConstraints)
.then(stream => {
videoElement.srcObject = stream
videoElement.oncanplay = function (e) {
videoElement.play()
inputElement.srcObject = stream
inputElement.oncanplay = function (e) {
inputElement.play()
.then(() => {
startDetect(render)
})
Expand Down
1 change: 1 addition & 0 deletions node_modules/.bin/mime

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ef2a06b

Please sign in to comment.