Created
July 21, 2015 22:41
-
-
Save alippai/41b3e574fb128e35e8f8 to your computer and use it in GitHub Desktop.
Image center
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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