Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed motion movement controls -> left, right, up, down #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/detectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ CamMotion.Detectors = (function () {
}

// play with this treshold to find the best sensitiveness for detection
var treshold = 40;
var treshold = 100;

function RightMotion(points) {
return HorizontalMotion(points, treshold, 1000, treshold);
Expand Down
17 changes: 11 additions & 6 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ CamMotion.Engine = function(options) {
options.colorDiffTreshold = options.colorDiffTreshold || 0x25;
options.width = options.width || 640;
options.height = options.height || 480;
options.timeout = options.timeout || 50; // in millis
options.timeout = options.timeout || 1; // in millis
options.videoNode = options.videoNode || appendVideo();
options.canvasSource = options.canvasSource || appendCanvas();
options.canvasBlended = options.canvasBlended || appendCanvas();
Expand Down Expand Up @@ -249,12 +249,17 @@ CamMotion.Engine = function(options) {
// loop over the pixels
while (i < (blendedData.data.length * 0.25)) {
// make an average between the color channel
average += (blendedData.data[i*4] + blendedData.data[i*4+1] + blendedData.data[i*4+2]) / 3;
i += options.pixelsToSkip;
var aalt = (blendedData.data[i*4] + blendedData.data[i*4+1] + blendedData.data[i*4+2]) / 3;
if(aalt != 0)
average += aalt;

i += options.pixelsToSkip + 20;
nPixels++;
}
// calculate an average between of the color values of the note area
average = average / nPixels;
if(nPixels != 0)
average = average / nPixels;

return average;
}

Expand Down Expand Up @@ -339,8 +344,8 @@ CamMotion.Engine = function(options) {
if (detectors.length > 0) {
// since gesture detectors need a
// list of pointsHistory, we need to calculate it
if (getAverageMovement() > 10) {
var point = getMovementPoint();
var point = getMovementPoint(true);
if (getAverageMovement(point.x-point.r/2, point.y-point.r/2, point.r, point.r) > 10) {
points.push([point.x, point.y]);
} else if(points.length()>0) {
points.reset();
Expand Down
2 changes: 1 addition & 1 deletion samples/theremin-instrument.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ <h1>Theremin Demo</h1>
<p>
The demo below combines js-cam-motion together with the
<a href="https://dvcs.w3.org/hg/audio/raw-file/tip/webaudio/specification.html">Web Audio API</a
to generate a <a href=="http://nl.wikipedia.org/wiki/Theremin">theremin<a/>.
to generate a <a href=="http://nl.wikipedia.org/wiki/Theremin">theremin</a>.
</p>

<p>
Expand Down