Skip to content

Commit 0eacaff

Browse files
committed
Add YOLO annotation out-of-bounds error tolerance.
1 parent 9727ce7 commit 0eacaff

File tree

5 files changed

+50
-1
lines changed

5 files changed

+50
-1
lines changed

src/main/java/com/github/mfl28/boundingboxeditor/model/io/YOLOLoadStrategy.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,27 @@ private BoundingBoxData parseBoundingBoxData(String line, int lineNumber) {
189189
double heightRelative = parseRatio(scanner, lineNumber);
190190

191191
double xMinRelative = xMidRelative - widthRelative / 2;
192+
if(xMinRelative < 0 && -xMinRelative < 1e-6) {
193+
xMinRelative = 0;
194+
}
192195
assertRatio(xMinRelative, INVALID_BOUNDING_BOX_COORDINATES_MESSAGE + lineNumber + ".");
193196

194197
double yMinRelative = yMidRelative - heightRelative / 2;
198+
if(yMinRelative < 0 && -yMinRelative < 1e-6) {
199+
yMinRelative = 0;
200+
}
195201
assertRatio(yMinRelative, INVALID_BOUNDING_BOX_COORDINATES_MESSAGE + lineNumber + ".");
196202

197203
double xMaxRelative = xMidRelative + widthRelative / 2;
204+
if(xMaxRelative > 1 && xMaxRelative - 1 < 1e-6) {
205+
xMaxRelative = 1;
206+
}
198207
assertRatio(xMaxRelative, INVALID_BOUNDING_BOX_COORDINATES_MESSAGE + lineNumber + ".");
199208

200209
double yMaxRelative = yMidRelative + heightRelative / 2;
210+
if(yMaxRelative > 1 && yMaxRelative - 1 < 1e-6) {
211+
yMaxRelative = 1;
212+
}
201213
assertRatio(yMaxRelative, INVALID_BOUNDING_BOX_COORDINATES_MESSAGE + lineNumber + ".");
202214

203215
String categoryName = categories.get(categoryId);

src/test/java/com/github/mfl28/boundingboxeditor/controller/AnnotationTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737
import java.io.File;
3838
import java.util.List;
39-
import java.util.Map;
4039

4140
import static org.testfx.api.FxAssert.verifyThat;
4241

src/test/java/com/github/mfl28/boundingboxeditor/controller/ControllerTests.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,41 @@ void onReloadAnnotations_afterImageFilesReopened_shouldCorrectlyDisplayBoundingS
11351135
verifyThat(mainView.getObjectTree().getRoot().getChildren(), Matchers.hasSize(0), saveScreenshot(testinfo));
11361136
}
11371137

1138+
@Test
1139+
void onLoadAnnotation_YOLO_WhenAnnotationWithinYOLOPrecision_ShouldLoadBoundingBoxes(FxRobot robot,
1140+
TestInfo testinfo) {
1141+
1142+
final String referenceAnnotationDirectoryPath = "/testannotations/yolo/precision";
1143+
1144+
waitUntilCurrentImageIsLoaded(testinfo);
1145+
WaitForAsyncUtils.waitForFxEvents();
1146+
timeOutAssertServiceSucceeded(controller.getImageMetaDataLoadingService(), testinfo);
1147+
1148+
verifyThat(mainView.getStatusBar().getCurrentEventMessage(),
1149+
Matchers.startsWith("Successfully loaded 4 image-files from folder "), saveScreenshot(testinfo));
1150+
1151+
final File referenceAnnotationFolder =
1152+
new File(getClass().getResource(referenceAnnotationDirectoryPath).getFile());
1153+
1154+
// Load bounding-boxes defined in the reference annotation-file.
1155+
Platform.runLater(() -> controller
1156+
.initiateAnnotationImport(referenceAnnotationFolder, ImageAnnotationLoadStrategy.Type.YOLO));
1157+
WaitForAsyncUtils.waitForFxEvents();
1158+
1159+
timeOutAssertServiceSucceeded(controller.getAnnotationImportService(), testinfo);
1160+
1161+
final Map<String, Integer> counts = model.getCategoryToAssignedBoundingShapesCountMap();
1162+
Assertions.assertDoesNotThrow(() -> WaitForAsyncUtils.waitFor(TIMEOUT_DURATION_IN_SEC, TimeUnit.SECONDS,
1163+
() -> Objects.equals(counts.get("Test"), 2)),
1164+
() -> saveScreenshotAndReturnMessage(testinfo, "Correct bounding box " +
1165+
"per-category-counts were not read within " +
1166+
TIMEOUT_DURATION_IN_SEC + " sec."));
1167+
1168+
verifyThat(model.getCategoryToAssignedBoundingShapesCountMap().size(), Matchers.equalTo(1),
1169+
saveScreenshot(testinfo));
1170+
verifyThat(model.getObjectCategories(), Matchers.hasSize(1), saveScreenshot(testinfo));
1171+
}
1172+
11381173
private void userChoosesNoOnAnnotationImportDialogSubtest(FxRobot robot, File annotationFile, TestInfo testinfo) {
11391174
userChoosesToSaveExistingAnnotationsOnAnnotationImport(robot, annotationFile, testinfo);
11401175
userChoosesNotToSaveExistingAnnotationsOnAnnotationImport(robot, annotationFile, testinfo);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
0 0.250000 0.250000 0.500001 0.500001
2+
0 0.750000 0.750000 0.500001 0.500001
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Test

0 commit comments

Comments
 (0)