This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* this is a partial gist */ | |
const Promise = require('bluebird') | |
const axios = require('axios') | |
const Camera = require('onvif').Cam | |
class OnvifManager { | |
//... | |
this.cameras = {} | |
//... | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Previous gist: https://gist.github.com/hawkeye64/a30e43c8301626f7687b985b5e7b04bd | |
Axios couldn't handle working with Axis camera authentication because it uses Realm Digest. I have since changed my code to use the 'request' package. | |
NOTE: It is very *important* to have request do `'sendImmediately': false` which means that request won't send the authentication until the server (camera) responds in the header with *www-authenticate*, then request will send the authorization at that time. | |
commandFetchSnapshot (id) { | |
let self = this | |
return new Promise((resolve, reject) => { | |
let camera = self.cameras[id] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mkdir sql | |
cd sql | |
sudo -u postgres pg_dumpall > backup.sql | |
sudo service postgresql stop | |
sudo apt remove postgresql | |
sudo apt remove postgresql-9.6 postgresql-client-9.6 postgresql-client-common postgresql-common postgresql-contrib postgresql-contrib-9.6 postgresql-plpython3-9.6 | |
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main" > /etc/apt/sources.list.d/pgdg.list' | |
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - | |
sudo apt update | |
sudo apt upgrade |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const commandLineUsage = require('command-line-usage') | |
const sections = [ | |
{ | |
header: 'classify', | |
content: 'Classifies an image using machine learning from passed in image path.' | |
}, | |
{ | |
header: 'Options', | |
optionList: [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs') | |
const path = require('path') | |
const commandLineArgs = require('command-line-args') | |
/** | |
* Returns true if the passed in object is empty | |
* @param {Object} obj | |
*/ | |
const isEmptyObject = (obj) => { | |
return JSON.stringify(obj) === JSON.stringify({}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// OpenCV | |
const cv = require('opencv4nodejs') | |
// initialize model from prototxt and modelFile | |
let net | |
if (dataFile === 'coco300' || dataFile === 'coco512') { | |
net = cv.readNetFromCaffe(prototxt, modelFile) | |
} | |
// read the image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Predicts classifications based on passed in image | |
* @param {Object} img The image to use for predictions | |
*/ | |
const predict = (img) => { | |
// white is the better padding color | |
const white = new cv.Vec(255, 255, 255) | |
// resize to model size | |
const theImage = img.resizeToMax(modelData.size, modelData.size).padToSquare(white) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Extracts results from a network OutputBob | |
* @param {Object} outputBlob The outputBlob returned from net.forward() | |
* @param {Object} img The image used for classification | |
*/ | |
const extractResultsCoco = (outputBlob, img) => { | |
return Array(outputBlob.rows).fill(0) | |
.map((res, i) => { | |
// get class index | |
const classIndex = outputBlob.at(i, 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Generate a random color | |
*/ | |
const getRandomColor = () => new cv.Vec(Math.random() * 255, Math.random() * 255, Math.random() * 255); | |
/** | |
* Returns a function that, for each prediction, draws a rect area with rndom color | |
* @param {Arry} predictions Array of predictions | |
*/ | |
const makeDrawClassDetections = (predictions) => (drawImg, getColor, thickness = 2) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
find . -type f -name "*Color*.jpg" -exec classify --image "{}" --confidence 30 \; |
OlderNewer