Skip to content

Commit

Permalink
Split locate_motion into separate mode and style option.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoergWeber authored and JoergWeber committed Aug 22, 2008
1 parent de7f8ba commit b9218d9
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 138 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Features
* External pipe to allow external video encoders
http://www.lavrsen.dk/twiki/bin/view/Motion/DarkwindHackeronMotionPatching (Bill Payne, Angel Carpintero)
* Allow change/setup framerate in FreeBSD using pwcbsd. (Angel Carpintero)
* Split locate_motion into separate 'mode' and 'style' option to allow all
possible combinations. (Joerg Weber)

Bugfixes
* Fix Problem Encoding 1280x1024 resolution videos
Expand Down
2 changes: 2 additions & 0 deletions CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -1378,6 +1378,8 @@ Joerg Weber
* Improved smartmask feature: real moving objects don't trigger the mask anymore.
* Added area_detect feature.
* Add draw a RED box around the movement as default.
* Split locate_motion into separate 'mode' and 'style' option to allow all
possible combinations.

Dirk Wesenberg
* Track pan/tilt support for uvcvideo ( Michal Licko ,Dirk Wesenberg and Angel Carpintero )
Expand Down
146 changes: 47 additions & 99 deletions alg.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,24 +159,22 @@ void alg_locate_center_size(struct images *imgs, int width, int height, struct c


/* draw a box around the movement */
void alg_draw_location(struct coord *cent, struct images *imgs, int width, unsigned char *new, int mode)
void alg_draw_location(struct coord *cent, struct images *imgs, int width, unsigned char *new, int style, int mode)
{
unsigned char *out = imgs->out;
int x, y;

out = imgs->out;

/* Draw a box around the movement */
if (mode == LOCATE_BOTH) { /* both normal and motion image gets a box */
/* debug image always gets a 'normal' box */
if (mode == LOCATE_BOTH) {
int width_miny = width * cent->miny;
int width_maxy = width * cent->maxy;

for (x = cent->minx; x <= cent->maxx; x++) {
int width_miny_x = x + width_miny;
int width_maxy_x = x + width_maxy;

new[width_miny_x] =~new[width_miny_x];
new[width_maxy_x] =~new[width_maxy_x];
out[width_miny_x] =~out[width_miny_x];
out[width_maxy_x] =~out[width_maxy_x];
}
Expand All @@ -185,50 +183,47 @@ void alg_draw_location(struct coord *cent, struct images *imgs, int width, unsig
int width_minx_y = cent->minx + y * width;
int width_maxx_y = cent->maxx + y * width;

new[width_minx_y] =~new[width_minx_y];
new[width_maxx_y] =~new[width_maxx_y];
out[width_minx_y] =~out[width_minx_y];
out[width_maxx_y] =~out[width_maxx_y];
}

} else if (mode == LOCATE_CENTER) {
int centy = cent->y * width;

for (x = cent->x - 10; x <= cent->x + 10; x++) {
new[centy + x] =~new[centy + x];
out[centy + x] =~out[centy + x];
}

for (y = cent->y - 10; y <= cent->y + 10; y++) {
new[cent->x + y * width] =~new[cent->x + y * width];
out[cent->x + y * width] =~out[cent->x + y * width];
}

} else { /* normal image only (e.g. preview shot) */
}
if (style == LOCATE_BOX) { /* draw a box on normal images */
int width_miny = width * cent->miny;
int width_maxy = width * cent->maxy;

for (x = cent->minx; x <= cent->maxx; x++) {
int width_miny_x = width_miny + x;
int width_maxy_x = width_maxy + x;
int width_miny_x = x + width_miny;
int width_maxy_x = x + width_maxy;

new[width_miny_x] =~new[width_miny_x];
new[width_maxy_x] =~new[width_maxy_x];
}

for (y = cent->miny; y <= cent->maxy; y++) {
int minx_y = cent->minx + y * width;
int maxx_y = cent->maxx + y * width;
int width_minx_y = cent->minx + y * width;
int width_maxx_y = cent->maxx + y * width;

new[minx_y] =~new[minx_y];
new[maxx_y] =~new[maxx_y];
new[width_minx_y] =~new[width_minx_y];
new[width_maxx_y] =~new[width_maxx_y];
}
} else if (style == LOCATE_CROSS) { /* draw a cross on normal images */
int centy = cent->y * width;

for (x = cent->x - 10; x <= cent->x + 10; x++) {
new[centy + x] =~new[centy + x];
out[centy + x] =~out[centy + x];
}

for (y = cent->y - 10; y <= cent->y + 10; y++) {
new[cent->x + y * width] =~new[cent->x + y * width];
out[cent->x + y * width] =~out[cent->x + y * width];
}
}
}


/* draw a RED box around the movement */
void alg_draw_red_location(struct coord *cent, struct images *imgs, int width, unsigned char *new, int mode)
void alg_draw_red_location(struct coord *cent, struct images *imgs, int width, unsigned char *new, int style, int mode)
{
unsigned char *out = imgs->out;
unsigned char *new_u, *new_v;
Expand All @@ -242,8 +237,28 @@ void alg_draw_red_location(struct coord *cent, struct images *imgs, int width, u
new_u = new + x;
new_v = new + v;

/* Draw a box around the movement */
if (mode == LOCATE_BOTH) { /* both normal and motion image gets a box */
/* debug image always gets a 'normal' box */
if (mode == LOCATE_BOTH) {
int width_miny = width * cent->miny;
int width_maxy = width * cent->maxy;

for (x = cent->minx; x <= cent->maxx; x++) {
int width_miny_x = x + width_miny;
int width_maxy_x = x + width_maxy;

out[width_miny_x] =~out[width_miny_x];
out[width_maxy_x] =~out[width_maxy_x];
}

for (y = cent->miny; y <= cent->maxy; y++) {
int width_minx_y = cent->minx + y * width;
int width_maxx_y = cent->maxx + y * width;

out[width_minx_y] =~out[width_minx_y];
out[width_maxx_y] =~out[width_maxx_y];
}
}
if (style == LOCATE_REDBOX) { /* draw a red box on normal images */
int width_miny = width * cent->miny;
int width_maxy = width * cent->maxy;
int cwidth_miny = cwidth * (cent->miny / 2);
Expand Down Expand Up @@ -271,11 +286,6 @@ void alg_draw_red_location(struct coord *cent, struct images *imgs, int width, u

new[width_miny_x + 1 + width] = 128;
new[width_maxy_x + 1 + width] = 128;

out[width_miny_x] =~out[width_miny_x];
out[width_maxy_x + width] =~out[width_maxy_x + width];
out[width_miny_x + 1] =~out[width_miny_x + 1];
out[width_maxy_x + 1 + width] =~out[width_maxy_x + 1 + width];
}

for (y = cent->miny; y <= cent->maxy; y += 2) {
Expand All @@ -300,14 +310,8 @@ void alg_draw_red_location(struct coord *cent, struct images *imgs, int width, u

new[width_minx_y + width + 1] = 128;
new[width_maxx_y + width + 1] = 128;

out[width_minx_y + 1] =~out[width_minx_y + 1];
out[width_maxx_y] =~out[width_maxx_y];
out[width_minx_y + width + 1] =~out[width_minx_y + width + 1];
out[width_maxx_y + width] =~out[width_maxx_y + width];
}

} else if (mode == LOCATE_CENTER) {
} else if (style == LOCATE_REDCROSS) { /* draw a red cross on normal images */
int cwidth_maxy = cwidth * (cent->y / 2);

for (x = cent->x - 10; x <= cent->x + 10; x += 2) {
Expand All @@ -323,66 +327,10 @@ void alg_draw_red_location(struct coord *cent, struct images *imgs, int width, u
new_u[cwidth_minx_y] = 128;
new_v[cwidth_minx_y] = 255;
}


} else { /* normal image only (e.g. preview shot) */
int width_miny = width * cent->miny;
int width_maxy = width * cent->maxy;
int cwidth_miny = cwidth * (cent->miny / 2);
int cwidth_maxy = cwidth * (cent->maxy / 2);

for (x = cent->minx + 2; x <= cent->maxx - 2; x += 2) {
int width_miny_x = x + width_miny;
int width_maxy_x = x + width_maxy;
int cwidth_miny_x = x / 2 + cwidth_miny;
int cwidth_maxy_x = x / 2 + cwidth_maxy;

new_u[cwidth_miny_x] = 128;
new_u[cwidth_maxy_x] = 128;
new_v[cwidth_miny_x] = 255;
new_v[cwidth_maxy_x] = 255;

new[width_miny_x] = 128;
new[width_maxy_x] = 128;

new[width_miny_x + 1] = 128;
new[width_maxy_x + 1] = 128;

new[width_miny_x + width] = 128;
new[width_maxy_x + width] = 128;

new[width_miny_x + 1 + width] = 128;
new[width_maxy_x + 1 + width] = 128;
}

for (y = cent->miny; y <= cent->maxy; y += 2) {
int width_minx_y = cent->minx + y * width;
int width_maxx_y = cent->maxx + y * width;
int cwidth_minx_y = (cent->minx / 2) + (y / 2) * cwidth;
int cwidth_maxx_y = (cent->maxx / 2) + (y / 2) * cwidth;

new_u[cwidth_minx_y] = 128;
new_u[cwidth_maxx_y] = 128;
new_v[cwidth_minx_y] = 255;
new_v[cwidth_maxx_y] = 255;

new[width_minx_y] = 128;
new[width_maxx_y] = 128;

new[width_minx_y + width] = 128;
new[width_maxx_y + width] = 128;

new[width_minx_y + 1] = 128;
new[width_maxx_y + 1] = 128;

new[width_minx_y + width + 1] = 128;
new[width_maxx_y + width + 1] = 128;
}
}
}



#define NORM 100
#define ABS(x) ((x) < 0 ? -(x) : (x))
#define DIFF(x, y) (ABS((x)-(y)))
Expand Down
4 changes: 2 additions & 2 deletions alg.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ struct segment {
};

void alg_locate_center_size(struct images *, int width, int height, struct coord *);
void alg_draw_location(struct coord *, struct images *, int width, unsigned char *, int);
void alg_draw_red_location(struct coord *, struct images *, int width, unsigned char *, int);
void alg_draw_location(struct coord *, struct images *, int width, unsigned char *, int, int);
void alg_draw_red_location(struct coord *, struct images *, int width, unsigned char *, int, int);
int alg_diff(struct context *, unsigned char *);
int alg_diff_standard(struct context *, unsigned char *);
int alg_lightswitch(struct context *, int diffs);
Expand Down
25 changes: 18 additions & 7 deletions conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ struct config conf_template = {
event_gap: DEF_EVENT_GAP,
max_movie_time: DEF_MAXMOVIETIME,
snapshot_interval: 0,
locate_motion: "off",
locate_motion_mode: "off",
locate_motion_style: "box",
input: IN_DEFAULT,
norm: 0,
frame_limit: DEF_MAXFRAMERATE,
Expand Down Expand Up @@ -754,7 +755,7 @@ config_param config_params[] = {
print_int
},
{
"locate_motion",
"locate_motion_mode",
"\n############################################################\n"
"# Text Display\n"
"# %Y = year, %m = month, %d = date,\n"
Expand All @@ -768,13 +769,23 @@ config_param config_params[] = {
"# leading spaces\n"
"############################################################\n\n"
"# Locate and draw a box around the moving object.\n"
"# Valid values: on, off, red, preview, center, center_red (default: off)\n"
"# Set to 'redbox' will draw a red box around the moving object.\n"
"# Set to 'preview' will only draw a box in preview_shot pictures.\n"
"# Set to 'center' will draw a little cross to mark center.\n"
"# Valid values: on, off, preview (default: off)\n"
"# Set to 'preview' will only draw a box in preview_shot pictures.",
0,
CONF_OFFSET(locate_motion_mode),
copy_string,
print_string
},
{
"locate_motion_style",
"# Set the look and style of the locate box if enabled.\n"
"# Valid values: box, redbox, cross, redcross (default: box)\n"
"# Set to 'box' will draw the traditional box.\n"
"# Set to 'redbox' will draw a red box.\n"
"# Set to 'cross' will draw a little cross to mark center.\n"
"# Set to 'redcross' will draw a little red cross to mark center.",
0,
CONF_OFFSET(locate_motion),
CONF_OFFSET(locate_motion_style),
copy_string,
print_string
},
Expand Down
3 changes: 2 additions & 1 deletion conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ struct config {
int event_gap;
int max_movie_time;
int snapshot_interval;
const char *locate_motion;
const char *locate_motion_mode;
const char *locate_motion_style;
int input;
int norm;
int frame_limit;
Expand Down
60 changes: 37 additions & 23 deletions motion.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,17 @@ static void image_save_as_preview(struct context *cnt, struct image_data *img)
if (cnt->imgs.preview_image.diffs == 0)
cnt->imgs.preview_image.diffs = 1;

/* If we have locate on it is already done */
if (cnt->locate_motion == LOCATE_PREVIEW)
alg_draw_red_location(&img->location, &cnt->imgs, cnt->imgs.width, cnt->imgs.preview_image.image, LOCATE_NORMAL);

/* draw locate box here when mode = LOCATE_PREVIEW */
if (cnt->locate_motion_mode == LOCATE_PREVIEW) {
if (cnt->locate_motion_style == LOCATE_BOX)
alg_draw_location(&img->location, &cnt->imgs, cnt->imgs.width, cnt->imgs.preview_image.image, LOCATE_BOX, LOCATE_NORMAL);
else if (cnt->locate_motion_style == LOCATE_REDBOX)
alg_draw_red_location(&img->location, &cnt->imgs, cnt->imgs.width, cnt->imgs.preview_image.image, LOCATE_REDBOX, LOCATE_NORMAL);
else if (cnt->locate_motion_style == LOCATE_CROSS)
alg_draw_location(&img->location, &cnt->imgs, cnt->imgs.width, cnt->imgs.preview_image.image, LOCATE_CROSS, LOCATE_NORMAL);
else if (cnt->locate_motion_style == LOCATE_REDCROSS)
alg_draw_red_location(&img->location, &cnt->imgs, cnt->imgs.width, cnt->imgs.preview_image.image, LOCATE_REDCROSS, LOCATE_NORMAL);
}
}

/**
Expand Down Expand Up @@ -383,14 +390,16 @@ static void motion_detected(struct context *cnt, int dev, struct image_data *img
struct coord *location = &img->location;

/* Draw location */
if (cnt->locate_motion == LOCATE_ON)
alg_draw_location(location, imgs, imgs->width, img->image, LOCATE_BOTH);
else if (cnt->locate_motion == LOCATE_REDBOX)
alg_draw_red_location(location, imgs, imgs->width, img->image, LOCATE_BOTH);
else if (cnt->locate_motion == LOCATE_CENTER)
alg_draw_location(location, imgs, imgs->width, img->image, LOCATE_CENTER);
else if (cnt->locate_motion == LOCATE_REDCROSS)
alg_draw_red_location(location, imgs, imgs->width, img->image, LOCATE_CENTER);
if (cnt->locate_motion_mode == LOCATE_ON) {
if (cnt->locate_motion_style == LOCATE_BOX)
alg_draw_location(location, imgs, imgs->width, img->image, LOCATE_BOX, LOCATE_BOTH);
else if (cnt->locate_motion_style == LOCATE_REDBOX)
alg_draw_red_location(location, imgs, imgs->width, img->image, LOCATE_REDBOX, LOCATE_BOTH);
else if (cnt->locate_motion_style == LOCATE_CROSS)
alg_draw_location(location, imgs, imgs->width, img->image, LOCATE_CROSS, LOCATE_BOTH);
else if (cnt->locate_motion_style == LOCATE_REDCROSS)
alg_draw_red_location(location, imgs, imgs->width, img->image, LOCATE_REDCROSS, LOCATE_BOTH);
}

/* Calculate how centric motion is if configured preview center*/
if (cnt->new_img & NEWIMG_CENTER) {
Expand Down Expand Up @@ -1901,18 +1910,23 @@ static void *motion_loop(void *arg)
else
cnt->new_img = NEWIMG_OFF;

if (strcasecmp(cnt->conf.locate_motion, "on") == 0)
cnt->locate_motion = LOCATE_ON;
else if (strcasecmp(cnt->conf.locate_motion, "redbox") == 0)
cnt->locate_motion = LOCATE_REDBOX;
else if (strcasecmp(cnt->conf.locate_motion, "center") == 0)
cnt->locate_motion = LOCATE_CENTER;
else if (strcasecmp(cnt->conf.locate_motion, "redcross") == 0)
cnt->locate_motion = LOCATE_REDCROSS;
else if (strcasecmp(cnt->conf.locate_motion, "preview") == 0)
cnt->locate_motion = LOCATE_PREVIEW;
if (strcasecmp(cnt->conf.locate_motion_mode, "on") == 0)
cnt->locate_motion_mode = LOCATE_ON;
else if (strcasecmp(cnt->conf.locate_motion_mode, "preview") == 0)
cnt->locate_motion_mode = LOCATE_PREVIEW;
else
cnt->locate_motion = LOCATE_OFF;
cnt->locate_motion_mode = LOCATE_OFF;

if (strcasecmp(cnt->conf.locate_motion_style, "box") == 0)
cnt->locate_motion_style = LOCATE_BOX;
else if (strcasecmp(cnt->conf.locate_motion_style, "redbox") == 0)
cnt->locate_motion_style = LOCATE_REDBOX;
else if (strcasecmp(cnt->conf.locate_motion_style, "cross") == 0)
cnt->locate_motion_style = LOCATE_CROSS;
else if (strcasecmp(cnt->conf.locate_motion_style, "redcross") == 0)
cnt->locate_motion_style = LOCATE_REDCROSS;
else
cnt->locate_motion_style = LOCATE_BOX;

/* Sanity check for smart_mask_speed, silly value disables smart mask */
if (cnt->conf.smart_mask_speed < 0 || cnt->conf.smart_mask_speed > 10)
Expand Down
Loading

0 comments on commit b9218d9

Please sign in to comment.