grabing floatimb picz from a webcam

This commit is contained in:
2019-08-10 18:37:52 +02:00
parent 016497c870
commit 66cd54f3c6
10 changed files with 175 additions and 32 deletions

View File

@@ -27,9 +27,23 @@
#include <libv4l2.h>
#include "../floatimg.h"
#include "funcs.h"
/* --------------------------------------------------------------------- */
/* compilation control */
#define SAVE_AS_PNM 0
#define SAVE_AS_FIMG 1
/* --------------------------------------------------------------------- */
#define CLEAR(x) memset(&(x), 0, sizeof(x))
struct buffer {
void *start;
size_t length;
@@ -81,6 +95,7 @@ char out_name[256];
FILE *fout;
struct buffer *buffers;
int foo, bar;
int period = 10; /* delai entre les captures */
int nbre_capt = 1; /* nombre de captures */
int opt;
@@ -189,9 +204,12 @@ for (i = 0; i < nbre_capt; i++) {
buf.memory = V4L2_MEMORY_MMAP;
xioctl(fd, VIDIOC_DQBUF, &buf);
#if SAVE_AS_PNM
/* at this time,we'v got a picture in-memory,
so we can blast in on storage */
sprintf(out_name, "%s/%05d.ppm", dest_dir, i);
if (verbosity > 1) fprintf(stderr, "--> %s\n", out_name);
fout = fopen(out_name, "w");
if (!fout) {
perror("Cannot open image");
@@ -202,6 +220,16 @@ for (i = 0; i < nbre_capt; i++) {
fwrite(buffers[buf.index].start, buf.bytesused, 1, fout);
fclose(fout);
#endif
#if SAVE_AS_FIMG
sprintf(out_name, "%s/%05d.fimg", dest_dir, i);
if (verbosity > 1) fprintf(stderr, "--> %s\n", out_name);
foo = x_rgb2file(buffers[buf.index].start,
fmt.fmt.pix.width, fmt.fmt.pix.height,
out_name);
#endif
if (nbre_capt > 1 && period) {
sleep(period);
}