From a2f20d7069883287f6a1bdf073c70667a91b3fbe Mon Sep 17 00:00:00 2001 From: Stefano Sinigardi Date: Sun, 27 Aug 2023 23:49:28 +0200 Subject: [PATCH] use ansi escape sequence vt100 ESC[H ESC[J to clear screen in a portable way (win10+ supported!) (#8834) --- src/art.c | 3 +-- src/classifier.c | 16 ++++------------ src/demo.c | 3 +-- src/detector.c | 7 +++---- 4 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/art.c b/src/art.c index d90290fc..748e1903 100644 --- a/src/art.c +++ b/src/art.c @@ -40,8 +40,7 @@ void demo_art(char *cfgfile, char *weightfile, int cam_index) float *p = network_predict(net, in_s.data); - printf("\033[2J"); - printf("\033[1;1H"); + printf("\033[H\033[J"); float score = 0; for(i = 0; i < n; ++i){ diff --git a/src/classifier.c b/src/classifier.c index c17e1b1f..0c81aee4 100644 --- a/src/classifier.c +++ b/src/classifier.c @@ -1129,11 +1129,8 @@ void threat_classifier(char *datacfg, char *cfgfile, char *weightfile, int cam_i sprintf(buff, "tmp/threat_%06d", count); //save_image(out, buff); -#ifndef _WIN32 - printf("\033[2J"); - printf("\033[1;1H"); -#endif - printf("\nFPS:%.0f\n",fps); + printf("\033[H\033[J"); + printf("\nFPS:%.0f\n", fps); for(i = 0; i < top; ++i){ int index = indexes[i]; @@ -1208,8 +1205,7 @@ void gun_classifier(char *datacfg, char *cfgfile, char *weightfile, int cam_inde float *predictions = network_predict(net, in_s.data); top_predictions(net, top, indexes); - printf("\033[2J"); - printf("\033[1;1H"); + printf("\033[H\033[J"); int threat = 0; for(i = 0; i < sizeof(bad_cats)/sizeof(bad_cats[0]); ++i){ @@ -1308,11 +1304,7 @@ void demo_classifier(char *datacfg, char *cfgfile, char *weightfile, int cam_ind if(net.hierarchy) hierarchy_predictions(predictions, net.outputs, net.hierarchy, 1); top_predictions(net, top, indexes); -#ifndef _WIN32 - printf("\033[2J"); - printf("\033[1;1H"); -#endif - + printf("\033[H\033[J"); if (!benchmark) { printf("\rFPS: %.2f (use -benchmark command line flag for correct measurement)\n", fps); diff --git a/src/demo.c b/src/demo.c index 2c48bb78..e9017a0b 100644 --- a/src/demo.c +++ b/src/demo.c @@ -280,8 +280,7 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int if (l.embedding_size) set_track_id(local_dets, local_nboxes, demo_thresh, l.sim_thresh, l.track_ciou_norm, l.track_history_size, l.dets_for_track, l.dets_for_show); - //printf("\033[2J"); - //printf("\033[1;1H"); + printf("\033[H\033[J"); //printf("\nFPS:%.1f\n", fps); printf("Objects:\n\n"); diff --git a/src/detector.c b/src/detector.c index 6f050986..37990631 100644 --- a/src/detector.c +++ b/src/detector.c @@ -314,14 +314,13 @@ void train_detector(char *datacfg, char *cfgfile, char *weightfile, int *gpus, i if (mean_average_precision > 0) printf("\n Last accuracy mAP@%0.2f = %2.2f %%, best = %2.2f %% ", iou_thresh, mean_average_precision * 100, best_map * 100); } - #ifndef WIN32 + printf("\033[H\033[J"); if (mean_average_precision > 0.0) { - printf("\033]2;%d/%d: loss=%0.1f map=%0.2f best=%0.2f hours left=%0.1f\007", iteration, net.max_batches, loss, mean_average_precision, best_map, avg_time); + printf("%d/%d: loss=%0.1f map=%0.2f best=%0.2f hours left=%0.1f\007", iteration, net.max_batches, loss, mean_average_precision, best_map, avg_time); } else { - printf("\033]2;%d/%d: loss=%0.1f hours left=%0.1f\007", iteration, net.max_batches, loss, avg_time); + printf("%d/%d: loss=%0.1f hours left=%0.1f\007", iteration, net.max_batches, loss, avg_time); } - #endif if (net.cudnn_half) { if (iteration < net.burn_in * 3) fprintf(stderr, "\n Tensor Cores are disabled until the first %d iterations are reached.\n", 3 * net.burn_in);