Groot 7 months ago
parent
commit
8106cdb3a8
2 changed files with 37 additions and 22 deletions
  1. 28 13
      example/lib/main.dart
  2. 9 9
      lib/models.dart

+ 28 - 13
example/lib/main.dart

@@ -20,7 +20,10 @@ class _MyAppState extends State<MyApp> {
   bool _hasPermission = false;
   bool _hasPermission = false;
   StreamSubscription<ClassificationEvent?>? _subscription;
   StreamSubscription<ClassificationEvent?>? _subscription;
   ClassificationProgress? _progress;
   ClassificationProgress? _progress;
-  ClassificationResult? _result;
+  List<ClassifiedImageGroup> _similarResult = [];
+  List<ClassifiedImage> _peopleResult = [];
+  List<ClassifiedImage> _screenshotResult = [];
+  List<ClassifiedImage> _blurryResult = [];
   bool _isClassifying = false;
   bool _isClassifying = false;
   String _errorMessage = '';
   String _errorMessage = '';
 
 
@@ -107,7 +110,7 @@ class _MyAppState extends State<MyApp> {
                   ),
                   ),
                 ),
                 ),
               ],
               ],
-              if (_result != null && _progress?.isCompleted == true) ...[
+              if (_progress != null) ...[
                 const SizedBox(height: 20),
                 const SizedBox(height: 20),
                 const Text('分类结果:', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
                 const Text('分类结果:', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
                 _buildResultSummary(),
                 _buildResultSummary(),
@@ -128,15 +131,15 @@ class _MyAppState extends State<MyApp> {
   }
   }
 
 
   Widget _buildResultSummary() {
   Widget _buildResultSummary() {
-    if (_result == null) return const Text('无结果');
-
+    if (_similarResult.isEmpty && _peopleResult.isEmpty && _screenshotResult.isEmpty && _blurryResult.isEmpty) return const Text('无结果');
+    
     return Expanded(
     return Expanded(
       child: ListView(
       child: ListView(
         children: [
         children: [
-          _buildResultItem('相似图片组', _result?.similarGroups, isGroup: true),
-          _buildResultItem('人物照片', _result?.peopleGroups),
-          _buildResultItem('屏幕截图', _result?.screenshotGroups),
-          _buildResultItem('模糊图片', _result?.blurryGroups),
+          _buildResultItem('相似图片组', _similarResult.length, isGroup: true),
+          _buildResultItem('人物照片', _peopleResult.length),
+          _buildResultItem('屏幕截图', _screenshotResult.length),
+          _buildResultItem('模糊图片', _blurryResult.length),
         ],
         ],
       ),
       ),
     );
     );
@@ -194,7 +197,10 @@ class _MyAppState extends State<MyApp> {
       _isClassifying = true;
       _isClassifying = true;
       _errorMessage = '';
       _errorMessage = '';
       _progress = null;
       _progress = null;
-      _result = null;
+      _similarResult = [];
+      _peopleResult = [];
+      _screenshotResult = [];
+      _blurryResult = [];
     });
     });
 
 
     try {
     try {
@@ -213,10 +219,16 @@ class _MyAppState extends State<MyApp> {
           if (event == null) return;
           if (event == null) return;
           setState(() {
           setState(() {
             _progress = event.progress;
             _progress = event.progress;
-            print("批次: ${event.progress?.currentBatch}/${event.progress?.totalBatches}, 进度: ${event.progress?.batchDuration}");
-            print("${event.result?.screenshotGroups?.length}");
+            print("批次: ${event.progress?.currentBatch}/${event.progress?.totalBatches}, 用时: ${event.progress?.batchDuration}");
+            print("${event.result?.screenshotImages?.length}");
+            var result = event.result;
+            if (result != null) {
+              _similarResult.addAll(result.similarGroups?.map((group) => group).toList() ?? []);
+              _peopleResult.addAll(result.peopleImages?.map((image) => image).toList() ?? []);
+              _screenshotResult.addAll(result.screenshotImages?.map((image) => image).toList() ?? []);
+              _blurryResult.addAll(result.blurryImages?.map((image) => image).toList() ?? []);
+            }
             if (event.progress?.isCompleted == true) {
             if (event.progress?.isCompleted == true) {
-              _result = event.result;
               _isClassifying = false;
               _isClassifying = false;
               _subscription?.cancel();
               _subscription?.cancel();
               // 取消订阅
               // 取消订阅
@@ -261,7 +273,10 @@ class _MyAppState extends State<MyApp> {
   void _resetAll() {
   void _resetAll() {
     setState(() {
     setState(() {
       _progress = null;
       _progress = null;
-      _result = null;
+      _similarResult = [];
+      _peopleResult = [];
+      _screenshotResult = [];
+      _blurryResult = [];
       _errorMessage = '';
       _errorMessage = '';
       _isClassifying = false;
       _isClassifying = false;
     });
     });

+ 9 - 9
lib/models.dart

@@ -119,15 +119,15 @@ class ClassifiedImage {
 
 
 class ClassificationResult {
 class ClassificationResult {
   final List<ClassifiedImageGroup>? similarGroups;
   final List<ClassifiedImageGroup>? similarGroups;
-  final List<ClassifiedImage>? peopleGroups;
-  final List<ClassifiedImage>? screenshotGroups;
-  final List<ClassifiedImage>? blurryGroups;
+  final List<ClassifiedImage>? peopleImages;
+  final List<ClassifiedImage>? screenshotImages;
+  final List<ClassifiedImage>? blurryImages;
   
   
   ClassificationResult({
   ClassificationResult({
     required this.similarGroups,
     required this.similarGroups,
-    required this.peopleGroups,
-    required this.screenshotGroups,
-    required this.blurryGroups,
+    required this.peopleImages,
+    required this.screenshotImages,
+    required this.blurryImages,
   });
   });
 
 
   static ClassificationResult fromJson(Map<String, dynamic> json) {
   static ClassificationResult fromJson(Map<String, dynamic> json) {
@@ -145,13 +145,13 @@ class ClassificationResult {
               processedImages(group)
               processedImages(group)
             )
             )
           )),
           )),
-      peopleGroups: json['peopleImages']?.isEmpty ?? true
+      peopleImages: json['peopleImages']?.isEmpty ?? true
         ? null
         ? null
         : processedImages(json['peopleImages']),
         : processedImages(json['peopleImages']),
-      screenshotGroups: json['screenshotImages']?.isEmpty ?? true 
+      screenshotImages: json['screenshotImages']?.isEmpty ?? true 
         ? null 
         ? null 
         : processedImages(json['screenshotImages']),
         : processedImages(json['screenshotImages']),
-      blurryGroups: json['blurryImages']?.isEmpty ?? true 
+      blurryImages: json['blurryImages']?.isEmpty ?? true 
         ? null 
         ? null 
         : processedImages(json['blurryImages']),
         : processedImages(json['blurryImages']),
     );
     );