{
"remoteClasses": [
{
"name": "FaceDetectionModule",
"extends": "OpenCVFilter",
"doc": "FaceDetectionModule interface. Documentation about the module",
"constructor": {
"doc": "Create an element",
"params": [
{
"name": "mediaPipeline",
"doc": "the parent :rom:cls:`MediaPipeline`",
"type": "MediaPipeline",
"final": true
}
]
},
"methods": [
. . .
],
"events": [
"FaceFound"
]
}
],
"events": [
{
"properties": [
{
"name": "detected",
"doc": "Weather it the face is detected or not.",
"type": "boolean"
}
],
"extends": "Media",
"name": "FaceFound",
"doc": "Event raised by a :rom:cls:`FaceDetectionModule` when a face is found in the data being streamed."
}
]
}
This will create an event class for you to use the next time you build your project. The parameters it takes in the constructor are (shared_ptr, string, {any_other_props_you_defined}). The generated code provides this constructor:
FaceFound (std::shared_ptr<MediaObject> source, const std::string &type, bool detected) : Media (source, type)Then you need to add a few things in the {module_name}Impl.hpp and
{module_name}Impl.cpp (NOT {module_name}OpenCVImpl.cpp). This gets into gstreamer and I have no experience with it at all. This is where I am going to omit what I did here and move to how to use the event that is generated by the kmd.json file.
You usually use the Message Bus to put a "face-found" message onto the bus and then emit the corresponding event when you find the message with the correct name, but I am not sure how to do this properly.
So I found a hack way of doing what I need. In my case there are a good amount of messages being passed during the video processing. I just have an if-statement for whenever I need to send my event. Here is the code for when a message comes onto the bus: FaceDetectionModule.cpp
void FaceDetectionModuleImpl::busMessage (GstMessage *message)
{
bool emitState = FaceDetectionModuleOpenCVImpl::getEmitState();
if (emitState){
try {
FaceFound event (shared_from_this(), "face-found", FaceDetectionModuleOpenCVImpl::getFaceDetected());
sigcSignalEmit(signalFaceFound, event);
FaceDetectionModuleOpenCVImpl::setEmitState(!emitState);
} catch (std::bad_weak_ptr &e) {
}
}
}