|
| 1 | +Conditional actions |
| 2 | +=================== |
| 3 | + |
| 4 | +DepthAI SDK provides a way to perform actions based on some conditions. |
| 5 | +For example, you can perform an action when a certain number of objects is detected in the frame. |
| 6 | +This functionality can be achieved by using Trigger-Action API. |
| 7 | + |
| 8 | +Overview |
| 9 | +-------- |
| 10 | +Trigger-Action API is a way to define a set of conditions and actions that should be performed when these conditions are met. |
| 11 | +DepthAI SDK provides a set of predefined conditions and actions, but you can also define your own. |
| 12 | + |
| 13 | +Basic concepts: |
| 14 | + |
| 15 | +- **Trigger** - a condition that should be met to perform an action. |
| 16 | +- **Action** - an action that should be performed when a trigger is met. |
| 17 | + |
| 18 | +.. note:: Trigger-Action API is implemented in the :mod:`depthai.trigger_action` module. |
| 19 | + |
| 20 | +Triggers |
| 21 | +-------- |
| 22 | + |
| 23 | +The base class for all triggers is :class:`Trigger <depthai_sdk.trigger_action.Trigger>`. |
| 24 | +In order to create a trigger, you need to use the :class:`Trigger <depthai_sdk.trigger_action.Trigger>` class and pass the following parameters: |
| 25 | + |
| 26 | +- ``input`` - a component that should be used as a trigger source. |
| 27 | +- ``condition`` - a function that should return ``True`` or ``False`` based on the trigger source. |
| 28 | +- ``cooldown`` - defines how often a trigger can be activated (in seconds). |
| 29 | + |
| 30 | +The set of predefined triggers: |
| 31 | + |
| 32 | +- :class:`DetectionTrigger <depthai_sdk.trigger_action.DetectionTrigger>` - a trigger that is activated when a certain number of objects is detected in the frame. |
| 33 | + |
| 34 | +Actions |
| 35 | +------- |
| 36 | + |
| 37 | +An action can be represented by either a function or a class derived from :class:`Action <depthai_sdk.trigger_action.Action>` class. |
| 38 | +The custom action should implement :meth:`activate() <depthai_sdk.trigger_action.Action.activate>` and optionally :meth:`on_new_packets() <depthai_sdk.trigger_action.Action.on_new_packets>` methods. |
| 39 | + |
| 40 | +The set of predefined actions: |
| 41 | + |
| 42 | +- :class:`RecordAction <depthai_sdk.trigger_action.RecordAction>` - records a video of a given duration when a trigger is activated. |
| 43 | + |
| 44 | +Usage |
| 45 | +----- |
| 46 | + |
| 47 | +The following example shows how to create a trigger that is activated when at least 1 person is detected in the frame. |
| 48 | +When the trigger is activated, it records a 15 seconds video (5 seconds before the trigger is activated and 10 seconds after). |
| 49 | + |
| 50 | +.. literalinclude:: ../../../examples/trigger_action/person_record.py |
| 51 | + :language: python |
| 52 | + |
| 53 | +Reference |
| 54 | +------------- |
| 55 | + |
| 56 | +.. autoclass:: depthai_sdk.trigger_action.TriggerAction |
| 57 | + :members: |
| 58 | + :undoc-members: |
| 59 | + |
| 60 | +.. autoclass:: depthai_sdk.trigger_action.Trigger |
| 61 | + :members: |
| 62 | + :undoc-members: |
| 63 | + |
| 64 | +.. autoclass:: depthai_sdk.trigger_action.Action |
| 65 | + :members: |
| 66 | + :undoc-members: |
| 67 | + |
| 68 | +.. autoclass:: depthai_sdk.trigger_action.DetectionTrigger |
| 69 | + :members: |
| 70 | + :undoc-members: |
| 71 | + |
| 72 | +.. autoclass:: depthai_sdk.trigger_action.RecordAction |
| 73 | + :members: |
| 74 | + :undoc-members: |
| 75 | + |
0 commit comments