Compare commits

..

3 Commits

Author SHA1 Message Date
tth
d11947bd7c optimize cumul videograb 2019-08-15 05:50:40 +02:00
tth
4ea5294009 a little tip from paulk 2019-08-14 19:49:01 +02:00
tth
556522f647 period time now in floating point 2019-08-14 19:29:11 +02:00
4 changed files with 50 additions and 9 deletions

View File

@ -3,3 +3,13 @@
------------- -------------
------------------------------------------------------------------------
<paulk-leonov> tth: en faisant de la revue de patch sur V4L2, j'apprends
que V4L2_FMT_FLAG et V4L2_PIX_FMT_FLAG n'ont rien à voir:
le premier concerne le champ flags de la structure de l'ioctl enum_fmt
et le second le champ flag de la structure de g_fmt.

View File

@ -8,6 +8,8 @@ int init_device(int notused);
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
int x_add_rgb2fimg(unsigned char *src, int w, int h, FloatImg *d);
int x_rgb2fimg(unsigned char *src, int w, int h, FloatImg *d); int x_rgb2fimg(unsigned char *src, int w, int h, FloatImg *d);
int x_rgb2file(unsigned char *src, int w, int h, char *fname); int x_rgb2file(unsigned char *src, int w, int h, char *fname);

View File

@ -91,15 +91,15 @@ struct timeval tv;
int r, fd = -1; int r, fd = -1;
unsigned int i, n_buffers; unsigned int i, n_buffers;
char *dev_name = "/dev/video0"; char *dev_name = "/dev/video0";
char out_name[256];
FILE *fout; FILE *fout;
struct buffer *buffers; struct buffer *buffers;
int foo, bar; int foo, bar;
int period = 10; /* delai entre les captures */ double period = 10.0; /* delai entre les captures */
int nbre_capt = 1; /* nombre de captures */ int nbre_capt = 1; /* nombre de captures */
int opt; int opt;
double t_debut, t_final; double t_final;
char *dest_dir = "."; /* no trailing slash */ char *dest_dir = "."; /* no trailing slash */
char *outfile = "out.pnm"; char *outfile = "out.pnm";
@ -114,13 +114,14 @@ while ((opt = getopt(argc, argv, "d:hn:o:O:p:v")) != -1) {
case 'n': nbre_capt = atoi(optarg); break; case 'n': nbre_capt = atoi(optarg); break;
case 'O': dest_dir = optarg; break; case 'O': dest_dir = optarg; break;
case 'o': outfile = optarg; break; case 'o': outfile = optarg; break;
case 'p': period = atoi(optarg); break; case 'p': period = 1e6*atof(optarg); break;
case 'v': verbosity++; break; case 'v': verbosity++; break;
} }
} }
if (verbosity) { if (verbosity) {
fprintf(stderr, "running %s pid=%d\n", argv[0], getpid()); fprintf(stderr, "running %s pid=%d\n", argv[0], getpid());
fprintf(stderr, "period is %.3f microseconds\n", period);
} }
fd = v4l2_open(dev_name, O_RDWR | O_NONBLOCK, 0); fd = v4l2_open(dev_name, O_RDWR | O_NONBLOCK, 0);
@ -172,7 +173,7 @@ for (n_buffers = 0; n_buffers < req.count; ++n_buffers) {
} }
} }
t_debut = fimg_timer_set(0); (void)fimg_timer_set(0);
for (i = 0; i < n_buffers; ++i) { for (i = 0; i < n_buffers; ++i) {
CLEAR(buf); CLEAR(buf);
@ -218,6 +219,11 @@ for (i = 0; i < nbre_capt; i++) {
return errno; return errno;
} }
if(verbosity > 1) {
printf("%6d %9.3f\n", i, fimg_timer_get(0));
}
CLEAR(buf); CLEAR(buf);
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP; buf.memory = V4L2_MEMORY_MMAP;
@ -240,9 +246,15 @@ for (i = 0; i < nbre_capt; i++) {
#endif #endif
#if SAVE_AS_CUMUL #if SAVE_AS_CUMUL
/**
x_rgb2fimg(buffers[buf.index].start, x_rgb2fimg(buffers[buf.index].start,
fmt.fmt.pix.width, fmt.fmt.pix.height, &grab); fmt.fmt.pix.width, fmt.fmt.pix.height, &grab);
fimg_add(&grab, &cumul, &cumul); fimg_add(&grab, &cumul, &cumul);
**/
x_add_rgb2fimg(buffers[buf.index].start,
fmt.fmt.pix.width, fmt.fmt.pix.height, &cumul);
#endif #endif
#if SAVE_AS_FIMG #if SAVE_AS_FIMG
@ -253,8 +265,8 @@ for (i = 0; i < nbre_capt; i++) {
out_name); out_name);
#endif #endif
if (nbre_capt > 1 && period) { if (nbre_capt > 1 && period > 1.0) {
sleep(period); usleep(period);
} }
xioctl(fd, VIDIOC_QBUF, &buf); xioctl(fd, VIDIOC_QBUF, &buf);

View File

@ -9,11 +9,11 @@
int x_upscaler(unsigned char *src, int w, int h, FloatImg *d) int x_upscaler(unsigned char *src, int w, int h, FloatImg *d)
{ {
int x, y, xx, yy; int x, y, xx, yy;
float *rp, *gp, *bp; // float *rp, *gp, *bp;
float r, g, b; float r, g, b;
static unsigned short modz; static unsigned short modz;
rp = d->R, gp = d->G, bp = d->B; // rp = d->R, gp = d->G, bp = d->B;
for (y=0; y<h; y++) { for (y=0; y<h; y++) {
yy = (y*2) + ! (modz & 1); yy = (y*2) + ! (modz & 1);
@ -49,6 +49,23 @@ for (iter=0; iter<size; iter++) {
return 0; return 0;
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
/* --------------------------------------------------------------------- */
int x_add_rgb2fimg(unsigned char *src, int w, int h, FloatImg *d)
{
int iter, size;
float *rp, *gp, *bp;
size = w * h;
rp = d->R, gp = d->G, bp = d->B;
for (iter=0; iter<size; iter++) {
*rp++ += (float)*src++;
*gp++ += (float)*src++;
*bp++ += (float)*src++;
}
return 0;
}
int x_rgb2file(unsigned char *src, int w, int h, char *fname) int x_rgb2file(unsigned char *src, int w, int h, char *fname)
{ {
FloatImg buff; FloatImg buff;