CHDK_DE Vorschauversion  Trunk Rev. 5272
 Alle Datenstrukturen Dateien Funktionen Variablen Typdefinitionen Aufzählungen Aufzählungswerte Makrodefinitionen
motion_detector.c-Dateireferenz
#include "camera_info.h"
#include "action_stack.h"
#include "console.h"
#include "keyboard.h"
#include "clock.h"
#include "viewport.h"
#include "debug_led.h"
#include "gui.h"
#include "gui_draw.h"
#include "script_api.h"
#include "script.h"
#include "motion_detector.h"
#include "module_def.h"
#include "gui_lang.h"
+ Include-Abhängigkeitsdiagramm für motion_detector.c:

gehe zum Quellcode dieser Datei

Datenstrukturen

struct  motion_detector_s
 

Makrodefinitionen

#define MD_XY2IDX(x, y)   ((y)*motion_detector.columns+(x))
 
#define MOTION_DETECTOR_CELLS   1024
 
#define md_save_calls_history()
 
#define mx_dump_memory(x)
 

Aufzählungen

enum  {
  MD_MEASURE_MODE_U =0, MD_MEASURE_MODE_Y =1, MD_MEASURE_MODE_V =2, MD_MEASURE_MODE_R =3,
  MD_MEASURE_MODE_G =4, MD_MEASURE_MODE_B =5
}
 
enum  { MD_DO_IMMEDIATE_SHOOT =1, MD_MAKE_DEBUG_LOG_FILE =2, MD_MAKE_RAM_DUMP_FILE =4, MD_NO_SHUTTER_RELEASE_ON_SHOOT =8 }
 
enum  { MD_REGION_NONE =0, MD_REGION_INCLUDE =1, MD_REGION_EXCLUDE =2 }
 

Funktionen

static int md_detect_motion (void)
 
static void time_counter_capture (time_counter *t)
 
static int action_stack_AS_MOTION_DETECTOR ()
 
static void md_kbd_sched_immediate_shoot (int no_release)
 
static int clip (int v)
 
void md_close_motion_detector ()
 
int md_init_motion_detector (int columns, int rows, int pixel_measure_mode, int detection_timeout, int measure_interval, int threshold, int draw_grid, int clipping_region_mode, int clipping_region_column1, int clipping_region_row1, int clipping_region_column2, int clipping_region_row2, int parameters, int pixels_step, int msecs_before_trigger)
 
static int md_running ()
 
static int md_measure_y ()
 
static int md_measure_u ()
 
static int md_measure_v ()
 
static int md_measure_r ()
 
static int md_measure_g ()
 
static int md_measure_b ()
 
int md_get_cell_val (int column, int row)
 
int md_get_cell_diff (int column, int row)
 
void md_draw_grid ()
 
int _module_unloader ()
 
int _module_can_unload ()
 

Variablen

static struct motion_detector_s motion_detector
 
static unsigned char * img
 
static int x_start
 
static int x_end
 
static int x_step
 
static int y_start
 
static int y_end
 
static int y_step
 
libmotiondetect_sym _libmotiondetect
 
ModuleInfo _module_info
 

Makro-Dokumentation

#define md_save_calls_history ( )

Definiert in Zeile 430 der Datei motion_detector.c.

#define MD_XY2IDX (   x,
  y 
)    ((y)*motion_detector.columns+(x))

Definiert in Zeile 50 der Datei motion_detector.c.

#define MOTION_DETECTOR_CELLS   1024

Definiert in Zeile 78 der Datei motion_detector.c.

#define mx_dump_memory (   x)

Definiert in Zeile 431 der Datei motion_detector.c.

Dokumentation der Aufzählungstypen

anonymous enum
Aufzählungswerte
MD_MEASURE_MODE_U 
MD_MEASURE_MODE_Y 
MD_MEASURE_MODE_V 
MD_MEASURE_MODE_R 
MD_MEASURE_MODE_G 
MD_MEASURE_MODE_B 

