Developing a Plugin

By Creating a Plugin Development Project

  1. Navigate to the project creation window.
    • On the MindStudio welcome page, click New Project.
    • On the MindStudio project page, choose File > New > Project... from the top menu bar.
  2. In the New Project window, select Ascend App and specify the project type. See Figure 1. (If the project type name is not completely displayed, hover the cursor on the name to display the complete name.)

    CANN Version: indicates the activated CANN version. You can click Change on the right to change the CANN version. For details, see Switching/Activating a CANN Package.

    If CANN is not configured in MindStudio, some application projects may not be properly displayed.

    Figure 1 Plugin development project
    • MindX SDK Plugin: creates an empty project for MindX SDK plugin development that contains only the development framework and does not contain specific code logic.
    • MxpiSamplePlugin: creates a sample project for MindX SDK plugin development.
  3. Click Next to set the project parameters, as described in Table 1.
    Table 1 Project parameters

    Parameter

    Description

    Project name

    Project name (user-defined).

    Project location

    Default path for saving a project (user-defined). (For users who use MindStudio for the first time, the default value is $HOME/MindstudioProjects)

    More Settings

    Module name: module name, the same as the Project name.

    Content root: path in the root directory.

    Module file location: module file path.

    Click the check box on the right of Project format. A drop-down list is displayed.
    • .idea (directory-based) (default option): During project creation, an .idea project directory is created to save the project information.
    • .ipr (file-based): project configuration file used to save the project configuration information.
  4. Click Finish. The directory of a created project is organized as follows (for reference only).
    • MindX SDK Plugin:

      Set the name of the empty project for MindX SDK plugin development (that is, the project name in the following project directory) to the name of the developed plugin.

      ├── Project name
          ├── build                       // Directory of CMake dependencies.
          ├── lib
          │   └── plugins                // Directory for storing the .so files of the developed plugin.
          ├── src
          │   └── Project name
          │        ├── CMakeLists.txt    // Build script.
          │        ├── Project name.cpp         // Implementation file of the main function.
          │        └── Project name.h           // Dependent header file of the main function.
          └── CMakeLists.txt              // Build script that calls the CMakeLists file in the src directory.
    • MxpiSamplePlugin:
      ├── Project name
          ├── build               // Directory of CMake dependencies.
          ├── lib
          │   └── plugins        // Directory for storing the .so files of the developed plugin.
          ├── src
          │   └── mxpi_sampleplugin
          │        ├── CMakeLists.txt         // Build script.
          │        ├── MxpiSamplePlugin.cpp   // Implementation file of the main function.
          │        └── MxpiSamplePlugin.h     // Dependent header file of the main function.
          └── CMakeLists.txt                   // Build script that calls the CMakeLists file in the src directory.
  5. For details about the code implementation of the empty plugin development project, see "Plugin Development Introduction" in the mxManufacture User Guide or mxVision User Guide.

    For details about the code implementation of the sample project for plugin development, see MxpiSamplePlugin.cpp (implementation file of the main function) and MxpiSamplePlugin.h (dependent header file of the main function) in the project file.

  6. Develop and build the plugin. The following uses the plugin development sample project as an example.
    1. On the MindStudio project page, choose Build > Edit Build Configuration... from the top menu bar. The build configuration page is displayed. For details about parameter settings, see Building and Running an Application Project.
    2. After the build is complete, the .so file of the developed plugin is generated in project directory/lib/plugins. See Figure 2.
    3. On the top menu bar, choose Ascend > MindX SDK Pipeline to open the pipeline drawing page. Then click Plugin Manager in the lower right corner to configure the custom plugin directory. For details about how to configure the custom plugin function, see Table 2.
    4. Find the plugin MxpiSamplePlugin in the plugin library and use it properly (for example, you can drag the plugin to the editing area, connect it to other plugins, and view plugin attributes). See Figure 2.
      Figure 2 Plugin development

By Adding a Plugin Template

  1. After creating an empty project MindX SDK Project(C/C++) or a sample project Detection and Classification(C++), right-click the project name in the project directory on the IDE page and choose New MindX SDK Plugin from the shortcut menu. The dialog box shown in Figure 3 is displayed.
    Figure 3 Plugin creation dialog box
    • Plugin Name: user-defined plugin name.
    • Plugin Path: plugin creation directory. You are advised to place the plugin in the plugin directory of the project. If the directory does not exist, create it.
  2. After the project is created, check the following directory levels generated in the project directory. The value of Plugin Name is the plugin name set in Figure 3.
    └── plugin
       └── Plugin Name          // Plugin template.
            ├── Plugin Name.cpp
            ├── Plugin Name.h
            └── CMakeLists.txt
  3. In the CMakeLists.txt file (shown as 1 in the following figure) in the root directory of the project or the CMakeLists.txt file (shown as 2 in the following figure) in the C++ directory, locate the CMakeLists.txt file (shown as 3 in the following figure) of the new plugin, to add the new plugin to the compilation process.

    The following uses the plugin mxpi_sample as an example.

    • Add the following information to the CMakeLists.txt file in the root directory of the project file:
      add_subdirectory("./plugin/mxpi_sample")

      ./plugin/mxpi_sample indicates the path of the CMakeLists.txt file of the new plugin relative to the CMakeLists.txt file in the root directory of the project file.

    • Add the following information to the CMakeLists.txt file in the C++ directory of the project file:
      add_subdirectory("../plugin/mxpi_sample")

      ../plugin/mxpi_sample indicates the path of the CMakeLists.txt file of the new plugin relative to the CMakeLists.txt file in the C++ directory of the project file.

    Figure 4 add_subdirectory

  4. After the build is complete, find the .so file generated in the root directory of the project file/lib/plugins, and set the file permission to 640.
  5. For details about how to develop a plugin, see "Plugin Development Introduction" in the mxManufacture User Guide or mxVision User Guide.