12
12
use App \Entity \Core \Asset ;
13
13
use App \Entity \Core \Attribute ;
14
14
use App \Entity \Core \File ;
15
+ use App \Entity \Traits \AssetAnnotationsInterface ;
15
16
use App \Integration \ApiBudgetLimiter ;
16
17
use App \Integration \IntegrationConfig ;
17
18
use App \Integration \IntegrationDataManager ;
@@ -51,22 +52,40 @@ public function analyze(?Asset $asset, File $file, string $category, Integration
51
52
52
53
if (!empty ($ result ) && $ asset instanceof Asset) {
53
54
if (AwsRekognitionIntegration::LABELS === $ category && !empty ($ config ['labels ' ]['attributes ' ] ?? [])) {
54
- $ this ->saveTextsToAttributes ($ asset , array_map (fn (array $ text ): array => [
55
+ $ this ->saveTextsToAttributes ($ category , $ asset , array_map (fn (array $ text ): array => [
55
56
'value ' => $ text ['Name ' ],
56
- 'confidence ' => $ text ['Confidence ' ],
57
+ 'confidence ' => $ text ['Confidence ' ] / 100 ,
58
+ 'annotations ' => array_map (fn (array $ instance ): array => [
59
+ 'type ' => AssetAnnotationsInterface::TYPE_RECTANGLE ,
60
+ 'x ' => $ instance ['BoundingBox ' ]['Left ' ] ?? null ,
61
+ 'y ' => $ instance ['BoundingBox ' ]['Top ' ] ?? null ,
62
+ 'w ' => $ instance ['BoundingBox ' ]['Width ' ] ?? null ,
63
+ 'h ' => $ instance ['BoundingBox ' ]['Height ' ] ?? null ,
64
+ ], $ text ['Instances ' ] ?? []),
57
65
], $ result ['Labels ' ]), $ config ['labels ' ]['attributes ' ]);
58
66
} elseif (AwsRekognitionIntegration::TEXTS === $ category && !empty ($ config ['texts ' ]['attributes ' ] ?? [])) {
59
- $ this ->saveTextsToAttributes ($ asset , array_map (fn (array $ text ): array => [
60
- 'value ' => $ text ['DetectedText ' ],
61
- 'confidence ' => $ text ['Confidence ' ],
62
- ], array_filter ($ result ['TextDetections ' ], fn (array $ text ): bool => 'LINE ' === $ text ['Type ' ])), $ config ['texts ' ]['attributes ' ]);
67
+ $ this ->saveTextsToAttributes ($ category , $ asset , array_map (function (array $ text ): array {
68
+ $ box = $ text ['Geometry ' ]['BoundingBox ' ] ?? [];
69
+
70
+ return [
71
+ 'value ' => $ text ['DetectedText ' ],
72
+ 'confidence ' => $ text ['Confidence ' ] / 100 ,
73
+ 'annotations ' => [[
74
+ 'type ' => AssetAnnotationsInterface::TYPE_RECTANGLE ,
75
+ 'x ' => $ box ['Left ' ] ?? null ,
76
+ 'y ' => $ box ['Top ' ] ?? null ,
77
+ 'w ' => $ box ['Width ' ] ?? null ,
78
+ 'h ' => $ box ['Height ' ] ?? null ,
79
+ ]],
80
+ ];
81
+ }, array_filter ($ result ['TextDetections ' ], fn (array $ text ): bool => 'LINE ' === $ text ['Type ' ])), $ config ['texts ' ]['attributes ' ]);
63
82
}
64
83
}
65
84
66
85
return $ result ;
67
86
}
68
87
69
- protected function saveTextsToAttributes (Asset $ asset , array $ texts , array $ attributes ): void
88
+ protected function saveTextsToAttributes (string $ category , Asset $ asset , array $ texts , array $ attributes ): void
70
89
{
71
90
foreach ($ attributes as $ attrConfig ) {
72
91
$ attrDef = $ this ->attributeManager
@@ -84,17 +103,20 @@ protected function saveTextsToAttributes(Asset $asset, array $texts, array $attr
84
103
$ i ->action = BatchAttributeManager::ACTION_DELETE ;
85
104
$ i ->origin = Attribute::ORIGIN_MACHINE ;
86
105
$ i ->originVendor = AwsRekognitionIntegration::getName ();
106
+ $ i ->originVendorContext = $ category ;
87
107
$ input ->actions [] = $ i ;
88
108
89
109
foreach ($ texts as $ text ) {
90
- if (null === $ threshold || $ threshold < $ text ['confidence ' ]) {
110
+ if (null === $ threshold || $ text ['confidence ' ] >= $ threshold ) {
91
111
$ i = new AttributeActionInput ();
92
112
$ i ->action = BatchAttributeManager::ACTION_ADD ;
93
113
$ i ->originVendor = AwsRekognitionIntegration::getName ();
114
+ $ i ->originVendorContext = $ category ;
94
115
$ i ->origin = Attribute::ORIGIN_MACHINE ;
95
116
$ i ->definitionId = $ attrDef ->getId ();
96
117
$ i ->confidence = $ text ['confidence ' ];
97
118
$ i ->value = $ text ['value ' ];
119
+ $ i ->annotations = $ text ['annotations ' ] ?? [];
98
120
$ input ->actions [] = $ i ;
99
121
}
100
122
}
0 commit comments