Skip to content

Commit d046678

Browse files
authored
Merge branch 'master' into PS-907-fixes
2 parents b76c0ec + a755408 commit d046678

File tree

11 files changed

+319
-290
lines changed

11 files changed

+319
-290
lines changed

databox/api/src/Api/Model/Input/Attribute/AbstractExtendedAttributeInput.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
namespace App\Api\Model\Input\Attribute;
66

7+
use App\Entity\Traits\AssetAnnotationsInterface;
8+
use Symfony\Component\Validator\Constraints as Assert;
9+
710
abstract class AbstractExtendedAttributeInput extends AbstractBaseAttributeInput
811
{
912
/**
@@ -22,6 +25,12 @@ abstract class AbstractExtendedAttributeInput extends AbstractBaseAttributeInput
2225
/**
2326
* @var array
2427
*/
28+
#[Assert\Collection(
29+
fields: [
30+
'type' => new Assert\Choice(AssetAnnotationsInterface::TYPES),
31+
],
32+
allowExtraFields: true,
33+
)]
2534
public $annotations;
2635

2736
/**

databox/api/src/Attribute/BatchAttributeManager.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ public function handleBatch(
204204
'ids' => $action->ids,
205205
'origin' => $action->origin,
206206
'originVendor' => $action->originVendor,
207+
'originVendorContext' => $action->originVendorContext,
207208
]);
208209
break;
209210
case self::ACTION_SET:
@@ -469,6 +470,11 @@ private function deleteAttributes(
469470
->andWhere('a.originVendor = :originVendor')
470471
->setParameter('originVendor', $options['originVendor']);
471472
}
473+
if ($options['originVendorContext'] ?? null) {
474+
$qb
475+
->andWhere('a.originVendorContext = :ovc')
476+
->setParameter('ovc', $options['originVendorContext']);
477+
}
472478
$qb->getQuery()->execute();
473479
}
474480

databox/api/src/Entity/Traits/AssetAnnotationsInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ interface AssetAnnotationsInterface
1010
// "x", "y", "r" (radius in %), "c"? (border color in hexa), "f"? (fill color in hexa)
1111
final public const string TYPE_CIRCLE = 'circle';
1212

13-
// "x1", "y1", "x2", "y2", "c"? (border color in hexa), "f"? (fill color in hexa)
13+
// "x", "y", "w", "h", "c"? (border color in hexa), "f"? (fill color in hexa)
1414
final public const string TYPE_RECTANGLE = 'rect';
1515

1616
// "t" (time: float in seconds)

databox/api/src/Integration/Aws/Rekognition/RekognitionAnalyzer.php

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use App\Entity\Core\Asset;
1313
use App\Entity\Core\Attribute;
1414
use App\Entity\Core\File;
15+
use App\Entity\Traits\AssetAnnotationsInterface;
1516
use App\Integration\ApiBudgetLimiter;
1617
use App\Integration\IntegrationConfig;
1718
use App\Integration\IntegrationDataManager;
@@ -51,22 +52,40 @@ public function analyze(?Asset $asset, File $file, string $category, Integration
5152

5253
if (!empty($result) && $asset instanceof Asset) {
5354
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 => [
5556
'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'] ?? []),
5765
], $result['Labels']), $config['labels']['attributes']);
5866
} 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']);
6382
}
6483
}
6584

6685
return $result;
6786
}
6887

69-
protected function saveTextsToAttributes(Asset $asset, array $texts, array $attributes): void
88+
protected function saveTextsToAttributes(string $category, Asset $asset, array $texts, array $attributes): void
7089
{
7190
foreach ($attributes as $attrConfig) {
7291
$attrDef = $this->attributeManager
@@ -84,17 +103,20 @@ protected function saveTextsToAttributes(Asset $asset, array $texts, array $attr
84103
$i->action = BatchAttributeManager::ACTION_DELETE;
85104
$i->origin = Attribute::ORIGIN_MACHINE;
86105
$i->originVendor = AwsRekognitionIntegration::getName();
106+
$i->originVendorContext = $category;
87107
$input->actions[] = $i;
88108

89109
foreach ($texts as $text) {
90-
if (null === $threshold || $threshold < $text['confidence']) {
110+
if (null === $threshold || $text['confidence'] >= $threshold) {
91111
$i = new AttributeActionInput();
92112
$i->action = BatchAttributeManager::ACTION_ADD;
93113
$i->originVendor = AwsRekognitionIntegration::getName();
114+
$i->originVendorContext = $category;
94115
$i->origin = Attribute::ORIGIN_MACHINE;
95116
$i->definitionId = $attrDef->getId();
96117
$i->confidence = $text['confidence'];
97118
$i->value = $text['value'];
119+
$i->annotations = $text['annotations'] ?? [];
98120
$input->actions[] = $i;
99121
}
100122
}

0 commit comments

Comments
 (0)