class ProcessAnnotatedVideo extends ProcessAnnotatedFile

Traits

SerializesModels
InteractsWithQueue
Queueable
Dispatchable

Constants

DINO_PATCH_SIZE

Size of a square input patch for generating feature vectors with DINO.

Properties

int $maxRedispatchTries

The maximum number of times the job may be redispatched.

from  ProcessAnnotatedFile
int $tries

The number of times the job may be attempted.

from  ProcessAnnotatedFile
protected bool $deleteWhenMissingModels

Ignore this job if the annotation does not exist any more.

from  ProcessAnnotatedFile

Methods

array
getAnnotationBoundingBox(array $points, Shape $shape, int $pointPadding = self::DINO_PATCH_SIZE / 2, int $boxPadding = 0, int $minSize = 32)

Get the bounding box of an annotation

array
ensureBoxAspectRatio(array $box, int $aspectWidth, int $aspectHeight)

Modify a bounding box so it adheres to the aspect ratio given by width and height.

makeBoxContained(array $box, int|null $maxWidth, int|null $maxHeight)

Adjust the position and size of the box so it is contained in a box with the given dimensions.

array
getPointBoundingBox(array $points, int $padding)

Get the bounding box of a point annotation.

array
getCircleBoundingBox(array $points)

Get the bounding box of a circle annotation.

array
getPolygonBoundingBox(array $points)

Get the bounding box of an annotation that is no point, circle or whole frame.

array
makeBoxIntegers(array $box)

Round and cast box values to int.

array
generateAnnotationBoxes(VolumeFile $file, Collection $annotations)

No description

string
getCropBufferForPyworker(Image $image, array $box)

Get the byte string of the cropped and resized patch for the Python worker.

array
sendPyworkerRequest(string $buffer)

Send the PNG image crop to the Python worker and return the feature vector array.

__construct(VolumeFile $file, array $only = [], bool $skipPatches = false, bool $skipFeatureVectors = false, bool $skipSvgs = false, string|null $targetDisk = null, int $redispatchTries = 0)

Create a new job instance.

static string
getTargetPath(Annotation $annotation, string|null $format = null)

Assemble the target path for an annotation patch.

void
handle()

Execute the job.

handleFile(VolumeFile $file, string $path)

Handle a single file.

bool
shouldGiveUpAfterException(Exception $e)

Determine if the job should give up trying because the error will likely not be fixed the next time.

bool
shouldRetryAfterException(Exception $e)

Determine if this job should retry instead of fail after an exception

void
createSvgs()

Generate and upload annotation SVGs for the file.

void
createSvg(Annotation $annotation)

Generate and upload an SVG for the annotation.

string
getAnnotationPatch(Image $image, array $points, Shape $shape)

Get the annotation patch as buffer.

void
generateFeatureVectors(Collection $annotations, array|string $filePath)

Generates feature vectors for the specified annotations belonging to the file of this job. This method either creates new feature vector models or updates the existing ones for the annotations.

void
updateOrCreateFeatureVectors(Collection $annotations, Generator $output)

Create the feature vectors based on the Python script output.

Builder
getAnnotationQuery(VolumeFile $file)

Get the query builder for the annotations (maybe filtered by IDs).

SVGNodeContainer
getSVGAnnotation(array $points, Shape $shape)

Draw annotation as SVG

SVGRect
getRectangleSvgAnnotation(array $tuples)

Get an SVG rectangle element.

SVGEllipse
getEllipseSvgAnnotation(array $tuples)

Get an SVG ellipse element.

float
computeRotationAngle(array $v, array $u)

Computes angle between two vectors

array
getOrientedCoordinates(array $tuples, Shape $shape)

Determines position of coordinate

void
redispatch()

Dispatch a copy of this job with a delay.

getVipsImageForPyworker(string $path, array $options = [])

Get the vips image instance for submission to the Python worker for feature vectors.

void
processAnnotationChunk(Collection $annotations, Video $video)

Process a chunk of annotations of this job's file.

getVideo(string $path)

Get the FFMpeg video instance.

Image
getVideoFrame(Video $video, float $time, int $trySeek = 60)

Get a video frame from a specific time as VipsImage object.

Details

array getAnnotationBoundingBox(array $points, Shape $shape, int $pointPadding = self::DINO_PATCH_SIZE / 2, int $boxPadding = 0, int $minSize = 32)

Get the bounding box of an annotation

Parameters

array $points
Shape $shape
int $pointPadding

The default is half the patch size of 224 that is expected by DINO.

int $boxPadding
int $minSize

Each side of the box should have at least this number of pixels. Must be divisible by 2.

Return Value

array

array ensureBoxAspectRatio(array $box, int $aspectWidth, int $aspectHeight)

Modify a bounding box so it adheres to the aspect ratio given by width and height.

Parameters

array $box
int $aspectWidth
int $aspectHeight

Return Value

array

makeBoxContained(array $box, int|null $maxWidth, int|null $maxHeight)

Adjust the position and size of the box so it is contained in a box with the given dimensions.

Parameters

array $box
int|null $maxWidth
int|null $maxHeight

protected array getPointBoundingBox(array $points, int $padding)

Get the bounding box of a point annotation.

Parameters

array $points
int $padding

Return Value

array

protected array getCircleBoundingBox(array $points)

Get the bounding box of a circle annotation.

Parameters

array $points

Return Value

array

protected array getPolygonBoundingBox(array $points)

Get the bounding box of an annotation that is no point, circle or whole frame.

Parameters

array $points

Return Value

array

protected array makeBoxIntegers(array $box)

