简介
当今,人工智能技术已经渗透到我们生活的方方面面,其中目标检测技术是非常重要的一种技术。目标检测技术可以对图像或视频中的物体进行识别和定位,是实现自动驾驶、智能监控等众多应用的基础。
华为 Atlas 200 是一款高性能的人工智能处理器,支持多种神经网络架构和算法,包括目标检测算法。在 Atlas 200 上进行目标检测,可以利用其强大的计算能力和低延迟的数据传输性能,实现高效的物体识别和定位。
在本文中,我们将介绍如何使用 Atlas 200 提供的 sendData 和 getResult 接口,实现对 Pieline 模型的目标检测框数据读取。我们将使用 RapidJSON 库解析返回的 JSON 数据,并在 OpenCV 中绘制矩形框,以便更直观地观察目标检测的结果。
读取主函数
传入数据时使用SendData,对应取出推理结果时使用GetResult。读取图片的相关函数忽略。
std::cout << "Start reading pipeline config file." << std::endl;
std::string pipelinePath = "/home/HwHiAiUser/selfwork/MyFirstApp3/pipeline/Sample.pipeline";
std::string pipelineConfigStr = ReadPipeline(pipelinePath);
// init stream manager
MxStream::MxStreamManager mxStreamManager;
if (mxStreamManager.InitManager() != APP_ERR_OK) {
LogError << "Failed to init Stream manager.";
return APP_ERR_COMM_INIT_FAIL;
}
// create stream by pipeline config file
if (mxStreamManager.CreateMultipleStreams(pipelineConfigStr) != APP_ERR_OK) {
LogError << "Failed to create Stream.";
return APP_ERR_COMM_INIT_FAIL;
}
std::cout << "Start reading image file and building stream input." << std::endl;
MxStream::MxstDataInput dataBuffer;
if (ReadFile("/home/HwHiAiUser/selfwork/MyFirstApp3/data/1.jpg", dataBuffer) != APP_ERR_OK) {
LogError << "Failed to read image file.";
return APP_ERR_COMM_INIT_FAIL;
}
std::string streamName = "yolox";
int inPluginId = 0;
std::cout << "Start sending data into stream." << std::endl;
APP_ERROR ret = mxStreamManager.SendData(streamName, inPluginId, dataBuffer);
if (ret != APP_ERR_OK) {
LogError << GetError(ret) << "Failed to send data to stream.";
delete dataBuffer.dataPtr;
dataBuffer.dataPtr = nullptr;
return ret;
}
std::cout << "Getting output result from stream." << std::endl;
std::vector<std<