|
| virtual QWidget * | getSettingsWidget (QWidget *parent)=0 |
| | getSettingsWidget is provides an QWidget to display plugin specific settings to the user. Keep in mind that the widget will run in gui thread while this ITransform instance is moved to a worker thread! Use DirectConnection for signals between the widget and this instance or ensure thread safety for interaction.
|
| |
| virtual QString | getName () const =0 |
| | getName returns the display name for the plugin.
|
| |
| virtual ITransform * | copy ()=0 |
| | copy creates a new ITransform instance which is a deep copy.
|
| |
| virtual TransformResult | transform (uint idx, const cv::Mat &img, const Resolution &resolution, const ROI &roi)=0 |
| | transform generates additional images from the given image. The signal sendToGui can be used to update the preview for the user.
|
| |
| virtual void | enableCuda (bool enabled)=0 |
| | enableCuda enables use of the CUDA api to accelerate computations.
|
| |
| virtual void | setSettings (QMap< QString, QVariant > settings)=0 |
| | setter for plugin's settings
|
| |
| virtual QMap< QString, QVariant > | getSettings ()=0 |
| | getter for plugin's settings
|
| |
|
virtual void | activate () |
| | activate will be called before the plugin is used, i.e. when the user selects it in the seampling window or when exporting.
|
| |
|
virtual void | deactivate () |
| | deactivate will be called when the plugin is no longer used, i.e. when the user deselects it in the sampling window or when exporting finishes. This should be used to free resources such as gpu memory.
|
| |
The ITransform interface is used for algorithms to create additional image files from the source images. Plugins for this interface are dynamically loaded from the plugins folder. Each ITransform needs to provide an QWidget for user interaction and a display name. Using the transform method, the plugin can create additional images such as semantic maps for the given source image.
Since calculation on images can be computationally expensive, the ITransform instance is moved to a worker thread. Previews for the gui can be sent to the gui thread using the sendToGui signal.
Keep in mind that the QWidget provided by getSettingsWidget will run in the gui thread while the ITransform instance itself is moved to a worker thread. Intraction between the QWidget and ITransform has to be threadsafe!
- See also
- SemanticSegmentation
- Date
- 2021/03/30
- Author
- Dominik Wüst
This example shows how to create a ITransform plugin and a settings widget with a button:
Q_OBJECT
Q_PLUGIN_METADATA(IID "pse.iVS3D.ITransform")
QWidget *settingsWidget = nullptr;
cv::Mat image;
uint imageIdx;
private slots:
void onButtonPressed(){
cv::Mat preview = cv::convert(image, RGB2GREY);
emit sendToGui(imageIdx, preview);
}
public:
QWidget* getSettingsWidget(QWidget* parent){
if(settingsWidget) return settingWidget;
auto *button = new QPushButton(parent, "Press me");
settingsWidget = new QWidget(parent);
settingsWidget->layout()->addWidget(button);
connect(button, &QPushButton::pressed, this, &Plugin::onButtonPressed, Qt::DirectConnection);
}
ImageList transform(uint idx, const cv::Mat &img){
image = img;
imageIdx = idx;
auto res = doWork();
emit sendToGui(imageIdx,res[0]);
return res;
}
};
The Button on the settingsWidget is connected to the plugin using the threadsafe DirectConnection. This allows to calculate computationally expensive previews in the worker thread and update the gui after calculation has finished.