Repository navigation
Expand file tree
/
Copy pathSimpleImageSegmentation.lf
More file actions
61 lines (54 loc) · 1.93 KB
/
Copy pathSimpleImageSegmentation.lf
File metadata and controls
61 lines (54 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* @file SimpleImageSegmentation.lf
* @author Vincenzo Barbuto
* @brief Examples of how to use the Image Segmentation reactor.
*/
target Python
import ImageSegmenter from "lib/ComputerVision.lf"
/**
* @brief Injects an image into the image segmentation pipeline.
*
* The ImageInjector reactor reads an image from the specified file path and outputs it to the
* `image_data` port. This allows the image to be consumed by other reactors in the pipeline, such
* as the ImageSegmenter.
*
* The Actuator reactor receives the segmentation results and inference time from the ImageSegmenter
* and prints them to the console.
*
* The main reactor wires up the `ImageInjector`, `ImageSegmenter`, and `Actuator` reactors
* together. The ImageInjector reactor outputs the image data to the ImageSegmenter reactor. The
* ImageSegmenter reactor outputs the detected results and inference time to the Actuator reactor.
*
* @note Remember to set the `model` parameter to the absolute path of the image segmentation model
* you want to use, as well as the `img_path` parameter to the absolute path of the image file you
* want to use.
*/
reactor ImageInjector(img_path="") {
output image_data
preamble {=
import cv2
=}
reaction(startup) -> image_data {=
img = self.cv2.imread(self.img_path)
image_data.set(img)
=}
}
reactor Actuator {
input res
input inference_time
reaction(res, inference_time) {=
results = res.value
print("-"*70)
for i, result in enumerate(results):
print(f"{i}) Segment: {result['segment']}")
print(f"Time per inference: {inference_time.value} ms")
=}
}
main reactor {
inj = new ImageInjector(img_path="/path/to/image.png")
sgm = new ImageSegmenter(
model = {= os.path.join(os.getcwd(),"models/vision/segmentation/deeplab.tflite") =})
actuator = new Actuator()
inj.image_data -> sgm.input_data
sgm.results, sgm.inference_time -> actuator.res, actuator.inference_time
}