|
| 1 | +# coding: utf-8 |
| 2 | + |
| 3 | +""" |
| 4 | +This example demonstrates the use of the Camera Block, in the case when |
| 5 | +recording the acquired images and sending a message to downstream Blocks each |
| 6 | +time a new image is saved. It does not require any hardware to run, but |
| 7 | +necessitates the opencv-python, scikit-image and Pillow modules to be |
| 8 | +installed. |
| 9 | +
|
| 10 | +It acquires images on a fake camera, and records part of them at the given |
| 11 | +location. Before the test starts, it also lets the user adjust some settings on |
| 12 | +the camera in a configuration window. Because images are recorded, no image |
| 13 | +processing is performed, and an output Link is defined, a message is sent to |
| 14 | +downstream Blocks each time a new image is saved. This message is caught by a |
| 15 | +Dashboard Block, that displays the last timestamp when an image was saved. In |
| 16 | +addition, a StopButton Block allows stopping the script properly without using |
| 17 | +CTRL+C by clicking on a button. |
| 18 | +
|
| 19 | +After starting this script, you can play with the parameters in the |
| 20 | +configuration window. Once you're done, close the configuration window. Images |
| 21 | +will start being recorded at the given location, and the timestamp of the last |
| 22 | +saved image should be displayed by the Dashboard. Stop the test after a few |
| 23 | +seconds by clicking on the stop button that appears, and check the destination |
| 24 | +folder to see the recorded images. You can also hit CTRL+C, but it is not a |
| 25 | +clean way to stop Crappy. |
| 26 | +""" |
| 27 | + |
| 28 | +import crappy |
| 29 | + |
| 30 | +if __name__ == '__main__': |
| 31 | + |
| 32 | + # The Block in charge of acquiring the images and recording them |
| 33 | + # It also displays a configuration windows before the test starts, in which |
| 34 | + # the user can tune a few parameters of the Camera |
| 35 | + # Here, a fake camera is used so that no hardware is required |
| 36 | + # Because save_images is True, no image processing is performed, and an |
| 37 | + # output Link is defined, the timestamp and metadata are sent at each new |
| 38 | + # saved image over the labels 't(s)' and 'meta' |
| 39 | + cam = crappy.blocks.Camera( |
| 40 | + 'FakeCamera', # Using the FakeCamera camera so that no hardware is |
| 41 | + # required |
| 42 | + config=True, # Before the test starts, displays a configuration window |
| 43 | + # for configuring the camera |
| 44 | + display_images=False, # Here, we don't want the images displayed |
| 45 | + save_images=True, # The acquired images should be recorded during this |
| 46 | + # test |
| 47 | + img_extension='tiff', # The images should be saved as .tiff files |
| 48 | + save_folder='demo_record_images_send', # The images will be saved in |
| 49 | + # this folder, whose path can be relative or absolute |
| 50 | + save_period=10, # Only one out of 10 images will be saved, to avoid |
| 51 | + # bothering you with tons of images |
| 52 | + save_backend=None, # The first available backend will be used |
| 53 | + freq=40, # Lowering the default frequency because it's just a demo |
| 54 | + |
| 55 | + # Sticking to default for the other arguments |
| 56 | + ) |
| 57 | + |
| 58 | + # This Block allows the user to properly exit the script |
| 59 | + stop = crappy.blocks.StopButton( |
| 60 | + # No specific argument to give for this Block |
| 61 | + ) |
| 62 | + |
| 63 | + # This Block displays the time value of the moments when an image is saved by |
| 64 | + # the Camera Block |
| 65 | + # It is here to demonstrate that the information is properly sent to |
| 66 | + # downstream Blocks |
| 67 | + dash = crappy.blocks.Dashboard(('t(s)',)) |
| 68 | + |
| 69 | + # Linking the Blocks together so that the correct information is sent |
| 70 | + crappy.link(cam, dash) |
| 71 | + |
| 72 | + # Mandatory line for starting the test, this call is blocking |
| 73 | + crappy.start() |
0 commit comments