You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
131 lines
3.4 KiB
131 lines
3.4 KiB
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <time.h>
|
|
|
|
#include "vidoiltank.h"
|
|
|
|
char conf_devname[LEN_FILENAME] = "/dev/video0";
|
|
char conf_debugout[LEN_FILENAME] = ".";
|
|
int conf_width = 1920;
|
|
int conf_height = 1080;
|
|
int conf_iomode = IOM_MMAP;
|
|
int conf_samples = 25;
|
|
int conf_rotate = 0;
|
|
Rect conf_rect = { .x = 315, .y = 0, .w = 70, .h = 1910 };
|
|
|
|
/*
|
|
* open video device
|
|
* read multiple images into memory
|
|
* close video device
|
|
*
|
|
* calculate images together
|
|
* find position
|
|
*
|
|
* save all data
|
|
*/
|
|
|
|
void help() {
|
|
printf ("\t-dev DEVICE video device file (default /dev/video0)\n");
|
|
printf ("\t-s w,h define with and height\n");
|
|
printf ("\t-debug OUTDIR debug files output dir\n");
|
|
printf ("\t-ioread use read instead of mmap\n");
|
|
printf ("\t-samples NUM samples to read\n");
|
|
printf ("\t-rect X,Y,W,H part of the screen to search for the level\n");
|
|
printf ("\t-rotate DEG rotate image by 0,90,180,270\n");
|
|
printf ("\t-help display this help\n");
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
Video *video;
|
|
ImageRaw *img = NULL;
|
|
ImageRaw *tmpimg = NULL;
|
|
ImageFloat *imgf = NULL;
|
|
char fn[3*LEN_FILENAME];
|
|
char outdate[LEN_FILENAME];
|
|
time_t curtime = time(NULL);
|
|
struct tm *curtime_tm = NULL;
|
|
int i;
|
|
|
|
// for debugging only
|
|
curtime_tm = localtime(&curtime);
|
|
strftime(outdate, LEN_FILENAME-1, "%Y%m%d-%H%M%S", curtime_tm);
|
|
|
|
for (int i = 1; i < argc; i++) {
|
|
if (strcmp(argv[i], "-dev") == 0) {
|
|
i++;
|
|
strncpy (conf_devname, argv[i], LEN_FILENAME-1);
|
|
}
|
|
else if (strcmp(argv[i], "-s") == 0){
|
|
i++;
|
|
sscanf (argv[i], "%d,%d", &conf_width, &conf_height);
|
|
}
|
|
else if (strcmp(argv[i], "-rect") == 0){
|
|
i++;
|
|
sscanf (argv[i], "%d,%d,%d,%d", &conf_rect.x, &conf_rect.y, &conf_rect.w, &conf_rect.h);
|
|
}
|
|
else if (strcmp(argv[i], "-samples") == 0){
|
|
i++;
|
|
conf_samples = atoi (argv[i]);
|
|
}
|
|
else if (strcmp(argv[i], "-debug") == 0){
|
|
i++;
|
|
strncpy (conf_debugout, argv[i], LEN_FILENAME-1);
|
|
}
|
|
else if (strcmp(argv[i], "-ioread") == 0){
|
|
conf_iomode = IOM_READ;
|
|
}
|
|
else if (strcmp(argv[i], "-rotate") == 0){
|
|
i++;
|
|
conf_rotate = atoi (argv[i]);
|
|
if (conf_rotate != 0 && conf_rotate != 90 && conf_rotate != 180 && conf_rotate != 270) {
|
|
printf ("rotate can only work for 0°, 90°, 180°, 270°. Rotation of %d° is not supported\n", conf_rotate);
|
|
return 1;
|
|
}
|
|
}
|
|
else if (strcmp(argv[i], "-help") == 0){
|
|
help();
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
// printf ("vidoiltank\n");
|
|
// printf (" device: %s (%d x %d)\n", conf_devname, conf_width, conf_height);
|
|
|
|
if ((video = vid_open("/dev/video0")) == NULL) return -1;
|
|
if (vid_start(video, conf_iomode, conf_width, conf_height) == -1) return -1;
|
|
|
|
for (i = 0; i < conf_samples; i++) {
|
|
do {} while ((tmpimg = vid_grabimage(video, img)) == NULL && errno == EAGAIN);
|
|
if (tmpimg == NULL) {
|
|
printf ("could not grab image\n");
|
|
exit(1);
|
|
}
|
|
img = tmpimg;
|
|
image_rotate(img, conf_rotate);
|
|
|
|
if (i == 0) imgf = imageF_copy(img, &conf_rect);
|
|
else {
|
|
imageF_add (imgf, img, &conf_rect);
|
|
}
|
|
|
|
if (i == 0) {
|
|
snprintf (fn, 3*LEN_FILENAME, "%s/%s-img-%02d.jpg", conf_debugout, outdate, i);
|
|
image_draw_rect(img, &conf_rect, 0x00FFFF);
|
|
image_save(img, fn, 98);
|
|
}
|
|
}
|
|
if (vid_stop(video) == -1) return -1;
|
|
vid_close(video);
|
|
video = NULL;
|
|
|
|
tmpimg = image_copyF(imgf);
|
|
snprintf (fn, 3*LEN_FILENAME, "%s/%s-imgf-%03d.jpg", conf_debugout, outdate, conf_samples);
|
|
image_save(tmpimg, fn, 98);
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
|