Definiert in Zeile 52 der Datei motion_detector.c.

anonymous enum
Aufzählungswerte
MD_DO_IMMEDIATE_SHOOT 
MD_MAKE_DEBUG_LOG_FILE 
MD_MAKE_RAM_DUMP_FILE 
MD_NO_SHUTTER_RELEASE_ON_SHOOT 

Definiert in Zeile 63 der Datei motion_detector.c.

anonymous enum
Aufzählungswerte
MD_REGION_NONE 
MD_REGION_INCLUDE 
MD_REGION_EXCLUDE 

Definiert in Zeile 71 der Datei motion_detector.c.

72 {
76 };

Dokumentation der Funktionen

int _module_can_unload ( )

Definiert in Zeile 880 der Datei motion_detector.c.

int _module_unloader ( )

Definiert in Zeile 874 der Datei motion_detector.c.

875 {
877  return 0;
878 }
static int action_stack_AS_MOTION_DETECTOR ( )
static

Definiert in Zeile 135 der Datei motion_detector.c.

136 {
137  // MD testing with AF LED
139  {
140  if (camera_info.perf.af_led_on == 0)
141  {
145  }
146  else if (camera_info.perf.af_led_on > 0)
147  {
149  }
150  }
151 
152  if (md_detect_motion() == 0)
153  {
155  {
157  }
158 
159  // MD testing with AF LED
161  {
164  {
166  }
167  }
168 
169  // We need to recover the motion detector's
170  // result and push it onto the thread's stack.
172 
173  action_pop_func(0);
174  return 1;
175  }
176  return 0;
177 }
static int clip ( int  v)
static

Definiert in Zeile 200 der Datei motion_detector.c.

201 {
202  if (v<0) return 0;
203  if (v>255) return 255;
204  return v;
205 }
void md_close_motion_detector ( )

Definiert in Zeile 208 der Datei motion_detector.c.

209 {
210 }
static int md_detect_motion ( void  )
static
void md_draw_grid ( )

Definiert in Zeile 790 der Datei motion_detector.c.

791 {
792  int col, row;
793  int i;
794  char mdbuff[8];
795 
797  {
798  return;
799  }
800 
801  int xoffset = vid_get_viewport_display_xoffset(); // used when image size != viewport size
802  int yoffset = vid_get_viewport_display_yoffset(); // used when image size != viewport size
803 
804  // display area size
805  int x_size = camera_screen.width-xoffset * 2;
806  int y_size = camera_screen.height-yoffset * 2;
807 
808  // initial display offsets
809  int y_start, y_end = yoffset;
810  int x_start, x_end;
811 
812  for (i=0, row=0; row < motion_detector.rows && camera_info.state.state_kbd_script_run; row++)
813  {
814  // Calc display start and end offsets
815  y_start = y_end; // reuse last end value as new start value
816  y_end = yoffset + ((row + 1) * y_size) / motion_detector.rows;
817 
818  x_end = xoffset;
819 
820  for (col=0; col < motion_detector.columns; col++, i++)
821  {
822  // Calc display x start and end offsets
823  x_start = x_end; // reuse last end value as new start value
824  x_end = xoffset + ((col + 1) * x_size) / motion_detector.columns;
825 
826  int in_clipping_region = 0;
831  )
832  {
833  in_clipping_region = 1;
834  }
835 
836  if ((motion_detector.clipping_region_mode==MD_REGION_EXCLUDE && in_clipping_region==0) ||
837  (motion_detector.clipping_region_mode==MD_REGION_INCLUDE && in_clipping_region==1) ||
839  {
840  int diff = motion_detector.diff[i];
841 
843  if (diff > motion_detector.threshold)
844  {
846  }
847 
848  if (motion_detector.draw_grid & 2)
849  {
850  sprintf(mdbuff,"%-3d", diff);
851  draw_string(x_start+4, y_start+2, mdbuff, c);
852  }
853 
854  if (motion_detector.draw_grid & 1)
855  {
856  draw_rectangle(x_start+2, y_start+2, x_end-2, y_end-2, c, RECT_BORDER1);
857  }
858  }
859  }
860  }
861 }
int md_get_cell_diff ( int  column,
int  row 
)

