Duck Confit

This tutorial presents intermediate recipes for cooking up new PeekingDuck pipelines by modifying the nodes and their configs.

More Object Detection

This section will demonstrate how to change the settings of PeekingDuck’s nodes to vary their functionalities.

If you had completed the earlier object detection tutorial, you will have the necessary folder and can skip to the next step. Otherwise, create a new PeekingDuck project as shown below:

Terminal Session

[~user] > mkdir object_detection
[~user] > cd object_detection
[~user/object_detection] > peekingduck init

Next, download this demo video cat_and_computer.mp4 and save it into the object_detection folder.

The folder should contain the following:

object_detection/ ⠀
├── cat_and_computer.mp4
├── pipeline_config.yml
└── src/

To perform object detection on the cat_and_computer.mp4 file, edit the pipeline_config.yml file as follows:

1nodes:
2- input.visual:
3    source: cat_and_computer.mp4
4- model.yolo:
5    detect: ["cup", "cat", "laptop", "keyboard", "mouse"]
6- draw.bbox:
7    show_labels: True    # configure draw.bbox to display object labels
8- output.screen

Here is a step-by-step explanation of what has been done:

Line 2 input.visual: tells PeekingDuck to load the cat_and_computer.mp4.
Line 4 model.yolo: by default, the YOLO model detects person only.
The cat_and_computer.mp4 contains other classes of objects like cup, cat, laptop, etc.
So we have to change the model settings to detect the other object classes.
Line 6 draw.bbox: reconfigure this node to display the detected object class label.

Run the above with the command peekingduck run.

Cat and Computer Screenshot

Cat and Computer Screenshot

You should see a display of the cat_and_computer.mp4 with the various objects being highlighted by PeekingDuck in bounding boxes.
The 30-second video will auto-close at the end, or you can press q to end early.

Note

The YOLO model can detect 80 different object classes. By default, it only detects the "person" class. Use detect: ["*"] in the pipeline_config.yml to configure the model to detect all 80 classes.

Record Video File with FPS

This section demonstrates how to record PeekingDuck’s output into a video file. In addition, we will modify the pipeline by adding new nodes to calculate the frames per second (FPS) and to show the FPS.

Edit pipeline_config.yml as shown below:

 1nodes:
 2- input.visual:
 3    source: cat_and_computer.mp4
 4- model.yolo:
 5    detect: ["cup", "cat", "laptop", "keyboard", "mouse"]
 6- draw.bbox:
 7    show_labels: True
 8- dabble.fps                           # add new dabble node
 9- draw.legend:                         # show fps
10    show: ["fps"]
11- output.screen
12- output.media_writer:                 # add new output node
13    output_dir: /folder/to/save/video  # this is a folder name

The additions are:

Line 8 dabble.fps: adds new dabble node to the pipeline. This node calculates the FPS.
Line 9 draw.legend: adds new draw node to display the FPS.
Line 12 output.media_writer: adds new output node to save PeekingDuck’s output to a local video file. It requires a local folder path. If the folder is not available, PeekingDuck will create the folder automatically. The filename is auto-generated by PeekingDuck based on the input source.

Run the above with the command peekingduck run.
You will see the same video being played, but now it has the FPS counter. When the video ends, an mp4 video file will be created and saved in the specified folder.

Note

You can view all the available nodes and their respective configurable settings in PeekingDuck’s API documentation.

Configuration - Behind the Scenes

Here is an explanation on what goes on behind the scenes when you configure a node. Every node has a set of default configuration. For instance, draw.bbox default configuration is:

1input: ["bboxes", "img", "bbox_labels"]
2output: ["none"]
3
4show_labels: False
The keys input and output are compulsory and common across every node.
input specifies the data types the node would consume, to be read from the pipeline.
output specifies the data types the node would produce, to be put into the pipeline.

By default, show_labels is disabled. When you enable it with show_labels: True, what PeekingDuck does is to override the default show_labels: False configuration with your specified True value. You will see another instance of this at work in the advanced Peaking Duck tutorial on Tracking People Within a Zone.

Augmenting Images

PeekingDuck has a class of augment nodes that can be used to perform preprocessing or postprocessing of images/videos. Augment currently lets you modify the brightness and contrast, and remove distortion from a wide-angle camera image. For more details on image undistortion, refer to the documentation on augment.undistort and dabble.camera_calibration.

The pipeline_config.yml below shows how to use the augment.brightness node within the pipeline:

1nodes:
2- input.visual:
3    source: https://storage.googleapis.com/peekingduck/videos/wave.mp4
4- model.yolo
5- augment.brightness:
6    beta: 50         # ranges from -100 (darken) to +100 (brighten)
7- draw.bbox
8- output.screen

The following figure shows the difference between the original vs the brightened image:

augment.brightness screenshot - original vs brightened image

Augment Brightness: Original vs Brightened Image

Note

Royalty free video of cat and computer from: https://www.youtube.com/watch?v=-C1TEGZavko
Royalty free video of man waving hand from: https://www.youtube.com/watch?v=IKj_z2hgYUM