From e18a303d1c17acd30c21162826c554ee770cf35a Mon Sep 17 00:00:00 2001
From: AlexeyAB <alexeyab84@gmail.com>
Date: Sat, 21 Apr 2018 12:19:58 +0000
Subject: [PATCH] Fixed utils.c for short lines.

---
 src/data.c |   18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/src/data.c b/src/data.c
index 88d5720..a9dba1d 100644
--- a/src/data.c
+++ b/src/data.c
@@ -292,7 +292,8 @@
     free(boxes);
 }
 
-void fill_truth_detection(char *path, int num_boxes, float *truth, int classes, int flip, float dx, float dy, float sx, float sy, int small_object)
+void fill_truth_detection(char *path, int num_boxes, float *truth, int classes, int flip, float dx, float dy, float sx, float sy, 
+	int small_object, int net_w, int net_h)
 {
     char labelpath[4096];
     find_replace(path, "images", "labels", labelpath);
@@ -301,15 +302,18 @@
     find_replace(labelpath, "raw", "labels", labelpath);
     find_replace(labelpath, ".jpg", ".txt", labelpath);
     find_replace(labelpath, ".png", ".txt", labelpath);
+	find_replace(labelpath, ".bmp", ".txt", labelpath);
     find_replace(labelpath, ".JPG", ".txt", labelpath);
     find_replace(labelpath, ".JPEG", ".txt", labelpath);
     int count = 0;
 	int i;
     box_label *boxes = read_boxes(labelpath, &count);
+	float lowest_w = 1.F / net_w;
+	float lowest_h = 1.F / net_h;
 	if (small_object == 1) {
 		for (i = 0; i < count; ++i) {
-			if (boxes[i].w < 0.01) boxes[i].w = 0.01;
-			if (boxes[i].h < 0.01) boxes[i].h = 0.01;
+			if (boxes[i].w < lowest_w) boxes[i].w = lowest_w;
+			if (boxes[i].h < lowest_h) boxes[i].h = lowest_h;
 		}
 	}
     randomize_boxes(boxes, count);
@@ -326,7 +330,9 @@
         id = boxes[i].id;
 
 		// not detect small objects
-		if ((w < 0.001 || h < 0.001)) continue;
+		//if ((w < 0.001F || h < 0.001F)) continue;
+		// if truth (box for object) is smaller than 1x1 pix
+		if ((w < lowest_w || h < lowest_h)) continue;
 
         truth[i*5+0] = x;
         truth[i*5+1] = y;
@@ -738,7 +744,7 @@
 		//show_image(ai, "aug");
 		//cvWaitKey(0);
 
-        fill_truth_detection(filename, boxes, d.y.vals[i], classes, flip, dx, dy, 1./sx, 1./sy, small_object);
+        fill_truth_detection(filename, boxes, d.y.vals[i], classes, flip, dx, dy, 1./sx, 1./sy, small_object, w, h);
 
 		cvReleaseImage(&src);
     }
@@ -789,7 +795,7 @@
 		random_distort_image(sized, hue, saturation, exposure);
 		d.X.vals[i] = sized.data;
 
-		fill_truth_detection(random_paths[i], boxes, d.y.vals[i], classes, flip, dx, dy, 1. / sx, 1. / sy, small_object);
+		fill_truth_detection(random_paths[i], boxes, d.y.vals[i], classes, flip, dx, dy, 1. / sx, 1. / sy, small_object, w, h);
 
 		free_image(orig);
 		free_image(cropped);

--
Gitblit v1.10.0