From 8d799bcd9671aa3c1347889d99e5b193c1066361 Mon Sep 17 00:00:00 2001 From: Cedric Godin Date: Tue, 6 Feb 2018 14:50:46 -0500 Subject: [PATCH] Camera viewer --- main.js | 1 + package-lock.json | 49 ++++++++++++++++++++ package.json | 5 +- resources/js/point-to-image.js | 20 ++++++++ resources/js/share-model.js | 83 ++++++++++++++++++++++++++++++++++ resources/js/tcp_link.js | 4 +- share.js | 47 +++++++++++++++++++ views/live_data.html | 1 + views/share.html | 48 ++++++++++++++++++++ 9 files changed, 254 insertions(+), 4 deletions(-) create mode 100644 resources/js/point-to-image.js create mode 100644 resources/js/share-model.js create mode 100644 share.js create mode 100644 views/share.html diff --git a/main.js b/main.js index 000afb6..44a9366 100644 --- a/main.js +++ b/main.js @@ -79,6 +79,7 @@ app.on('activate', function () { const sockets = require('./servers.js') const recordings = require('./recordings.js') +const share = require('./share.js') odasStudio.odas = require('./odas.js') recordings.register(odasStudio) diff --git a/package-lock.json b/package-lock.json index ddf8f7f..e84f5b8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -369,6 +369,11 @@ "delayed-stream": "1.0.0" } }, + "complex.js": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/complex.js/-/complex.js-2.0.4.tgz", + "integrity": "sha512-Syl95HpxUTS0QjwNxencZsKukgh1zdS9uXeXX2Us0pHaqBR6kiZZi0AkZ9VpZFwHJyVIUVzI4EumjWdXP3fy6w==" + }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -449,6 +454,11 @@ "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=" }, + "decimal.js": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/decimal.js/-/decimal.js-9.0.1.tgz", + "integrity": "sha512-2h0iKbJwnImBk4TGk7CG1xadoA0g3LDPlQhQzbZ221zvG0p2YVUedbKIPsOZXKZGx6YmZMJKYOalpCMxSdDqTQ==" + }, "deep-extend": { "version": "0.4.2", "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.4.2.tgz", @@ -763,6 +773,11 @@ "mime-types": "2.1.17" } }, + "fraction.js": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/fraction.js/-/fraction.js-4.0.4.tgz", + "integrity": "sha512-aK/oGatyYLTtXRHjfEsytX5fieeR5H4s8sLorzcT12taFS+dbMZejnvm9gRa8mZAPwci24ucjq9epDyaq5u8Iw==" + }, "fs-extra": { "version": "0.30.0", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-0.30.0.tgz", @@ -1853,6 +1868,11 @@ "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=" }, + "javascript-natural-sort": { + "version": "0.7.1", + "resolved": "https://registry.npmjs.org/javascript-natural-sort/-/javascript-natural-sort-0.7.1.tgz", + "integrity": "sha1-+eIwPUUH9tdDVac2ZNFED7Wg71k=" + }, "jsbn": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", @@ -2004,6 +2024,20 @@ "integrity": "sha1-2TPOuSBdgr3PSIb2dCvcK03qFG0=", "dev": true }, + "mathjs": { + "version": "3.20.1", + "resolved": "https://registry.npmjs.org/mathjs/-/mathjs-3.20.1.tgz", + "integrity": "sha512-cra4iv6Xj5g38TlVX9VQCqaE8UcDGZkIlB2aM3cB5djoD9YAsLVsQPmzfGWGoZIB/qTht93U8mf1BmkteynSOQ==", + "requires": { + "complex.js": "2.0.4", + "decimal.js": "9.0.1", + "fraction.js": "4.0.4", + "javascript-natural-sort": "0.7.1", + "seed-random": "2.2.0", + "tiny-emitter": "2.0.2", + "typed-function": "0.10.6" + } + }, "meow": { "version": "3.7.0", "resolved": "https://registry.npmjs.org/meow/-/meow-3.7.0.tgz", @@ -2732,6 +2766,11 @@ "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==" }, + "seed-random": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/seed-random/-/seed-random-2.2.0.tgz", + "integrity": "sha1-KpsZ4lCoFwmSMaW5mk2vgLf77VQ=" + }, "semver": { "version": "5.5.0", "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz", @@ -2969,6 +3008,11 @@ "xtend": "4.0.1" } }, + "tiny-emitter": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/tiny-emitter/-/tiny-emitter-2.0.2.tgz", + "integrity": "sha512-2NM0auVBGft5tee/OxP4PI3d8WItkDM+fPnaRAVo6xTDI2knbz9eC5ArWGqtGlYqiH3RU5yMpdyTTO7MguC4ow==" + }, "tough-cookie": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.3.3.tgz", @@ -3007,6 +3051,11 @@ "resolved": "https://registry.npmjs.org/type-name/-/type-name-2.0.2.tgz", "integrity": "sha1-7+fUEj2KxSr/9/QMfk3sUmYAj7Q=" }, + "typed-function": { + "version": "0.10.6", + "resolved": "https://registry.npmjs.org/typed-function/-/typed-function-0.10.6.tgz", + "integrity": "sha512-PYtsDjxyW3vq7Itn2RMz0cn6CrbybIY6XC2i9c1q1o/H94QW8B1Pf3wSsbBDOCMpN1i5jDRrlDsLXFaqXBpfHQ==" + }, "typedarray": { "version": "0.0.6", "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", diff --git a/package.json b/package.json index 8b9aac2..b7c7c96 100644 --- a/package.json +++ b/package.json @@ -14,11 +14,12 @@ "electron-rebuild": "^1.7.3" }, "dependencies": { + "@google-cloud/speech": "^1.0.1", "ip": "^1.1.5", + "mathjs": "^3.20.1", "systeminformation": "^3.17.3", "wav": "^1.0.1", - "wav-file-info": "^0.0.8", - "@google-cloud/speech": "^1.0.1" + "wav-file-info": "^0.0.8" }, "repository": { "type": "git", diff --git a/resources/js/point-to-image.js b/resources/js/point-to-image.js new file mode 100644 index 0000000..72ffdbb --- /dev/null +++ b/resources/js/point-to-image.js @@ -0,0 +1,20 @@ +math = require('mathjs'); + +mtx = [ + [ 788.9292, 0, 329.4620], + [0, 785.3060, 229.3576], + [0, 0, 1.0000] +]; + +exports.transform = function(point) { + + pt = [ + -point.x, + -point.y, + point.z + ]; + + coord = math.multiply(mtx, pt); + + return { x: coord[0], y: coord[1]}; +} diff --git a/resources/js/share-model.js b/resources/js/share-model.js new file mode 100644 index 0000000..bf50be1 --- /dev/null +++ b/resources/js/share-model.js @@ -0,0 +1,83 @@ +const electron = require('electron'); +const ipcRenderer = require('electron').ipcRenderer; +const pointToImage = require("../resources/js/point-to-image.js"); + +const markers = document.getElementsByClassName('marker'); +var rgbValueStrings = ["rgb(75,192,192)","rgb(192,75,192)","rgb(192,192,30)","rgb(0,200,40)"]; + +var errorCallback = function(e) { + console.log('Reeeejected!', e); + }; + + // Not showing vendor prefixes. + navigator.getUserMedia({video: true, audio: false}, function(localMediaStream) { + var video = document.getElementById('video-frame') + video.src = window.URL.createObjectURL(localMediaStream); + }, errorCallback); + + +ipcRenderer.on('tracking', (event, data)=> { + + data.forEach(source => { + let marker = markers[source.index]; + + if(source.active) { + let point = { + x: source.x, + y: source.y, + z: source.z + }; + + let coord = pointToImage.transform(point); + + marker.style.top = coord.y-25 + 'px'; + marker.style.left = coord.x-25 + 'px'; + let video = document.getElementById('video-frame'); + + if(coord.y < 0 || coord.x < 0) { + marker.style.display = 'none'; + } + + else if(coord.x > video.offsetWidth || coord.y > video.offsetHeight) { + marker.style.display = 'none'; + } + + else { + marker.style.display = 'block'; + } + } + + else { + marker.style.display = 'none'; + } + }) +}) ; + + +const shareModel = new Vue({ + el: '#share-model', + data: { + }, + methods: { + } +}); + +const drawCircle = function(canvas, index) { + console.log(canvas); + console.log(index); + + let centerX = 25; + let centerY = 25; + let radius = 20; + + let context = canvas.getContext('2d'); + + context.beginPath(); + context.arc(centerX, centerY, radius, 0, 2 * Math.PI, false); + context.lineWidth = 10; + context.strokeStyle = rgbValueStrings[index]; + context.stroke(); +} + +for(let n = 0; n < markers.length; n++) + drawCircle(markers[n], n); diff --git a/resources/js/tcp_link.js b/resources/js/tcp_link.js index 7df2908..d6345a7 100644 --- a/resources/js/tcp_link.js +++ b/resources/js/tcp_link.js @@ -98,8 +98,8 @@ const processTracking = function(event, msg) { // Trigger update document.dispatchEvent(new Event('tracking')); - if(hasNewSource) - document.dispatchEvent(new Event('update-selection')); + // Send to main + ipcRenderer.send('tracking', currentFrame.sources); }; ipcRenderer.on('newTracking', processTracking) diff --git a/share.js b/share.js new file mode 100644 index 0000000..0bf3193 --- /dev/null +++ b/share.js @@ -0,0 +1,47 @@ +const electron = require('electron'); +const fs = require('fs'); +const path = require('path'); +const url = require('url'); + +const BrowserWindow = electron.BrowserWindow; +const ipcMain = electron.ipcMain; + +let shareWindow = null; + +ipcMain.on('open-share-window', openShareWindow); + +function openShareWindow () { + + if(shareWindow !== null) { + shareWindow.show(); + return; + } + + shareWindow = new BrowserWindow({width: 1280, height: 820, show: false}); + + shareWindow.loadURL(url.format({ + pathname: path.join(__dirname, 'views','share.html'), + protocol: 'file:', + slashes: true + })); + + shareWindow.once('ready-to-show', function () { + shareWindow.show() + }); + + shareWindow.on('closed', function () { + shareWindow = null + }); +} + +ipcMain.on('tracking', (event, data) => { + if(shareWindow !== null && data.length > 0) { + try { + shareWindow.webContents.send('tracking', data); + } + + catch(err) { + console.log('Window was closed'); + } + } +}); diff --git a/views/live_data.html b/views/live_data.html index fbdf8f1..5842880 100644 --- a/views/live_data.html +++ b/views/live_data.html @@ -33,6 +33,7 @@ diff --git a/views/share.html b/views/share.html new file mode 100644 index 0000000..1673754 --- /dev/null +++ b/views/share.html @@ -0,0 +1,48 @@ + + + + + + + Camera + + + + + + +
+
+
+ + + + + +
+
+
+ + + + + + + + + + -- 2.34.1