【Atlas200】继承MxBase类自制插件(C++),以官方例程为例

MindX SDK简介

MindX是一款针对昇腾系列AI芯片的软件开发工具包(SDK),它提供了一系列的API和工具,帮助开发者对昇腾系列AI芯片进行开发和优化。提供了一系列的部署工具,可以将优化后的AI模型部署到昇腾AI芯片上,进行实时推理,实现低延迟、高性能的AI应用。其突出特点是使用流程编排进行开发。

总的来说,MindX SDK为开发者提供了一套完整的开发环境和工具,帮助开发者轻松地进行昇腾系列AI芯片的开发、优化和部署,实现高性能、低功耗的AI应用。
在这里插入图片描述

插件的Buffer与Metadata

Plugin表示业务流程中的基础模块,通过Element的串接构建成一个Stream。Buffer用于内部挂载解码前后的视频、图像数据,是Element之间传递的数据结构,同时也允许用户挂载元数据(Metadata),用于存放结构化数据(如目标检测结果)或过程数据(如缩放后的图像)。如下图,Metadata依附于buffer。
在这里插入图片描述
在这里插入图片描述

自定义插件

Init初始化接口

virtual APP_ERROR Init(std::map<std::string, std::shared_ptr<void>>& configParamMap) = 0;

插件json版:该插件名为mxpi_webpushstream0

"mxpi_webpushstream0": {
   
    "props": {
   
        "dataSourceCoordinate": "mxpi_objectpostprocessor0",
        "channelId": "0",
        "deviceId": "0"
    },
    "factory": "mxpi_webpushstream",
    "next": "fakesink0"
},

获取基础资源,获取控件的基本属性(“props”),读取的原始属性都是字符串,需要进行转换,也可以读取本地自定义的配置文件:

APP_ERROR WebPushStream::Init(std::map<std::string, std::shared_ptr<void>>& configParamMap)
{
   
     for (const auto& kv : configParamMap) {
   
        const std::string& key = kv.first;
        std::cout<<key;
     }
    channelId_ = *std::static_pointer_cast<uint>(configParamMap["channelId"]);
    if (channelId_ == -1) {
   
        LogInfo << "Failed to read the channelId";
        return APP_ERR_COMM_INIT_FAIL;
    }
    coordinateDataSource_ = *std::
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
好的,下面是线程池的代码和附带的例程: 代码: ```c++ #include <queue> #include <thread> #include <vector> #include <functional> #include <condition_variable> class ThreadPool { public: ThreadPool(size_t threads) : stop(false) { for (size_t i = 0; i < threads; ++i) { workers.emplace_back([this] { for (;;) { std::function<void()> task; { std::unique_lock<std::mutex> lock(this->queue_mutex); this->condition.wait(lock, [this] { return this->stop || !this->tasks.empty(); }); if (this->stop && this->tasks.empty()) return; task = std::move(this->tasks.front()); this->tasks.pop(); } task(); } }); } } template<class F, class... Args> auto enqueue(F&& f, Args&&... args) -> std::future<typename std::result_of<F(Args...)>::type> { using return_type = typename std::result_of<F(Args...)>::type; auto task = std::make_shared<std::packaged_task<return_type()>>(std::bind(std::forward<F>(f), std::forward<Args>(args)...)); std::future<return_type> res = task->get_future(); { std::unique_lock<std::mutex> lock(queue_mutex); if (stop) throw std::runtime_error("enqueue on stopped ThreadPool"); tasks.emplace([task] { (*task)(); }); } condition.notify_one(); return res; } ~ThreadPool() { { std::unique_lock<std::mutex> lock(queue_mutex); stop = true; } condition.notify_all(); for (std::thread &worker : workers) worker.join(); } private: std::vector<std::thread> workers; std::queue<std::function<void()>> tasks; std::mutex queue_mutex; std::condition_variable condition; bool stop; }; ``` 例程: ```c++ #include <iostream> #include <chrono> #include <thread> #include "ThreadPool.h" int main() { ThreadPool pool(4); std::vector<std::future<int>> results; for (int i = 0; i < 8; ++i) { results.emplace_back( pool.enqueue([i] { std::cout << "task " << i << " started\n"; std::this_thread::sleep_for(std::chrono::seconds(1)); std::cout << "task " << i << " finished\n"; return i * i; }) ); } for (auto && result : results) std::cout << result.get() << ' '; std::cout << std::endl; return 0; } ``` 这个例程中,我们定义了一个线程池,使用大小为4的线程池,并在其中运行8个任务,每个任务都是一个延时1秒的函数,每个任务完成后返回其自身的平方值。运行完毕后,打印输出这8个任务的结果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

颢师傅

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值