Skip to content

Instantly share code, notes, and snippets.

@alippai
Created July 21, 2015 22:41
Show Gist options
  • Save alippai/41b3e574fb128e35e8f8 to your computer and use it in GitHub Desktop.
Save alippai/41b3e574fb128e35e8f8 to your computer and use it in GitHub Desktop.
Image center
const frame = ctx2.getImageData(data.left, data.top, data.width, data.height);
M00 = 0;
M10 = 0;
M01 = 0;
for (var i = 0; i < frame.data.length / 4; i++) {
const r = frame.data[i * 4];
const g = frame.data[i * 4 + 1];
const b = frame.data[i * 4 + 2];
const intensity = 0.2989*r + 0.5870*g + 0.1140*b;
const x = i % data.width;
const y = Math.floor(i / data.width);
M00 += intensity;
M10 += x * intensity;
M01 += y * intensity;
}
const res_x = M10 / M00;
const res_y = M01 / M00;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment