Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin M. Schwartz <bens@alum.mit.edu>2010-07-26 01:51:37 (GMT)
committer Benjamin M. Schwartz <bens@alum.mit.edu>2010-07-26 01:51:37 (GMT)
commitc578bebe27b5fd069886ce898e58961fe47c35ca (patch)
tree92e6edd8d2a7de7e38f55a100d72e22e6bb12b01
parent4bf29465b1956d7069e0f20c37db9a228a06c663 (diff)
Add warmup period. A bug in XO-1.5 seems to make it produce rows of length 1280 instead of 640. We adjust to this by introducing "bytesperline", which is used in place of "width".HEADmaster
-rw-r--r--capture.c30
1 files changed, 24 insertions, 6 deletions
diff --git a/capture.c b/capture.c
index 9cc43d5..fda01d4 100644
--- a/capture.c
+++ b/capture.c
@@ -46,6 +46,8 @@ static unsigned int n_buffers = 0;
FILE * output_file = NULL;
static unsigned int width = 640;
static unsigned int height = 480;
+static int remember = 0; /* boolean flag for recording */
+static int bytesperline = 0;
static void
errno_exit (const char * s)
@@ -88,11 +90,11 @@ process_image (const void * p)
{
fputc ('.', stdout);
fflush (stdout);
- if (output_file) {
+ if (remember && output_file) {
/* Write a portable graymap (PGM) binary file.
If num_frames > 1, all the files will be concatenated. */
- fprintf(output_file, "P5\n%d %d %d\n", width, height, 255);
- fwrite(p, 1, width*height, output_file);
+ fprintf(output_file, "P5\n%d %d %d\n", bytesperline, height, 255);
+ fwrite(p, 1, bytesperline*height, output_file);
}
}
@@ -542,14 +544,19 @@ init_device (void)
/* Note VIDIOC_S_FMT may change width and height. */
+ fprintf(stderr, "Image has total size %d with %d bytes per line\n", fmt.fmt.pix.sizeimage, fmt.fmt.pix.bytesperline);
+
+ /* Remember the number of bytes per line for use in the PGM writer */
+ bytesperline = fmt.fmt.pix.bytesperline;
+
/* Buggy driver paranoia. */
- min = fmt.fmt.pix.width * 2;
+ min = fmt.fmt.pix.width;
if (fmt.fmt.pix.bytesperline < min)
fmt.fmt.pix.bytesperline = min;
min = fmt.fmt.pix.bytesperline * fmt.fmt.pix.height;
if (fmt.fmt.pix.sizeimage < min)
fmt.fmt.pix.sizeimage = min;
-
+
switch (io) {
case IO_METHOD_READ:
init_read (fmt.fmt.pix.sizeimage);
@@ -613,13 +620,14 @@ usage (FILE * fp,
"-r | --read Use read() calls\n"
"-u | --userp Use application allocated buffers\n"
"-n | --numframes Number of frames to acquire (default=1)\n"
+ "-w | --warmup Number of warmup frames to require before acquisition.\n"
"-f | --framerate Frame rate at which to acquire (default: unspecified)\n"
"-o | --outfile File in which to dump frames as cat'd PGM\n"
"",
argv[0]);
}
-static const char short_options [] = "d:hmrun:f:o:";
+static const char short_options [] = "d:hmrun:w:f:o:";
static const struct option
long_options [] = {
@@ -629,6 +637,7 @@ long_options [] = {
{ "read", no_argument, NULL, 'r' },
{ "userp", no_argument, NULL, 'u' },
{ "numframes", required_argument, NULL, 'n' },
+ { "warmup", required_argument, NULL, 'w' },
{ "framerate", required_argument, NULL, 'f' },
{ "outfile", required_argument, NULL, 'o' },
{ 0, 0, 0, 0 }
@@ -640,6 +649,7 @@ main (int argc,
{
dev_name = "/dev/video";
unsigned int numframes = 1;
+ unsigned int warmup = 0;
unsigned int framerate = 0;
for (;;) {
@@ -681,6 +691,10 @@ main (int argc,
numframes = atoi(optarg);
break;
+ case 'w':
+ warmup = atoi(optarg);
+ break;
+
case 'f':
framerate = atoi(optarg);
break;
@@ -708,6 +722,10 @@ main (int argc,
if (framerate > 0) set_framerate(1, framerate);
+ remember = 0;
+ mainloop (warmup);
+
+ remember = 1;
mainloop (numframes);
stop_capturing ();