diff --git a/model_zoo/official/cv/dpn/infer/mxbase/src/DPN.cpp b/model_zoo/official/cv/dpn/infer/mxbase/src/DPN.cpp index 0bbe566009c..b92f9b5ac0b 100644 --- a/model_zoo/official/cv/dpn/infer/mxbase/src/DPN.cpp +++ b/model_zoo/official/cv/dpn/infer/mxbase/src/DPN.cpp @@ -81,20 +81,20 @@ APP_ERROR DPN::DeInit() { return APP_ERR_OK; } -APP_ERROR DPN::ReadImage(const std::string &imgPath, cv::Mat &imageMat) { - imageMat = cv::imread(imgPath, cv::IMREAD_COLOR); +APP_ERROR DPN::ReadImage(const std::string &imgPath, cv::Mat *imageMat) { + *imageMat = cv::imread(imgPath, cv::IMREAD_COLOR); return APP_ERR_OK; } -APP_ERROR DPN::ResizeImage(const cv::Mat &srcImageMat, cv::Mat &dstImageMat) { +APP_ERROR DPN::ResizeImage(const cv::Mat &srcImageMat, cv::Mat *dstImageMat) { static constexpr uint32_t resizeHeight = 224; static constexpr uint32_t resizeWidth = 224; - cv::resize(srcImageMat, dstImageMat, cv::Size(resizeWidth, resizeHeight)); + cv::resize(srcImageMat, *dstImageMat, cv::Size(resizeWidth, resizeHeight)); return APP_ERR_OK; } -APP_ERROR DPN::CVMatToTensorBase(const cv::Mat &imageMat, MxBase::TensorBase &tensorBase) { +APP_ERROR DPN::CVMatToTensorBase(const cv::Mat &imageMat, MxBase::TensorBase *tensorBase) { uint32_t dataSize = 1; for (size_t i = 0; i < modelDesc_.inputTensors.size(); ++i) { std::vector shape = {}; @@ -131,12 +131,12 @@ APP_ERROR DPN::CVMatToTensorBase(const cv::Mat &imageMat, MxBase::TensorBase &te return ret; } std::vector shape = {32, 224, 224, 3}; - tensorBase = TensorBase(memoryDataDst, false, shape, TENSOR_DTYPE_UINT8); + *tensorBase = TensorBase(memoryDataDst, false, shape, TENSOR_DTYPE_UINT8); return APP_ERR_OK; } APP_ERROR DPN::Inference(const std::vector &inputs, - std::vector &outputs) { + std::vector *outputs) { auto dtypes = model_->GetOutputDataType(); for (size_t i = 0; i < modelDesc_.outputTensors.size(); ++i) { std::vector shape = {}; @@ -149,12 +149,12 @@ APP_ERROR DPN::Inference(const std::vector &inputs, LogError << "TensorBaseMalloc failed, ret=" << ret << "."; return ret; } - outputs.push_back(tensor); + outputs->push_back(tensor); } DynamicInfo dynamicInfo = {}; dynamicInfo.dynamicType = DynamicType::STATIC_BATCH; auto startTime = std::chrono::high_resolution_clock::now(); - APP_ERROR ret = model_->ModelInference(inputs, outputs, dynamicInfo); + APP_ERROR ret = model_->ModelInference(inputs, *outputs, dynamicInfo); auto endTime = std::chrono::high_resolution_clock::now(); // save time double costMs = std::chrono::duration(endTime - startTime).count(); @@ -167,8 +167,8 @@ APP_ERROR DPN::Inference(const std::vector &inputs, } APP_ERROR DPN::PostProcess(const std::vector &inputs, - std::vector> &clsInfos) { - APP_ERROR ret = post_->Process(inputs, clsInfos); + std::vector> *clsInfos) { + APP_ERROR ret = post_->Process(inputs, *clsInfos); if (ret != APP_ERR_OK) { LogError << "Process failed, ret=" << ret << "."; return ret; @@ -209,25 +209,25 @@ APP_ERROR DPN::Process(const std::vector &batchImgPaths) { std::vector batchImgMat; for (auto &imgPath : batchImgPaths) { cv::Mat imageMat; - ret = ReadImage(imgPath, imageMat); + ret = ReadImage(imgPath, &imageMat); if (ret != APP_ERR_OK) { LogError << "ReadImage failed, ret=" << ret << "."; return ret; } - ResizeImage(imageMat, imageMat); + ResizeImage(imageMat, &imageMat); batchImgMat.push_back(imageMat); } cv::Mat inputBlob = cv::dnn::blobFromImages(batchImgMat, 1.0f, cv::Size(), cv::Scalar(), false, false); inputBlob.convertTo(inputBlob, CV_8U); TensorBase tensorBase; - ret = CVMatToTensorBase(inputBlob, tensorBase); + ret = CVMatToTensorBase(inputBlob, &tensorBase); if (ret != APP_ERR_OK) { LogError << "CVMatToTensorBase failed, ret=" << ret << "."; return ret; } inputs.push_back(tensorBase); auto startTime = std::chrono::high_resolution_clock::now(); - ret = Inference(inputs, outputs); + ret = Inference(inputs, &outputs); auto endTime = std::chrono::high_resolution_clock::now(); // save time double costMs = std::chrono::duration(endTime - startTime).count(); @@ -237,7 +237,7 @@ APP_ERROR DPN::Process(const std::vector &batchImgPaths) { return ret; } std::vector> BatchClsInfos = {}; - ret = PostProcess(outputs, BatchClsInfos); + ret = PostProcess(outputs, &BatchClsInfos); if (ret != APP_ERR_OK) { LogError << "PostProcess failed, ret=" << ret << "."; return ret; diff --git a/model_zoo/official/cv/dpn/infer/mxbase/src/DPN.h b/model_zoo/official/cv/dpn/infer/mxbase/src/DPN.h index cd3aff9814c..b029a569be1 100644 --- a/model_zoo/official/cv/dpn/infer/mxbase/src/DPN.h +++ b/model_zoo/official/cv/dpn/infer/mxbase/src/DPN.h @@ -39,12 +39,12 @@ class DPN { public: APP_ERROR Init(const InitParam &initParam); APP_ERROR DeInit(); - APP_ERROR ReadImage(const std::string &imgPath, cv::Mat &imageMat); - APP_ERROR ResizeImage(const cv::Mat &srcImageMat, cv::Mat &dstImageMat); - APP_ERROR CVMatToTensorBase(const cv::Mat &imageMat, MxBase::TensorBase &tensorBase); - APP_ERROR Inference(const std::vector &inputs, std::vector &outputs); + APP_ERROR ReadImage(const std::string &imgPath, cv::Mat *imageMat); + APP_ERROR ResizeImage(const cv::Mat &srcImageMat, cv::Mat *dstImageMat); + APP_ERROR CVMatToTensorBase(const cv::Mat &imageMat, MxBase::TensorBase *tensorBase); + APP_ERROR Inference(const std::vector &inputs, std::vector *outputs); APP_ERROR PostProcess(const std::vector &inputs, - std::vector> &clsInfos); + std::vector> *clsInfos); APP_ERROR Process(const std::vector &batchImgPaths); // get infer time double GetInferCostMilliSec() const {return inferCostTimeMilliSec;} diff --git a/model_zoo/official/cv/dpn/infer/mxbase/src/main.cpp b/model_zoo/official/cv/dpn/infer/mxbase/src/main.cpp index a7991e606a6..aeef9cfb418 100644 --- a/model_zoo/official/cv/dpn/infer/mxbase/src/main.cpp +++ b/model_zoo/official/cv/dpn/infer/mxbase/src/main.cpp @@ -23,7 +23,7 @@ namespace { const uint32_t BATCH_SIZE = 32; } // namespace -APP_ERROR ScanImages(const std::string &path, std::vector &imgFiles) { +APP_ERROR ScanImages(const std::string &path, std::vector *imgFiles) { DIR *dirPtr = opendir(path.c_str()); if (dirPtr == nullptr) { LogError << "opendir failed. dir:" << path; @@ -36,7 +36,7 @@ APP_ERROR ScanImages(const std::string &path, std::vector &imgFiles continue; } - imgFiles.emplace_back(path + "/" + fileName); + imgFiles->push_back(path + "/" + fileName); } closedir(dirPtr); return APP_ERR_OK; @@ -65,7 +65,7 @@ int main(int argc, char* argv[]) { std::string imgPath = argv[1]; std::vector imgFilePaths; - ret = ScanImages(imgPath, imgFilePaths); + ret = ScanImages(imgPath, &imgFilePaths); if (ret != APP_ERR_OK) { return ret; }