void check_area_motion(Area *area) { // printf("FRAME: check motion in area id #%d...\n", area->id); area->trig = 0; bool debug = false;// area->id == 1; // for directional support compare diff against x/y-offset average images and pick the one with least diff. int diff_sum = 0; for(int j=0; j<area->height; j++) { int o = ((area->y + j) * frame_width + area->x) * 3; for(int i=0; i<area->width; i++) { diff_sum += (diff_frame[o] + diff_frame[o+1] + diff_frame[o+2]) / 3; // diff_sum += (current_frame[o] - average_frame[o]); if (debug) { int sh = (diff_frame[o] * 7) / 255; printf("%c", shades[sh]); } o += 3; } if (debug) printf("\n"); } area->value = diff_sum; int diff_max = area->width * area->height * 255; area->percent_motion = 100.0f * (float)diff_sum / (float)diff_max; if (area->percent_motion > area->treshold_percent) { double t = current_time(); if (t > area->lasttrig + area->mininterval) { area->trig = 1; area->lasttrig = t; } } for(int i=99; i>=1; i--) { area->percent_history[i] = area->percent_history[i-1]; area->trig_history[i] = area->trig_history[i-1]; } area->percent_history[0] = area->percent_motion; area->trig_history[0] = area->trig; if (area->trig) { // printf("MOTION: area triggered - diff_sum=%6d/%6d percent=%1.2f %1.2f\n", diff_sum, diff_max, area->percent_motion, area->treshold_percent); osc_send(area->message, area->percent_motion - area->treshold_percent); } }
int osc_client( int port) { char sport[8]; int msg_size = 32; char msg[msg_size]; int get_vector = 0; int send_vector = 0; if( !port) { printf("[OSC CLIENT] No valid port\n"); return 0; } else { snprintf( sport, 8, "%d", port); printf("[OSC CLIENT] Init server at %d\n", port); } while( 1) { if( get_vector) { printf("vector:"); get_vector = 0; send_vector = 1; } else { printf("msg:"); } scanf( "%31s", msg); if( is( msg, "q")) { osc_send_quit( sport); return 1; } else if( is( msg, "vector")) get_vector = 1; if( get_vector) { } else if( send_vector) { osc_send_vector( sport, msg); send_vector = 0; } else { printf("quad!!\n"); osc_send( sport, "/quad", "iffff", 1, .1, .2, .3, .4); } usleep(1000); } return 1; }