eduardolundgren / tracking.js

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

How does the default color range in the template work? #139

Open phuwin1995 opened 8 years ago

phuwin1995 commented 8 years ago
    tracking.ColorTracker.registerColor('purple', function(r, g, b) {
    var dx = r - 120;
    var dy = g - 60;
    var dz = b - 210;
    if ((b - g) >= 100 && (r - g) >= 60) {
      return true;
    }
    return dx * dx + dy * dy + dz * dz < 3500;
  });

Does anybody know the logic behind this function? I really want to know because I want to make my own. Thanks in advance.

phuwin1995 commented 8 years ago

@eduardolundgren hi, can you help me with this? How could you come up with this function? For example, I want to have a green, how should I make it? And I think with the red (magenta), it does not detect the red so well.

cirocosta commented 8 years ago

hi @phuwin , it seems to be checking whether a given r,g,b color is too distant from what the library considers what a purple is (imagine that you have a 3d space of colors and you want to check whether the rgb color lies inside the sphere that tells you what is considered purple). That if seems like a way of giving a relaxation to diferences between red | green and blue | green (in the case where we have a very distributed set of distances we'd end up having dx = dy = dz ~= 34.15)

phuwin1995 commented 8 years ago

@cirocosta how do I come up with the 3500?