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

@@ -11,11 +11,14 @@ t: t.c Makefile ${DEPS} funcs.o v4l2_pr_structs.o
funcs.o: funcs.c funcs.h Makefile
gcc ${COPT} -c $<
rgb2fimg.o: rgb2fimg.c funcs.h Makefile
gcc ${COPT} -c $<
v4l2_pr_structs.o: v4l2_pr_structs.c v4l2_pr_structs.h Makefile
gcc ${COPT} -c $<
grabvidseq: grabvidseq.c Makefile
gcc -Wall -g $< ../libfloatimg.a -lv4l2 -o $@
grabvidseq: grabvidseq.c Makefile rgb2fimg.o
gcc -Wall -g $< rgb2fimg.o ../libfloatimg.a -lv4l2 -o $@
video-infos: video-infos.c Makefile funcs.o v4l2_pr_structs.o
gcc -Wall -g $< funcs.o v4l2_pr_structs.o -o $@

View File

@@ -4,4 +4,13 @@
int open_device(char *dev_name);
int init_device(int notused);
int init_device(int notused);
/* --------------------------------------------------------------------- */
int x_rgb2fimg(unsigned char *src, int w, int h, FloatImg *d);
int x_rgb2file(unsigned char *src, int w, int h, char *fname);
/* --------------------------------------------------------------------- */

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);
}

58
v4l2/rgb2fimg.c Normal file
View File

@@ -0,0 +1,58 @@
#include <stdio.h>
#include <stdlib.h>
#include "../floatimg.h"
#include "funcs.h"
/* --------------------------------------------------------------------- */
int x_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->G;
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)
{
FloatImg buff;
int foo;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %d %d '%s' )\n", __func__,
src, w, h, fname);
#endif
foo = fimg_create(&buff, w, h, FIMG_TYPE_RGB);
if (foo) {
fprintf(stderr, "Crash on create in %s %s\n", __FILE__, __func__);
exit(1);
}
foo = x_rgb2fimg(src, w, h, &buff);
if (foo) {
fprintf(stderr, "Crash on bit massage in %s %s\n", __FILE__, __func__);
exit(1);
}
foo = fimg_dump_to_file(&buff, fname, 0);
if (foo) {
fprintf(stderr, "Crash on dump in %s %s\n", __FILE__, __func__);
exit(1);
}
fimg_destroy(&buff);
return -1;
}
/* --------------------------------------------------------------------- */

View File

@@ -11,8 +11,8 @@
#include <inttypes.h>
#include <linux/videodev2.h>
#include "funcs.h"
#include "../floatimg.h"
#include "funcs.h"
#include "v4l2_pr_structs.h"

View File

@@ -175,7 +175,7 @@ char ligne[100];
struct v4l2_capability cap;
struct v4l2_format fmt;
struct v4l2_input input;
// struct v4l2_input input;
// int index;
// struct v4l2_requestbuffers reqbuf;
@@ -202,26 +202,17 @@ pr_v4l2_capability(devname, &cap);
foo = enum_inputs(vfd, "on peut voir quoi ?", 0);
/***
memset(&input, 0, sizeof(input));
input.index = 1;
if (-1 == ioctl(vfd, VIDIOC_ENUMINPUT, &input)) {
perror("VIDIOC_ENUMINPUT");
exit(EXIT_FAILURE);
}
sprintf(ligne, "input %d", input.index);
pr_v4l2_input(ligne, &input);
***/
memset(&fmt, 0, sizeof(fmt));
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
foo = ioctl(vfd, VIDIOC_G_FMT, &fmt);
fprintf(stderr, "ioctl -> %d\n", foo);
if (0 != foo) {
perror("ioctl G_FMT");
exit(1);
// exit(1);
}
else {
pr_v4l2_format("Experimental", &fmt);
}
pr_v4l2_format("Experimental", &fmt);
foo = enum_image_formats(vfd, "Experimental", 0);