Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelCarpintero authored and AngelCarpintero committed Aug 19, 2007
1 parent 664a72c commit 9bb0c66
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 19 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

Features
* Added the pre_capture buffer redesign to throttle load and enhance pre_capture feature.
http://www.lavrsen.dk/twiki/bin/view/Motion/PreCaptureRedesign (Dag Erlandsson)
http://www.lavrsen.dk/twiki/bin/view/Motion/PreCaptureRedesign (Dag Erlandsson).
* Added preview center feature.
http://www.lavrsen.dk/twiki/bin/view/Motion/PreviewCenter (Dag Erlandsson).

Bugfixes
* Handle mjpeg decoding and fix color issue adding mjpegtools dependecy
http://www.lavrsen.dk/twiki/bin/view/Motion/MjpegColorIssue
http://www.lavrsen.dk/twiki/bin/view/Motion/MjpegToYUV420pPatch
(Marius Rieder, Angel Carpintero).
* Fixed a problem with locate and fixed mask overlay (Dag Erlandsson)
* Fixed a problem with locate and fixed mask overlay (Dag Erlandsson).


3.2.8 Formal Release - Summary of Changes
Expand Down
2 changes: 2 additions & 0 deletions CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,8 @@ Dag Erlandsson
* Added the pre_capture buffer redesign to throttle load and enhance pre_capture feature.
http://www.lavrsen.dk/twiki/bin/view/Motion/PreCaptureRedesign
* Fixed a problem with locate and fixed mask overlay
* Added preview center feature.
http://www.lavrsen.dk/twiki/bin/view/Motion/PreviewCenter

