The purpose of this page is to layout exactly what elements of SIC are being run where and how, to gain more insight into the design of the framework. It is not to analyze how face detection works.
...
Code Block | ||
---|---|---|
| ||
run-face-detection |
within a shell
This runs the main() function of face_detection.py, which starts a ComponentManager
assigned to the FaceDetectionComponent
. In this example, this script is ran on the same computer as the rest of the application, although it may be ran on another computer.
...
Code Block | ||
---|---|---|
| ||
# Connect to the services desktop = Desktop(camera_conf=conf) |
within desktop_camera_facedetection.py
The Desktop class (inherits from Device) creates a new thread where its ComponentManager
runs.
...
Code Block | ||
---|---|---|
| ||
def connect(self, component): """ Connect the output of a component to the input of this component. :param component: The component connector providing the input to this component :type component: SICConnector :return: """ assert isinstance( component, SICConnector ), "Component connector is not a SICConnector " "(type:{})".format( type(component) ) request = ConnectRequest(component.output_channel) self._redis.request(self._request_reply_channel, request) |
within connector.py
The _handle_request
function of the actual FaceDetection component then picks up the request. It calls its _connect
method which adds the output channel of desktop.camera to its list of input channels. It also registers its _handle_message
function with Redis on this channel.
Code Block | ||
---|---|---|
| ||
def _connect(self, connection_request): """ Connect the output of a component to the input of this component, by registering the output channel to the on_message handler. :param connection_request: The component serving as an input to this component. :type connection_request: ConnectRequest :return: """ channel = connection_request.channel if channel in self._input_channels: self.logger.debug_framework( "Channel {} is already connected to this component".format(channel) ) return self._input_channels.append(channel) self._redis.register_message_handler(channel, self._handle_message) |
within component_python2.py
So now the FaceDetection component is subscribed to the output channel of the desktop.camera, and every time it receives a message on this channel, it runs the message through its _handle_message
function.
...