|
|
|
@ -15,6 +15,7 @@ int conf_width = 1920;
|
|
|
|
|
int conf_height = 1080;
|
|
|
|
|
int conf_iomode = IOM_MMAP;
|
|
|
|
|
int conf_samples = 25;
|
|
|
|
|
float conf_filter = 0.1;
|
|
|
|
|
int conf_rotate = 0;
|
|
|
|
|
Rect conf_rect = { .x = 315, .y = 0, .w = 70, .h = 1910 };
|
|
|
|
|
char conf_outdate[LEN_FILENAME];
|
|
|
|
@ -38,6 +39,7 @@ void help() {
|
|
|
|
|
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-filter NUM filter over NUM lines for detection\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");
|
|
|
|
@ -74,6 +76,10 @@ int main(int argc, char **argv) {
|
|
|
|
|
i++;
|
|
|
|
|
conf_samples = atoi (argv[i]);
|
|
|
|
|
}
|
|
|
|
|
else if (strcmp(argv[i], "-filter") == 0){
|
|
|
|
|
i++;
|
|
|
|
|
conf_filter = 1.0/(float)atoi (argv[i]);
|
|
|
|
|
}
|
|
|
|
|
else if (strcmp(argv[i], "-debug") == 0){
|
|
|
|
|
i++;
|
|
|
|
|
strncpy (conf_debugout, argv[i], LEN_FILENAME-1);
|
|
|
|
@ -176,12 +182,15 @@ int detect_level(ImageFloat *imgf) {
|
|
|
|
|
int y, x, level;
|
|
|
|
|
float v = 0.0, vmin, vmax;
|
|
|
|
|
FILE * outfile;
|
|
|
|
|
float deltamin = 0, deltamax = 0;
|
|
|
|
|
int deltamin_y = 0, deltamax_y = 0;
|
|
|
|
|
float deltamin = 0;
|
|
|
|
|
float deltamax = 0;
|
|
|
|
|
int deltamin_y = 0;
|
|
|
|
|
int deltamax_y = 0;
|
|
|
|
|
|
|
|
|
|
if (imgf == NULL) return -1;
|
|
|
|
|
|
|
|
|
|
float *deltas = malloc(sizeof(float) * imgf->h);
|
|
|
|
|
float *deltas = malloc(sizeof(float) * imgf->h); // deltas
|
|
|
|
|
float *deltasf = malloc(sizeof(float) * imgf->h); // filtered deltas
|
|
|
|
|
if (deltas == NULL) {
|
|
|
|
|
printf ("%s:%d could not allocate memory. Error:%s\n", __FILE__, __LINE__, strerror(errno));
|
|
|
|
|
return -1;
|
|
|
|
@ -214,33 +223,40 @@ int detect_level(ImageFloat *imgf) {
|
|
|
|
|
|
|
|
|
|
// generate average and delta
|
|
|
|
|
level = 0;
|
|
|
|
|
float delta = 0.0;
|
|
|
|
|
float delta = 0.0, deltaf = 0.0;
|
|
|
|
|
for (y = 0; y < imgf->h; y++) {
|
|
|
|
|
// average
|
|
|
|
|
v = 0.0;
|
|
|
|
|
for (x = 0; x < imgf->w; x++) v += imgf->data[x + (y) * imgf->w];
|
|
|
|
|
v /= (float)imgf->h;
|
|
|
|
|
v /= (float)imgf->w;
|
|
|
|
|
|
|
|
|
|
// output
|
|
|
|
|
for (x = 0; x < outavg_with; x++) imgf->data[x + (y) * imgf->w] = v;
|
|
|
|
|
|
|
|
|
|
// delta
|
|
|
|
|
if (y > 0) delta = imgf->data[0 + y * imgf->w] - imgf->data[0 + (y-1) * imgf->w];
|
|
|
|
|
if (y > 0) {
|
|
|
|
|
delta = imgf->data[0 + y * imgf->w] - imgf->data[0 + (y-1) * imgf->w];
|
|
|
|
|
deltaf = deltasf[y-1] * (1.0-conf_filter) + delta * conf_filter;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
delta = 0.0;
|
|
|
|
|
deltamin_y = 0;
|
|
|
|
|
deltamax_y = 0;
|
|
|
|
|
deltamin = delta;
|
|
|
|
|
deltamax = delta;
|
|
|
|
|
deltas[0] = delta;
|
|
|
|
|
deltasf[0] = delta;
|
|
|
|
|
}
|
|
|
|
|
if (deltamin > delta) {
|
|
|
|
|
deltamin = delta;
|
|
|
|
|
if (deltamin > deltaf) {
|
|
|
|
|
deltamin = deltaf;
|
|
|
|
|
deltamin_y = y;
|
|
|
|
|
}
|
|
|
|
|
if (deltamax > delta) {
|
|
|
|
|
deltamax = delta;
|
|
|
|
|
if (deltamax > deltaf) {
|
|
|
|
|
deltamax = deltaf;
|
|
|
|
|
deltamax_y = y;
|
|
|
|
|
}
|
|
|
|
|
deltas[y] = delta;
|
|
|
|
|
deltasf[y] = deltaf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// debugging write output
|
|
|
|
@ -252,7 +268,7 @@ int detect_level(ImageFloat *imgf) {
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
for (y = 0; y < imgf->h; y++) {
|
|
|
|
|
fprintf(outfile, "%05d\t%f\t%f\n", y, imgf->data[y * imgf->w], deltas[y]);
|
|
|
|
|
fprintf(outfile, "%05d\t%f\t%f\t%f\n", y, imgf->data[y * imgf->w], deltas[y], deltasf[y]);
|
|
|
|
|
}
|
|
|
|
|
fclose (outfile);
|
|
|
|
|
}
|
|
|
|
@ -262,6 +278,7 @@ int detect_level(ImageFloat *imgf) {
|
|
|
|
|
level = deltamin_y;
|
|
|
|
|
|
|
|
|
|
free(deltas);
|
|
|
|
|
free(deltasf);
|
|
|
|
|
return level;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|