Last active
July 5, 2016 02:36
-
-
Save andrevenancio/720fa05d1801289c560138a339528ed8 to your computer and use it in GitHub Desktop.
Returns the correlation between two data sets with the same width and height. 0% completely different, 100% same image. (ES6)
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
correlation(curData, oldData, minCorrelation) { | |
const sampledDataWidth = 80; | |
const sampledDataHeight = 60; | |
let count = 0; | |
const total = curData.data.length; | |
for (let i = 0; i < total; i += 4) { | |
// sampling the R channel, since the images are grayscaled and threshold samplying any of the channels will give the same results. | |
if (curData.data[i] !== oldData.data[i]) { | |
count++; | |
} | |
} | |
const correlation = count / (sampledDataWidth * sampledDataHeight); | |
if (correlation > minCorrelation) { | |
// blink detected | |
} | |
return correlation; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment