I want to detect red and green objects from webcam. I am using this Trackingjs library. I think with the library, it will track the red, green and blue value of an object and detect the colour according to the built-in colour library in their code.
Their built-in colours are defined like this:
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;
});
In the example above, objects which has their blue - green >= 100
and red -green >= 60
will be purple
.
Can someone explain this to me how this works. And if I want to detect red/ reddish and green/greenish, how should I do with the same function.