Skip to content

Instantly share code, notes, and snippets.

View hawkeye64's full-sized avatar

Jeff Galbraith hawkeye64

View GitHub Profile
@hawkeye64
hawkeye64 / gist:a30e43c8301626f7687b985b5e7b04bd
Created December 15, 2017 13:51
How to get snapshoutUri and finally snapshot from ONVIF camera
/* this is a partial gist */
const Promise = require('bluebird')
const axios = require('axios')
const Camera = require('onvif').Cam
class OnvifManager {
//...
this.cameras = {}
//...
@hawkeye64
hawkeye64 / gist:e67cb5aae8f46d9c94ea2c9a4bb9247b
Created December 29, 2017 14:15
Using request to get snapshot from ONVIF camera
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]
@hawkeye64
hawkeye64 / gist:8159c8ba07e7d11bf7a8a837e94fedbb
Last active May 24, 2018 16:54
Upgrade Postgresql 9.6 to 10.4 on Ubuntu 17.10 with Python support
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
@hawkeye64
hawkeye64 / command-line-usage_example.js
Created August 27, 2018 18:29
command-line-usage Example
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: [
@hawkeye64
hawkeye64 / command-line-args.example.js
Created August 27, 2018 18:35
command-line-args Example
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({})
@hawkeye64
hawkeye64 / opencv4nodejs_example.js
Created August 27, 2018 18:57
opencv4nodejs Example
// 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
@hawkeye64
hawkeye64 / predict_function.js
Last active August 27, 2018 21:46
The "predict" function
/**
* 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)
@hawkeye64
hawkeye64 / extract_results_example.js
Created August 27, 2018 19:10
Extract Results Example
/**
* 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);
@hawkeye64
hawkeye64 / update_image_example.js
Created August 27, 2018 19:18
Update Image Example
/**
* 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) => {
@hawkeye64
hawkeye64 / gist:8bd5c1a7eba8fb4d58b6df223ee115ea
Created September 5, 2018 14:31
Linux command to run "classify" on images (with Color in name and extension .jpg)
find . -type f -name "*Color*.jpg" -exec classify --image "{}" --confidence 30 \;