Skip to content

Triggers

Q-engineering edited this page Aug 20, 2023 · 2 revisions

Trigger

A trigger warns you when a particular object is detected. There are two types of triggers.

  • An email trigger that sends you an email.
  • A GPIO trigger sets a GPIO output pin high (or low).

Different triggers can be combined.

The trigger files are found at /mnt/WRdisk/.
The /mnt/WRdisk/ location is the only folder which can be written even with the overlay function active. All the other folders will not hold their data after a reboot. See the overlay item for more information.

👉 Because the triggers are loaded during booting, changes will not take effect until you restart the YoloIP.

output image

Email Trigger

Email triggers are listed in the comma-separated TrigMail<x>.csv file, where stands for the camera number. The file has the following structure.

Label Probability Move Area Prio

Label
    One of 80 different objects to detect. For example 'car' or 'horse'. Upper or lower case doesn't matter.
Probability
    The probability indicates how well the object is recognized. The lower this number, the more likely a mistake occurs, for instance, a car instead of a truck.
Move
    Indicates the movement of the object. The parameter allows you to filter out static objects, for example, parked cars. Zero (0) disables the parameter.
Area
    Represents the ratio of the area of the recognized object to the entire image. Very small objects of a few pixels can be filtered out in this way.
Prio
    Prioritize the events. A higher priority event can still send an email even if sending is blocked by a lower priority trigger. Remember, once an email is sent, there is a brief time before the next email can be sent, set by the setting no_sec_mail. This blocking mechanism is now governed by the priority scheme.

Email csv example

person , 50 , 10.5, 0.5 , 2  
person , 50 , 10.5 , 50.0 , 10 
car    , 50 , 20.0, 0.8 , 1  
truck  , 50 , 20.0 , 0.8 , 1  
bicycle, 50 , 5.5 , 0.5 , 2 

A recording can start when a person, a car, a truck or a bicycle is recognized in the camera scene.
Each object needs to fulfil additional conditions before it fires a trigger. First, they all have a minimal 50% probability.
The second condition is movement. A person has to move 10.5%, a car 20.0% and a bicycle only 5.5%. These figures are found by trial and error.
The next condition is the size of the scene. A person needs to occupy 0.5% of the scene (640 x 480 x 0.005 = 1536 pixels). Smaller sizes are too unreliable.
A car needs to be 0.8% before it's been detected. And a bicycle 0.5% again.

In this example, you see two definitions for a person. The first rule refers to daily events, such as passers-by at a distance, given the area condition of 0.5.
The second rule describes a person filling the entire image (area > 50). Say, someone at your door. Give this rule a very high prio, and you are sure an email will always send to you.

Preview of an email. In the diagram, Prio 0 means not active.
output image

GPIO Trigger

GPIO triggers are listed in the comma-separated TrigGPIO<x>.csv file, where stands for the camera number. The file has the following structure.

Label Probability Move Area Delay Prolong Pin Inv

Delay
    The delay value indicates how many seconds an object must be detected before a pin becomes active. You do not want a one-time glitch to set a trigger.
Prolong
    Prolong indicates the time in seconds how long a pin remains active if the object is no longer detected.
Pin
    The pin associated with the defined trigger. Pin numbers according to WiringPi.
Inv
    Inv=0 pin is active high | Inv=1 pin is active low.

GPIO csv example

person, 50 , 0 , 0.5 , 1 , 5 , 7 , 0 
car   , 50 , 2.5 , 0.5 , 0 , 5 , 8 , 1  

Two rules. The first set pin 7 (Pin=7) high (Inv=0) when a person is detected. The person must be in the picture for at least 1 second (Delay=1). The pin remains high for 5 seconds when no person (or persons) are recognized (Prolong=5). The person may stand still (Move=0).
The second rule set pin 8 (Pin=8) low (Inv=1) when a driving car is detected.

URL Trigger

URL triggers are also listed in the comma-separated TrigGPIO<x>.csv file. The file is identical to the GPIO structure with two supplementary fields.

Label Probability Move Area Delay Prolong Pin Inv URL on URL off

URL on
    The URL address used when a trigger is set active.
URL off
    The URL address used when a trigger resets after being set active.

URL csv example

person, 50 ,    0 ,  0.5 , 1  , 0 , 100 , 0 , https://www.example.com/begin
person, 50 , 10.5 , 50.0 , 0  , 5 ,   7 , 0 , https://www.example.com/api/startpoint , https://www.example.com/api/stoppoint
car   , 50 , 2.5  ,  0.5 , 0 ,  5 ,  -1 , 1 ,   , https://www.example.com/api2/stoppoint

Three rules.
The first sends a request to https://www.example.com/begin when a person is detected. The person must be in the picture for at least 1 second (Delay=1). There is no pin activated due to the non-existing pin number 100. The person may stand still (Move=0).

The second rule describes a person filling the entire image (area > 50). Say, someone at your door. The trigger set pin 7 (Pin=7) high (Inv=0) when a person is detected. The person must be in the picture for at least 1 second (Delay=1). At the same time, a request is sent to https://www.example.com/api/startpoint. Once the person leaves the scene, it will take 5 Sec (Prolong=5) before the reset URL is activated (URL off=https://www.example.com/api/stoppoint).

The last rule will only send a request when a once-detected car leaves the scene because only the URL off is being defined (https://www.example.com/api2/stoppoint).

Please note the URL addresses have no quotation marks.

Pin layout

output image

COCO labels

All detectable objects:

person bicycle car motorcycle airplane bus train truck boat traffic light
fire hydrant stop sign parking meter bench bird cat dog horse sheep cow
elephant bear zebra giraffe backpack umbrella handbag tie suitcase frisbee
skis snowboard sports ball kite baseball bat baseball glove skateboard surfboard tennis racket bottle
wine glass cup fork knife spoon bowl banana apple tennis racket bottle
broccoli carrot hot dog pizza donut cake chair couch potted plant bed
dining table toilet tv laptop mouse remote keyboard cell phone microwave oven
toaster sink refrigerator book clock vase scissors teddy bear hair drier toothbrush
Clone this wiki locally