Round and cast box values to int.

Parameters

array $box

Return Value

array

protected array generateAnnotationBoxes(VolumeFile $file, Collection $annotations)

No description

Parameters

VolumeFile $file
Collection $annotations

Return Value

array

protected string getCropBufferForPyworker(Image $image, array $box)

Get the byte string of the cropped and resized patch for the Python worker.

Parameters

Image $image
array $box

Return Value

string

protected array sendPyworkerRequest(string $buffer)

Send the PNG image crop to the Python worker and return the feature vector array.

Parameters

string $buffer

Return Value

array

__construct(VolumeFile $file, array $only = [], bool $skipPatches = false, bool $skipFeatureVectors = false, bool $skipSvgs = false, string|null $targetDisk = null, int $redispatchTries = 0)

Create a new job instance.

Parameters

VolumeFile $file

The file to process.

array $only

If filled with annotation IDs belonging to the file, only the annotations will be processed.

bool $skipPatches

Disable generation of annotation patches.

bool $skipFeatureVectors

Disable generation of annotation feature vectors.

bool $skipSvgs

Disable generation of annotation SVGs.

string|null $targetDisk

The storage disk to store annotation patches to ( default is the configured largo.patch_storage_disk).

int $redispatchTries

Counter to track the number of attempted redispatches.

static string getTargetPath(Annotation $annotation, string|null $format = null)

Assemble the target path for an annotation patch.

Parameters

Annotation $annotation
string|null $format

Return Value

string

in ProcessAnnotatedFile at line 114
void handle()

Execute the job.

Return Value

void

at line 24
handleFile(VolumeFile $file, string $path)

Handle a single file.

Parameters

VolumeFile $file
string $path

Path to the cached file.

in ProcessAnnotatedFile at line 166
protected bool shouldGiveUpAfterException(Exception $e)

Determine if the job should give up trying because the error will likely not be fixed the next time.

Parameters

Exception $e

Return Value

bool

in ProcessAnnotatedFile at line 197
protected bool shouldRetryAfterException(Exception $e)

Determine if this job should retry instead of fail after an exception

Parameters

Exception $e

Return Value

bool

in ProcessAnnotatedFile at line 217
void createSvgs()

Generate and upload annotation SVGs for the file.

Return Value

void

in ProcessAnnotatedFile at line 228
protected void createSvg(Annotation $annotation)

Generate and upload an SVG for the annotation.

Parameters

Annotation $annotation

Return Value

void

in ProcessAnnotatedFile at line 268
protected string getAnnotationPatch(Image $image, array $points, Shape $shape)

Get the annotation patch as buffer.

Parameters

Image $image
array $points
Shape $shape

Return Value

string

in ProcessAnnotatedFile at line 300
protected void generateFeatureVectors(Collection $annotations, array|string $filePath)

Generates feature vectors for the specified annotations belonging to the file of this job. This method either creates new feature vector models or updates the existing ones for the annotations.

Parameters

Collection $annotations
array|string $filePath

If a string, a file path to the local image to use for feature vector generation. If an array, a map of annotation IDs to a local image file path.

Return Value

void

at line 98
protected void updateOrCreateFeatureVectors(Collection $annotations, Generator $output)

Create the feature vectors based on the Python script output.

Parameters

Collection $annotations
Generator $output

Return Value

void

at line 163
protected Builder getAnnotationQuery(VolumeFile $file)

Get the query builder for the annotations (maybe filtered by IDs).

Parameters

VolumeFile $file

Return Value

Builder

in ProcessAnnotatedFile at line 397
protected SVGNodeContainer getSVGAnnotation(array $points, Shape $shape)

Draw annotation as SVG

Parameters

array $points

one dimensional array filled with coordinates of annotation

Shape $shape

shape of given annotation

Return Value

SVGNodeContainer

annotation as SVG

in ProcessAnnotatedFile at line 452
protected SVGRect getRectangleSvgAnnotation(array $tuples)

Get an SVG rectangle element.

Parameters

array $tuples

Return Value

SVGRect

in ProcessAnnotatedFile at line 473
protected SVGEllipse getEllipseSvgAnnotation(array $tuples)

Get an SVG ellipse element.

Parameters

array $tuples

Return Value

SVGEllipse

in ProcessAnnotatedFile at line 501
protected float computeRotationAngle(array $v, array $u)

Computes angle between two vectors

Parameters

array $v

first vector

array $u

second vector

Return Value

float

rotation angle in degree *

in ProcessAnnotatedFile at line 532
protected array getOrientedCoordinates(array $tuples, Shape $shape)

Determines position of coordinate

Parameters

array $tuples

coordinates array

Shape $shape

shapeId of given annotation

Return Value

array

with coordinates assigned to their position on the plane

in ProcessAnnotatedFile at line 558
protected void redispatch()

Dispatch a copy of this job with a delay.

Return Value

void

in ProcessAnnotatedFile at line 575
protected getVipsImageForPyworker(string $path, array $options = [])

Get the vips image instance for submission to the Python worker for feature vectors.

Parameters

string $path
array $options

at line 42
protected void processAnnotationChunk(Collection $annotations, Video $video)

Process a chunk of annotations of this job's file.

Parameters

Collection $annotations
Video $video

Return Value

void

at line 124
protected getVideo(string $path)

Get the FFMpeg video instance.

Parameters

string $path

at line 138
protected Image getVideoFrame(Video $video, float $time, int $trySeek = 60)

Get a video frame from a specific time as VipsImage object.

Parameters

Video $video
float $time
int $trySeek

Return Value

Image