adding filter for the detected values.

master
Steffen Pohle 2 years ago
parent a9152e2841
commit 6a9259fe86

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

Loading…
Cancel
Save