Skip to content

Importing

app.application.services.detection.importing

View source code

Detection layer import service — loads bounding-box data into layers A or B.

See Also

Layer: Application. Context: Coordinates domain state and infrastructure to complete application use cases.

DetectionImportService

Bases: QObject

Loads persisted bounding-box data into detection layers A or B.

Responsibilities
  • Read a JSON or CSV file produced by DetectionExportService.
  • Apply the chosen ImportMode merge strategy via apply_import_to_layer.
  • Return the total number of boxes written for status reporting.
Note

This service satisfies the IDataImporter interface Protocol via structural subtyping — no explicit inheritance is needed.

Layers A/B are the detection layers. Do not use this service to write to tracking layers C/D; use TrackingImportService instead.

The file_path extension determines the format: .json → JSON deserialiser .csv → CSV deserialiser Anything else raises ValueError.

Consider future improvement: add progress callbacks for very large files (millions of boxes across thousands of frames), similar to how the detection/export workers report progress today.

PARAMETER DESCRIPTION
app

Application adapted for resolving sessions and writing imported detection-layer boxes.

TYPE: Application

__init__(app: Application) -> None

import_layer(s_id: SessionId, layer: VideoDataLayer | str, file_path: str, mode: ImportMode | str) -> int

Import bounding-box data from file_path into layer.

PARAMETER DESCRIPTION
s_id

Target session.

TYPE: SessionId

layer

Target layer — should be A or B (or their string equivalents).

TYPE: VideoDataLayer | str

file_path

Absolute path to a .json or .csv file.

TYPE: str

mode

Merge strategy (enum or string).

TYPE: ImportMode | str

RETURNS DESCRIPTION
int

Number of boxes written.

TYPE: int

RAISES DESCRIPTION
ValueError

If file_path has an unrecognised extension.

FileNotFoundError

If file_path does not exist.

Note

Accepts both VideoDataLayer enums and string layer names to handle Qt signal/slot type coercion.