44 lines
1.3 KiB
Dart
44 lines
1.3 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:observer/detection/detection_result.dart';
|
|
import 'package:observer/detection/nms.dart';
|
|
|
|
DetectionResult box(double l, double t, double r, double b, double score,
|
|
{String label = 'x'}) =>
|
|
DetectionResult(
|
|
label: label, score: score, left: l, top: t, right: r, bottom: b);
|
|
|
|
void main() {
|
|
test('overlappingBoxes_keepHighestScore', () {
|
|
final a = box(0.1, 0.1, 0.5, 0.5, 0.8);
|
|
final b = box(0.12, 0.12, 0.52, 0.52, 0.6);
|
|
final result = nms([a, b], 0.45);
|
|
expect(result.length, 1);
|
|
expect(result[0].score, closeTo(0.8, 1e-6));
|
|
});
|
|
|
|
test('separateBoxes_bothKept', () {
|
|
final a = box(0.1, 0.1, 0.3, 0.3, 0.8);
|
|
final b = box(0.7, 0.7, 0.9, 0.9, 0.6);
|
|
expect(nms([a, b], 0.45).length, 2);
|
|
});
|
|
|
|
test('lowScoreBox_suppressedByHigherScore', () {
|
|
final a = box(0.1, 0.1, 0.5, 0.5, 0.9);
|
|
final b = box(0.1, 0.1, 0.5, 0.5, 0.5);
|
|
final result = nms([b, a], 0.45);
|
|
expect(result.length, 1);
|
|
expect(result[0].score, greaterThan(0.5));
|
|
});
|
|
|
|
test('iou_nonOverlapping_isZero', () {
|
|
final a = box(0.0, 0.0, 0.2, 0.2, 1);
|
|
final b = box(0.8, 0.8, 1.0, 1.0, 1);
|
|
expect(iou(a, b), closeTo(0, 1e-6));
|
|
});
|
|
|
|
test('iou_identicalBoxes_isOne', () {
|
|
final a = box(0.1, 0.1, 0.5, 0.5, 1);
|
|
expect(iou(a, a), closeTo(1, 1e-6));
|
|
});
|
|
}
|