Last active
April 11, 2018 16:23
-
-
Save baszoetekouw/c87f490a729bcdb56e1553f55528b84f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#include <math.h> | |
#include <stdio.h> | |
#include <inttypes.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <malloc.h> | |
#include <string.h> | |
#include <sys/time.h> | |
int main() | |
{ | |
const unsigned w = 1280; | |
const unsigned h = 720; | |
const unsigned d = 1; | |
const int num_frames = 1000; | |
const int nl3 = 1; | |
const int percentage_pixels_changed = 2; | |
struct timeval the_time; | |
gettimeofday(&the_time, NULL); | |
double time_start = the_time.tv_sec + 1e-6*the_time.tv_usec; | |
int triggered = 0; | |
unsigned num_triggered = 0; | |
uint8_t *work = (uint8_t *) malloc(w*h*d); | |
uint8_t *prev_frame = (uint8_t *) malloc(w*h*d); | |
memset(work,0,w*h*d); | |
memset(prev_frame,2,w*h*d); | |
for (unsigned frame=0; frame<num_frames; frame++) | |
{ | |
uint8_t *pw = work, *pp = prev_frame; | |
int cnt = 0; | |
for(int i=0; i<w*h; i++) { | |
int lc = 0, lp = 0; | |
for (unsigned j=0; j<d; j++) lc += *pw++; | |
for (unsigned j=0; j<d; j++) lp += *pp++; | |
cnt += abs(lc - lp) >= nl3; | |
} | |
triggered = cnt > (percentage_pixels_changed / 100) * w * h; | |
if (triggered) num_triggered++; | |
//free(work); | |
//free(prev_frame); | |
} | |
gettimeofday(&the_time, NULL); | |
double time_stop = the_time.tv_sec + 1e-6*the_time.tv_usec; | |
printf("%u triggered\n",num_triggered); | |
printf("%u frames in %.2f seconds\n",num_frames,time_stop-time_start); | |
printf("%.2f fps\n",1.0*num_frames/(time_stop-time_start)); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment