eduardolundgren / tracking.js

A modern approach for Computer Vision on the web
http://trackingjs.com
Other
9.43k stars 1.44k forks source link

tracking red, green and blue in camera #235

Open AlaaElZein opened 6 years ago

AlaaElZein commented 6 years ago

Hello support,

I am trying to track the r,g,b colors instead of cyan, magenta and yellow, so in the registerColor function i have changed the values (or add a new registerColor function): tracking.ColorTracker.registerColor("red", function (t, r, n) { var e = 50, a = t - 255, i = r - 0, o = n - 0; return t - n >= e && r - n >= e || a a + i i + o * o < 1e4

But how can i knot the correct values that i have to put in the formula for e,a,i,o ? i tried many values instead of 255 and 0 and still not working. so how can i track the red, green, and blue colors?

Regards,

AlaaElZein commented 6 years ago

Hello guys,

any update?

Regards,

murat-aka commented 6 years ago

Look at the examples below.

// Default colors //===================

tracking.ColorTracker.registerColor('cyan', function(r, g, b) {
    var thresholdGreen = 50,
      thresholdBlue = 70,
      dx = r - 0,
      dy = g - 255,
      dz = b - 255;

    if ((g - r) >= thresholdGreen && (b - r) >= thresholdBlue) {
      return true;
    }
    return dx * dx + dy * dy + dz * dz < 6400;
  });
tracking.ColorTracker.registerColor('magenta', function(r, g, b) {
    var threshold = 50,
      dx = r - 255,
      dy = g - 0,
      dz = b - 255;

    if ((r - g) >= threshold && (b - g) >= threshold) {
      return true;
    }
    return dx * dx + dy * dy + dz * dz < 19600;
  });
tracking.ColorTracker.registerColor('yellow', function(r, g, b) {
    var threshold = 50,
      dx = r - 255,
      dy = g - 255,
      dz = b - 0;

    if ((r - b) >= threshold && (g - b) >= threshold) {
      return true;
    }
    return dx * dx + dy * dy + dz * dz < 10000;
});
murat-aka commented 6 years ago

139

141

186

224

132

254

murat-aka commented 6 years ago

your question is already answered.

175