Definiert in Zeile 779 der Datei motion_detector.c.

780 {
781  if ((column<1 || column > motion_detector.columns) ||
782  (row<1 || row > motion_detector.rows))
783  {
784  return 0;
785  }
786 
787  return motion_detector.diff[ MD_XY2IDX(column-1,row-1) ];
788 }
int md_get_cell_val ( int  column,
int  row 
)

Definiert in Zeile 768 der Datei motion_detector.c.

769 {
770  if ((column<1 || column > motion_detector.columns) ||
771  (row<1 || row > motion_detector.rows))
772  {
773  return 0;
774  }
775 
776  return motion_detector.prev[ MD_XY2IDX(column-1,row-1) ]/motion_detector.points ;
777 }
int md_init_motion_detector ( int  columns,
int  rows,
int  pixel_measure_mode,
int  detection_timeout,
int  measure_interval,
int  threshold,
int  draw_grid,
int  clipping_region_mode,
int  clipping_region_column1,
int  clipping_region_row1,
int  clipping_region_column2,
int  clipping_region_row2,
int  parameters,
int  pixels_step,
int  msecs_before_trigger 
)

Definiert in Zeile 213 der Datei motion_detector.c.

230 {
231 #ifdef OPT_MD_DEBUG
232  motion_detector.comp_calls_cnt=0;
233 #endif
234 
235  if( pixel_measure_mode != MD_MEASURE_MODE_Y
236  && pixel_measure_mode != MD_MEASURE_MODE_U
237  && pixel_measure_mode != MD_MEASURE_MODE_V
238  && pixel_measure_mode != MD_MEASURE_MODE_R
239  && pixel_measure_mode != MD_MEASURE_MODE_G
240  && pixel_measure_mode != MD_MEASURE_MODE_B
241  )
242  {
243  pixel_measure_mode = MD_MEASURE_MODE_Y;
244  }
245 
246  // Sanity check on grid size
247  if (columns < 1) columns = 3;
248  if (rows < 1) rows = 3;
249  // If too many grid cells, reduce larger of columns and rows until it fits
250  while ((columns * rows) > MOTION_DETECTOR_CELLS)
251  {
252  if (columns > rows) columns--;
253  else rows--;
254  }
255 
256  if(msecs_before_trigger<0)
257  {
258  msecs_before_trigger=0;
259  }
260 
261  if (pixels_step<1)
262  {
263  pixels_step=1;
264  }
265 #ifdef THUMB_FW
266  if (((pixel_measure_mode == MD_MEASURE_MODE_U) || (pixel_measure_mode == MD_MEASURE_MODE_V)) && (pixels_step < 2))
267  {
268  pixels_step = 2; //uv is sampled every 4 bytes in X, prevent double counting
269  }
270 #endif
271 
272  if(detection_timeout<0)
273  {
274  detection_timeout=0;
275  }
276 
277  if(measure_interval<0)
278  {
279  measure_interval=0;
280  }
281 
282  if(threshold<0)
283  {
284  threshold=0;
285  }
286 
287  motion_detector.msecs_before_trigger = msecs_before_trigger;
288  motion_detector.parameters = parameters;
289  motion_detector.pixels_step = pixels_step;
290  motion_detector.columns = columns;
291  motion_detector.rows = rows;
293 
294  motion_detector.pixel_measure_mode = pixel_measure_mode;
295  motion_detector.timeout = detection_timeout;
296  motion_detector.measure_interval = measure_interval;
297  motion_detector.threshold = threshold;
298  motion_detector.draw_grid = draw_grid;
299 
300  if (clipping_region_column1>clipping_region_column2)
301  {
302  motion_detector.clipping_region_column2 = clipping_region_column1;
303  motion_detector.clipping_region_column1 = clipping_region_column2;
304  }
305  else
306  {
307  motion_detector.clipping_region_column2 = clipping_region_column2;
308  motion_detector.clipping_region_column1 = clipping_region_column1;
309  }
310 
311  if (clipping_region_row1>clipping_region_row2)
312  {
313  motion_detector.clipping_region_row2 = clipping_region_row1;
314  motion_detector.clipping_region_row1 = clipping_region_row2;
315  }
316  else
317  {
318  motion_detector.clipping_region_row2 = clipping_region_row2;
319  motion_detector.clipping_region_row1 = clipping_region_row1;
320  }
321 
322  if (clipping_region_mode!=MD_REGION_NONE && clipping_region_mode!=MD_REGION_INCLUDE && clipping_region_mode!=MD_REGION_EXCLUDE)
323  {
324  clipping_region_mode=MD_REGION_NONE;
325  }
326  motion_detector.clipping_region_mode = clipping_region_mode;
327 
331 
333 
335 
336  camera_info.perf.af_led_on = 100;
339 
340  return 1;
341 }
static void md_kbd_sched_immediate_shoot ( int  no_release)
static

