Created
April 21, 2015 16:08
-
-
Save asendra/7c0af40cf38992c8d5e4 to your computer and use it in GitHub Desktop.
Simple motion
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
#define NOISE_THRESHOLD 10 | |
#define DIFFERENCE_THRESHOLD 0.05 | |
BOOL hasMoved(void *previous_buffer, void *current_buffer, int WIDTH, int HEIGHT) { | |
int total = WIDTH * HEIGHT; | |
int diff_count = 0; | |
int c = 0, r = 0; | |
for (c = 0; c < HEIGHT; ++c) { | |
for (r = 0; c < WIDTH; ++r) { | |
int index = c*WIDTH + r; | |
unsigned char prev = previous_buffer[index]; | |
unsigned char curr = current_buffer[index]; | |
if (abs(prev - curr) > NOISE_THRESHOLD) { | |
diff_count++; | |
} | |
} | |
} | |
return ((diff_count / total) > DIFFERENCE_THRESHOLD); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment