Added some constants in video.c function v4l_picture_controls() which can help

people hack an optimal set of values for controlling auto brighness for their
particular camera. For now I am do not want to add all of these to the already
too large number of motion config options. Maybe based on feedback we can
permanently change the constants and add an additional auto brightness option.
Or maybe a combined option that sets more constant based on an algoritm.
(Kenneth Lavrsen)
http://www.lavrsen.dk/twiki/bin/view/Motion/BugReport2006x02x07x212816
This commit is contained in:
KennethLavrsen
2006-02-21 08:42:45 +00:00
parent 0f807518f9
commit 81af7d9295
4 changed files with 50 additions and 12 deletions

View File

@@ -35,6 +35,14 @@
problem related to building with ffmpeg. (Angel Carpintero)
* Implemented fix for missed snapshots with slow network cameras (Kenneth Lavrsen)
http://www.lavrsen.dk/twiki/bin/view/Motion/BugReport2006x02x07x162149
* Added some constants in video.c function v4l_picture_controls() which can help
people hack an optimal set of values for controlling auto brighness for their
particular camera. For now I am do not want to add all of these to the already
too large number of motion config options. Maybe based on feedback we can
permanently change the constants and add an additional auto brightness option.
Or maybe a combined option that sets more constant based on an algoritm.
(Kenneth Lavrsen)
http://www.lavrsen.dk/twiki/bin/view/Motion/BugReport2006x02x07x212816
3.2.4 Formal Release. Summary of changes

View File

@@ -825,6 +825,14 @@ Kenneth Lavrsen (Currently project managing Motion)
http://www.lavrsen.dk/twiki/bin/view/Motion/PwcConfiguration
* Implemented fix for missed snapshots with slow network cameras
http://www.lavrsen.dk/twiki/bin/view/Motion/BugReport2006x02x07x162149
* Added some constants in video.c function v4l_picture_controls() which can help
people hack an optimal set of values for controlling auto brighness for their
particular camera. For now I am do not want to add all of these to the already
too large number of motion config options. Maybe based on feedback we can
permanently change the constants and add an additional auto brightness option.
Or maybe a combined option that sets more constant based on an algoritm.
(Kenneth Lavrsen)
http://www.lavrsen.dk/twiki/bin/view/Motion/BugReport2006x02x07x212816
Mike Lees
* Added the onffmpegclose feature.

12
alg.c
View File

@@ -194,7 +194,7 @@ void alg_draw_location(struct coord *cent, struct images *imgs, int width, unsig
#define NDIFF(x, y) (ABS(x)*NORM/(ABS(x)+2*DIFF(x,y)))
void alg_noise_tune (struct context *cnt, unsigned char *new)
void alg_noise_tune(struct context *cnt, unsigned char *new)
{
struct images *imgs=&cnt->imgs;
int i;
@@ -338,7 +338,7 @@ static int iflood(int x, int y,
return count;
}
static int alg_labeling (struct context *cnt)
static int alg_labeling(struct context *cnt)
{
struct images *imgs=&cnt->imgs;
unsigned char *out=imgs->out;
@@ -970,7 +970,7 @@ int alg_diff_standard (struct context *cnt, unsigned char *new)
Very fast diff function, does not do nightcompensation or mask
overlaying.
*/
static char alg_diff_fast (struct context *cnt, int max_n_changes, unsigned char *new)
static char alg_diff_fast(struct context *cnt, int max_n_changes, unsigned char *new)
{
struct images *imgs=&cnt->imgs;
int i, diffs=0, step=imgs->motionsize/10000;
@@ -1000,7 +1000,7 @@ static char alg_diff_fast (struct context *cnt, int max_n_changes, unsigned char
/* alg_diff uses diff_fast to quickly decide if there is anything worth
* sending to diff_standard.
*/
int alg_diff (struct context *cnt, unsigned char *new)
int alg_diff(struct context *cnt, unsigned char *new)
{
int diffs=0;
@@ -1014,7 +1014,7 @@ int alg_diff (struct context *cnt, unsigned char *new)
It is assumed to be the light being switched on or a camera displacement.
In any way the user doesn't think it is worth capturing.
*/
int alg_lightswitch (struct context *cnt, int diffs)
int alg_lightswitch(struct context *cnt, int diffs)
{
struct images *imgs=&cnt->imgs;
@@ -1030,7 +1030,7 @@ int alg_lightswitch (struct context *cnt, int diffs)
return 0;
}
int alg_switchfilter (struct context *cnt, int diffs, unsigned char *newimg)
int alg_switchfilter(struct context *cnt, int diffs, unsigned char *newimg)
{
int linediff = diffs / cnt->imgs.height;
unsigned char *out = cnt->imgs.out;

34
video.c
View File

@@ -26,6 +26,26 @@
#define MAX2(x, y) ((x) > (y) ? (x) : (y))
#define MIN2(x, y) ((x) < (y) ? (x) : (y))
/* Constants used by auto brightness feature
* Defined as constant to make it easier for people to tweak code for a
* difficult camera.
* The experience gained from people could help improving the feature without
* adding too many new options.
* AUTOBRIGHT_HYSTERESIS sets the minimum the light intensity must change before
* we adjust brigtness.
* AUTOBRIGHTS_DAMPER damps the speed with which we adjust the brightness
* When the brightness changes a lot we step in large steps and as we approach the
* target value we slow down to avoid overshoot and oscillations. If the camera
* adjusts too slowly decrease the DAMPER value. If the camera oscillates try
* increasing the DAMPER value. DAMPER must be minimum 1.
* MAX and MIN are the max and min values of brightness setting we will send to
* the camera device.
*/
#define AUTOBRIGHT_HYSTERESIS 10
#define AUTOBRIGHT_DAMPER 5
#define AUTOBRIGHT_MAX 255
#define AUTOBRIGHT_MIN 0
static void v4l_picture_controls(struct context *cnt, struct video_dev *viddev)
{
int dev = viddev->fd;
@@ -79,8 +99,8 @@ static void v4l_picture_controls(struct context *cnt, struct video_dev *viddev)
else
brightness_target = 128;
brightness_window_high = MIN2(brightness_target + 10, 255);
brightness_window_low = MAX2(brightness_target - 10, 1);
brightness_window_high = MIN2(brightness_target + AUTOBRIGHT_HYSTERESIS, 255);
brightness_window_low = MAX2(brightness_target - AUTOBRIGHT_HYSTERESIS, 1);
for (i = 0; i < cnt->imgs.motionsize; i += 101) {
avg += image[i];
@@ -96,8 +116,9 @@ static void v4l_picture_controls(struct context *cnt, struct video_dev *viddev)
}
/* average is above window - turn down brightness - go for the target */
if (avg > brightness_window_high) {
step = MIN2((avg - brightness_target)/5+1, viddev->brightness);
if (viddev->brightness > step+1) {
step = MIN2((avg - brightness_target)/AUTOBRIGHT_DAMPER + 1,
viddev->brightness - AUTOBRIGHT_MIN);
if (viddev->brightness > step + 1 - AUTOBRIGHT_MIN) {
viddev->brightness -= step;
vid_pic.brightness = viddev->brightness * 256;
make_change = 1;
@@ -105,8 +126,9 @@ static void v4l_picture_controls(struct context *cnt, struct video_dev *viddev)
}
/* average is below window - turn up brightness - go for the target */
if (avg < brightness_window_low) {
step = MIN2((brightness_target - avg)/5+1, 255 - viddev->brightness);
if (viddev->brightness < 255-step ) {
step = MIN2((brightness_target - avg)/AUTOBRIGHT_DAMPER + 1,
AUTOBRIGHT_MAX - viddev->brightness);
if (viddev->brightness < AUTOBRIGHT_MAX - step ) {
viddev->brightness += step;
vid_pic.brightness = viddev->brightness * 256;
make_change = 1;