-
Notifications
You must be signed in to change notification settings - Fork 2
/
m_move.c
47 lines (40 loc) · 1.3 KB
/
m_move.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "m_move.h"
#include "m_file.h"
#include "m_options.h"
//#define MAX_NAME_SIZE 64
void open_new_file_handle(USERDATA_T *callback, char* name)
{
vcos_assert((callback->file_handle = fopen(output_file_name, "wb")) != NULL);
}
void* init_tmp_buffer(const void* data, int frame_sz){
void* new_buff = (void *)malloc(frame_sz);
if (new_buff == NULL) exit(1);
update_tmp_buff(data, new_buff, frame_sz);
fprintf(stderr,"Initializing buffer with size %u\n", frame_sz);
return new_buff;
}
void update_tmp_buff(const void* data, void* buff, unsigned frame_sz){
memcpy(buff, data, frame_sz);
}
/*Compare images, uses the green channel and compares every 10 pixels*/
unsigned movement_detected(MMAL_BUFFER_HEADER_T *buffer, void* buff_tmp_data) {
unsigned moved=0;
unsigned counter = buffer->length;
char *a=(char*)buff_tmp_data+buffer->length-1;
char *b=(char*)buffer->data+buffer->length-1;
char *buff=(char*)buff_tmp_data;
for (; a > buff ; a-=30, b-=30){
if (abs((*a) - (*b)) > threshold)
{
fprintf(stderr,"Movement detected - %d - %d = %d\n", *a, *b, *a - *b);
moved = 1;
break;
}
}
update_tmp_buff(buffer->data, buff_tmp_data, buffer->length);
return moved;
}