Initialization and Deinitialization

Function Description

  • Before calling related APIs, call the global initialization function MxInit() to allocate device and log resources for Vision SDK application development.
  • If application development involves operator calling APIs, you can call MxInitFromConfig() for global initialization. When you input the operator configuration file to load device and log resources, the involved operators are preloaded to improve the execution efficiency of the operator calling APIs.
  • To configure global variables (for example, adjusting the number of VPC channel resource pools), call MxInit(const AppGlobalCfg &globalCfg) and pass configuration parameters.

After all Vision SDK APIs are executed, call MxDeInit() to deinitialize the initialized global resources.

For details about APIs, see API Reference (C++).

Sample Code

The following are the code samples of each initialization method, which are for reference only and cannot be directly copied for compilation or running.

  • Perform global initialization to load device and log resources.
    APP_ERROR ret = MxInit();
    {
    // After global initialization, the Vision SDK APIs can be called normally.
    ...
    // After all Vision SDK APIs are executed, call the deinitialization API to destroy global resources.
    }
    ret = MxDeInit();
  • Perform global initialization, including operator preloading, to preload involved operators while loading device and log resources.
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    // Configure the operator preloading configuration file as required.
    std::string ConfigPath = "op.json";
    // Transfer the file path to the API for global initialization.
    APP_ERROR ret = MxInitFromConfig(ConfigPath);
    {
    // After global initialization, the Vision SDK APIs can be called normally.
    ...
    // After all Vision SDK APIs are executed, call the deinitialization API to destroy global resources.
    }
    ret = MxDeInit();
    
  • Perform global initialization and load global variables.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    AppGlobalCfg globalCfg;
    
    APP_ERROR ret = MxInit(globalCfg);
    {
    // After global initialization, the Vision SDK APIs can be called normally.
    ...
    // After all Vision SDK APIs are executed, call the deinitialization API to destroy global resources.
    }
    ret = MxDeInit();