Definiert in Zeile 179 der Datei motion_detector.c.

180 {
181  action_pop_func(0);// REMOVE MD ITEM
182 
183  // stack operations are reversed!
184  if (!no_release) // only release shutter if allowed
185  {
187  }
190  action_push_func(action_stack_AS_MOTION_DETECTOR); // it will removed right after exit from this function
191  kbd_key_press(KEY_SHOOT_FULL); // not a stack operation... pressing right now
192 
193  // MD testing with AF LED
195  {
197  }
198 }
static int md_measure_b ( )
static

Definiert in Zeile 577 der Datei motion_detector.c.

578 {
579  register int x, y, uvx, cy, cu;
580  register int curr = 0;
581 
582  for (y=y_start; y<y_end; y+=y_step)
583  {
584  for (x=x_start; x<x_end; x+=x_step)
585  {
586  cy = img[y + x + 1];
587  // Calc offset to U & V components in uvx
588 #ifdef THUMB_FW
589  uvx = x & 0xFFFFFFFC; // U is in 1st two bytes of each 4 byte block V is in 2nd two bytes
590  cu = (int)img[y + uvx] - 128;
591 #else
592  uvx = (x&1)?x-3:x;
593  cu = (signed char)img[y + uvx];
594 #endif
595  curr += clip(((cy<<12) + cu*7258 + 2048)>>12); // B
596  }
597  }
598 
599  return curr;
600 }
static int md_measure_g ( )
static

Definiert in Zeile 550 der Datei motion_detector.c.

551 {
552  register int x, y, uvx, cy, cu, cv;
553  register int curr = 0;
554 
555  for (y=y_start; y<y_end; y+=y_step)
556  {
557  for (x=x_start; x<x_end; x+=x_step)
558  {
559  cy = img[y + x + 1];
560  // Calc offset to U & V components in uvx
561 #ifdef THUMB_FW
562  uvx = x & 0xFFFFFFFC; // U is in 1st two bytes of each 4 byte block V is in 2nd two bytes
563  cu = (int)img[y + uvx] - 128;
564  cv = (int)img[y + uvx + 2] - 128;
565 #else
566  uvx = (x&1)?x-3:x;
567  cu = (signed char)img[y + uvx];
568  cv = (signed char)img[y + uvx + 2];
569 #endif
570  curr += clip(((cy<<12) - cu*1411 - cv*2925 + 2048)>>12); // G
571  }
572  }
573 
574  return curr;
575 }
static int md_measure_r ( )
static

Definiert in Zeile 525 der Datei motion_detector.c.