Stephen Farrugia
* Fixing the division by zero problem.
Expand Down
3 changes: 2 additions & 1 deletion conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,10 @@ config_param config_params[] = {
"# Image File Output\n"
"############################################################\n\n"
"# Output 'normal' pictures when motion is detected (default: on)\n"
"# Valid values: on, off, first, best\n"
"# Valid values: on, off, first, best, center\n"
"# When set to 'first', only the first picture of an event is saved.\n"
"# Picture with most motion of an event is saved when set to 'best'.\n"
"# Picture with motion nearest center of picture is saved when set to 'center'.\n"
"# Can be used as preview shot for the corresponding movie.",
CONF_OFFSET(output_normal),
copy_string,
Expand Down
2 changes: 1 addition & 1 deletion event.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ static void event_image_detect(struct context *cnt, int type ATTRIBUTE_UNUSED,
char fullfilename[PATH_MAX];
char filename[PATH_MAX];

if (cnt->new_img == NEWIMG_ON) {
if (cnt->new_img & NEWIMG_ON) {
const char *jpegpath;

/* conf.jpegpath would normally be defined but if someone deleted it by control interface
Expand Down
49 changes: 38 additions & 11 deletions motion.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,16 @@ static void motion_detected(struct context *cnt, int diffs, int dev, unsigned ch
if (cnt->conf.setup_mode)
motion_log(-1, 0, "Motion detected - starting event %d", cnt->event_nr);

/* If output_normal=first save first motion frame as preview-shot */
if (cnt->new_img == NEWIMG_FIRST || cnt->new_img == NEWIMG_BEST) {
/* always save first motion frame as preview-shot */
if (cnt->new_img & (NEWIMG_FIRST | NEWIMG_BEST | NEWIMG_CENTER)) {
unsigned int distX = abs((cnt->imgs.width/2) - location->x);
unsigned int distY = abs((cnt->imgs.height/2) - location->y);

memcpy(cnt->imgs.preview_buffer, newimg, cnt->imgs.size);
cnt->preview_max = diffs;
if (cnt->locate == LOCATE_PREVIEW) {
cnt->preview_cent_dist = distX*distX + distY*distY;
/* We haven't yet draw the location on the image, do it if configured */
if (cnt->locate == LOCATE_PREVIEW || cnt->locate == LOCATE_ON) {
alg_draw_location(location, imgs, imgs->width, cnt->imgs.preview_buffer, LOCATE_NORMAL);
}
}
Expand Down Expand Up @@ -357,13 +362,34 @@ static void motion_detected(struct context *cnt, int diffs, int dev, unsigned ch
}

/* Check for most significant preview-shot when output_normal=best */
if (cnt->new_img == NEWIMG_BEST && diffs > cnt->preview_max) {
if ((cnt->new_img & NEWIMG_BEST) && (diffs > cnt->preview_max)) {
unsigned int distX = abs((cnt->imgs.width/2) - location->x);
unsigned int distY = abs((cnt->imgs.height/2) - location->y);

memcpy(cnt->imgs.preview_buffer, newimg, cnt->imgs.size);
cnt->preview_max = diffs;
if (cnt->locate == LOCATE_PREVIEW){
cnt->preview_cent_dist = distX*distX + distY*distY;
if (cnt->locate == LOCATE_PREVIEW) {
alg_draw_location(location, imgs, imgs->width, cnt->imgs.preview_buffer, LOCATE_NORMAL);
}
}
/* Check for most significant preview-shot when output_normal=center */
if ((cnt->new_img & NEWIMG_CENTER) && (diffs > 0)) {
unsigned long distance;
unsigned int distX = abs((cnt->imgs.width/2) - location->x);
unsigned int distY = abs((cnt->imgs.height/2) - location->y);

distance = distX*distX + distY*distY;
if(distance < cnt->preview_cent_dist) {
memcpy(cnt->imgs.preview_buffer, newimg, cnt->imgs.size);
cnt->preview_max = diffs;
cnt->preview_cent_dist = distance;
if (cnt->locate == LOCATE_PREVIEW) {
alg_draw_location(location, imgs, imgs->width, cnt->imgs.preview_buffer, LOCATE_NORMAL);
}

}
}

/* Limit framerate */
if (cnt->shots < conf->frame_limit) {
Expand Down Expand Up @@ -1232,7 +1258,7 @@ static void *motion_loop(void *arg)

/* Save preview_shot here at the end of event */
if (cnt->preview_max) {
preview_best(cnt);
preview_save(cnt);
cnt->preview_max = 0;
}

Expand Down Expand Up @@ -1445,12 +1471,13 @@ static void *motion_loop(void *arg)
/* Check for some config parameter changes but only every second */
if (cnt->shots == 0){
if (strcasecmp(cnt->conf.output_normal, "on") == 0)
cnt->new_img=NEWIMG_ON;
cnt->new_img = NEWIMG_ON;
else if (strcasecmp(cnt->conf.output_normal, "first") == 0)
cnt->new_img=NEWIMG_FIRST;
else if (strcasecmp(cnt->conf.output_normal, "best") == 0){
cnt->new_img=NEWIMG_BEST;
}
cnt->new_img = NEWIMG_FIRST;
else if (strcasecmp(cnt->conf.output_normal, "best") == 0)
cnt->new_img = NEWIMG_BEST;
else if (strcasecmp(cnt->conf.output_normal, "center") == 0)
cnt->new_img = NEWIMG_CENTER;
else
cnt->new_img = NEWIMG_OFF;

Expand Down
7 changes: 6 additions & 1 deletion motion.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,12 @@
#define FTYPE_MPEG_ANY (FTYPE_MPEG | FTYPE_MPEG_MOTION | FTYPE_MPEG_TIMELAPSE)
#define FTYPE_IMAGE_ANY (FTYPE_IMAGE | FTYPE_IMAGE_SNAPSHOT | FTYPE_IMAGE_MOTION)

/* What types of jpeg files do we want to have */
#define NEWIMG_OFF 0
#define NEWIMG_ON 1
#define NEWIMG_FIRST 2
#define NEWIMG_BEST 3
#define NEWIMG_BEST 4
#define NEWIMG_CENTER 8

#define LOCATE_OFF 0
#define LOCATE_ON 1
Expand Down Expand Up @@ -267,6 +269,9 @@ struct context {
struct netcam_context *netcam;
int new_img;
int preview_max; /* Stores max diff number seen in an event of output_normal==best */
/* Current preview frame, movement to img center distance
* Note Dist is calculated distX*distX + distY*distY */
unsigned long preview_cent_dist;
int locate;
struct coord location; /* coordinates for center and size of last motion detection*/
struct rotdata rotate_data; /* rotation data is thread-specific */
Expand Down
4 changes: 2 additions & 2 deletions picture.c
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,8 @@ void put_fixed_mask(struct context *cnt, const char *file)
motion_log(LOG_ERR, 0, "Please edit this file and re-run motion to enable mask feature");
}

/* save 'best' preview_shot */
void preview_best(struct context *cnt)
/* save preview_shot */
void preview_save(struct context *cnt)
{
#ifdef HAVE_FFMPEG
int use_jpegpath;
Expand Down
2 changes: 1 addition & 1 deletion picture.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ void put_picture_fd(struct context *, FILE *, unsigned char *, int);
int put_picture_memory(struct context *, unsigned char*, int, unsigned char *, int);
void put_picture(struct context *, char *, unsigned char *, int );
unsigned char *get_pgm(FILE *, int, int);
void preview_best(struct context *);
void preview_save(struct context *);

#endif /* _INCLUDE_PICTURE_H_ */

0 comments on commit 9bb0c66

Please sign in to comment.