Skip to content

Instantly share code, notes, and snippets.

@npinto
npinto / cv2_detect.py
Created September 5, 2012 07:13
Simple face detection with OpenCV 'cv2' python bindings from 2.4.x
import cv2
import cv2.cv as cv
def detect(img, cascade_fn='haarcascades/haarcascade_frontalface_alt.xml',
scaleFactor=1.3, minNeighbors=4, minSize=(20, 20),
flags=cv.CV_HAAR_SCALE_IMAGE):
cascade = cv2.CascadeClassifier(cascade_fn)
rects = cascade.detectMultiScale(img, scaleFactor=scaleFactor,
@heisters
heisters / colorThreshold.cpp
Last active October 9, 2015 19:17
Function for elegantly performing range thresholding with arbitrary colors and ranges with OpenCV
// This code is modified from the working version to remove coupling with the original
// application, and hasn't been tested in its new form. So, it's enough to give you
// the basic idea, but may not entirely work ;)
//
// It assumes the src image is in HSV and the dst image is grayscale.
//
// CvScalar red = cvScalar(179, 255, 255);
// CvScalar lowOffset = cvScalar(-20, -150, -150); // find colors down to h = 159, s = 105, v = 105
// CvScalar highOffset = cvScalar(20, 0, 0); // find colors up to h = 19, s = 255, v = 255 (h wraps/is mod 179)
// colorThreshold(img, thresholded, red, lowOffset, highOffset);
@adammw
adammw / README.md
Created August 3, 2012 06:30
Node.js for Raspberry Pi

Node.js for Raspberry Pi

Pre-built binaries

Recent releases have been pre-built using cross-compilers and this script and are downloadable below.

If you have found these packages useful, give me a shout out on twitter: @adammw

@scttnlsn
scttnlsn / README.md
Created July 30, 2012 22:16
Pub/sub with MongoDB and Node.js

Pub/sub with MongoDB and Node.js

Setup:

$ mongo
> use pubsub
> db.createCollection('messages', { capped: true, size: 100000 })
> db.messages.insert({})
@turtlesoupy
turtlesoupy / nginx.conf
Created July 8, 2012 21:16
node.js upstream nginx config
http {
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=one:8m max_size=3000m inactive=600m;
proxy_temp_path /var/tmp;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
gzip_comp_level 6;
@nf
nf / hello-node.js
Created July 6, 2012 21:14
Hello world web server that scales across multiple processors
var cluster = require('cluster');
var http = require('http');
var numCPUs = require('os').cpus().length;
if (cluster.isMaster) {
// Fork workers.
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('exit', function(worker, code, signal) {
@InternetExplorer
InternetExplorer / scoreboardProjection.example.js
Created April 2, 2012 22:11
Justafriend.ie - Scoreboard Projection Example
function scoreboardProjection(frame_offset) {
if (frame_offset == null) frame_offset = 0;
var canvas, proj;
var score_img_1,
score_img_2,
overlay,
board_canvas,
score_canvas_1,
score_canvas_2;
@founddrama
founddrama / moment-in-node.js
Created March 24, 2012 12:53
Moment.js examples
// node:
var moment = require('moment');
moment().add('days', 2).fromNow();
// 'in 2 days'
moment().subtract('days', 2).fromNow();
// '2 days ago'
moment('November 1977').fromNow()
@youtalk
youtalk / node-jquery-autocomplete.js
Created January 12, 2012 06:40
Keyword search using Node.js server and jQuery-autocomplete client
// Server-side
app.get('/keyword/search',
function (req, res, next) {
var query = new RegExp('^' + req.query.q + '.*$', 'i');
var result = [];
mongodb.keywords.find(
{ word: query }, [ 'word' ], { limit: 5 },
function (err, keywords) {
keywords.forEach(function (k) {
result.push(k.word);
@Rob-ot
Rob-ot / Draggable.js
Created December 16, 2011 23:46
Draggable and dropable views for backbone, uses html5 drag and drop api, requires jquery and underscore, not tested in IE yet
return View.extend({
initialize: function () {
this.el.attr("draggable", "true")
this.el.bind("dragstart", _.bind(this._dragStartEvent, this))
},
_dragStartEvent: function (e) {
var data
if (e.originalEvent) e = e.originalEvent
e.dataTransfer.effectAllowed = "copy" // default to copy