526 {
527  register int x, y, uvx, cy, cv;
528  register int curr = 0;
529 
530  for (y=y_start; y<y_end; y+=y_step)
531  {
532  for (x=x_start; x<x_end; x+=x_step)
533  {
534  cy = img[y + x + 1];
535  // Calc offset to U & V components in uvx
536 #ifdef THUMB_FW
537  uvx = x & 0xFFFFFFFC; // U is in 1st two bytes of each 4 byte block V is in 2nd two bytes
538  cv = (int)img[y + uvx + 2] - 128;
539 #else
540  uvx = (x&1)?x-3:x;
541  cv = (signed char)img[y + uvx + 2];
542 #endif
543  curr += clip(((cy<<12) + cv*5743 + 2048)>>12); // R
544  }
545  }
546 
547  return curr;
548 }
static int md_measure_u ( )
static

Definiert in Zeile 479 der Datei motion_detector.c.

480 {
481  register int x, y, uvx;
482  register int curr = 0;
483 
484  for (y=y_start; y<y_end; y+=y_step)
485  {
486  for (x=x_start; x<x_end; x+=x_step)
487  {
488  // Calc offset to U & V components in uvx
489 #ifdef THUMB_FW
490  uvx = x & 0xFFFFFFFC; // U is in 1st two bytes of each 4 byte block V is in 2nd two bytes
491  curr += (int)img[y + uvx] - 128; //U
492 #else
493  uvx = (x&1)?x-3:x;
494  curr += (signed char)img[y + uvx]; //U
495 #endif
496  }
497  }
498 
499  return curr;
500 }
static int md_measure_v ( )
static

Definiert in Zeile 502 der Datei motion_detector.c.

503 {
504  register int x, y, uvx;
505  register int curr = 0;
506 
507  for (y=y_start; y<y_end; y+=y_step)
508  {
509  for (x=x_start; x<x_end; x+=x_step)
510  {
511  // Calc offset to U & V components in uvx
512 #ifdef THUMB_FW
513  uvx = x & 0xFFFFFFFC; // U is in 1st two bytes of each 4 byte block V is in 2nd two bytes
514  curr += (int)img[y + uvx + 2] - 128; //V
515 #else
516  uvx = (x&1)?x-3:x;
517  curr += (signed char)img[y + uvx + 2]; //V
518 #endif
519  }
520  }
521 
522  return curr;
523 }
static int md_measure_y ( )
static

Definiert in Zeile 463 der Datei motion_detector.c.

464 {
465  register int x, y;
466  register int curr = 0;
467 
468  for (y=y_start; y<y_end; y+=y_step)
469  {
470  for (x=x_start; x<x_end; x+=x_step)
471  {
472  curr += img[y + x + 1]; //Y always 2nd byte in each block
473  }
474  }
475 
476  return curr;
477 }
static int md_running ( )
static

Definiert in Zeile 435 der Datei motion_detector.c.

436 {
437  return motion_detector.running;
438 }
static void time_counter_capture ( time_counter t)
static

Definiert in Zeile 123 der Datei motion_detector.c.

124 {
125  t->last = get_tick_count() - t->tick_count;
126  if (t->last < t->min)
127  t->min = t->last;
128  if (t->last > t->max)
129  t->max = t->last;
130  t->sum += t->last;
131  t->count++;
132 }

Variablen-Dokumentation

unsigned char* img
static

Definiert in Zeile 441 der Datei motion_detector.c.

struct motion_detector_s motion_detector
static

Definiert in Zeile 121 der Datei motion_detector.c.

int x_end
static

Definiert in Zeile 442 der Datei motion_detector.c.

int x_start
static

Definiert in Zeile 442 der Datei motion_detector.c.

int x_step
static

Definiert in Zeile 442 der Datei motion_detector.c.

int y_end
static

Definiert in Zeile 443 der Datei motion_detector.c.

int y_start
static

Definiert in Zeile 443 der Datei motion_detector.c.

int y_step
static

Definiert in Zeile 443 der Datei motion_detector.c.