From 8bb3fcc6d856857dc8341fb4c7de42f6b0c23ab0 Mon Sep 17 00:00:00 2001 From: Li Zhang Date: Fri, 20 Jan 2023 00:04:42 +0800 Subject: [PATCH] fix 'cvtcolor' error in the preprocessing of single channel images (#1666) --- csrc/mmdeploy/operation/cuda/cvtcolor.cpp | 9 +++++---- csrc/mmdeploy/preprocess/transform/load.cpp | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/csrc/mmdeploy/operation/cuda/cvtcolor.cpp b/csrc/mmdeploy/operation/cuda/cvtcolor.cpp index eaff21b1a5..1e35adc06b 100644 --- a/csrc/mmdeploy/operation/cuda/cvtcolor.cpp +++ b/csrc/mmdeploy/operation/cuda/cvtcolor.cpp @@ -90,10 +90,11 @@ class CvtColorImpl : public CvtColor { auto height = src.height(); auto width = src.width(); - auto channels = src.channel(); - auto stride = width * channels; + auto src_channels = src.channel(); + auto src_stride = width * src_channels; Mat dst_mat(height, width, dst_fmt, src.type(), device()); + auto dst_stride = width * dst_mat.channel(); auto convert = [&](auto type) -> Result { using T = typename decltype(type)::type; @@ -101,8 +102,8 @@ class CvtColorImpl : public CvtColor { if (!converter) { return Status(eNotSupported); } - auto ret = - converter(cuda_stream, height, width, stride, src.data(), stride, dst_mat.data()); + auto ret = converter(cuda_stream, height, width, src_stride, src.data(), dst_stride, + dst_mat.data()); if (ret != ppl::common::RC_SUCCESS) { return Status(eFail); } diff --git a/csrc/mmdeploy/preprocess/transform/load.cpp b/csrc/mmdeploy/preprocess/transform/load.cpp index 57879d5b4b..c386957222 100644 --- a/csrc/mmdeploy/preprocess/transform/load.cpp +++ b/csrc/mmdeploy/preprocess/transform/load.cpp @@ -61,7 +61,7 @@ class PrepareImage : public Transform { if (color_type_ == "color" || color_type_ == "color_ignore_orientation") { OUTCOME_TRY(cvt_color_.Apply(src_mat, dst_mat, PixelFormat::kBGR)); } else { - OUTCOME_TRY(cvt_color_.Apply(dst_mat, dst_mat, PixelFormat::kGRAYSCALE)); + OUTCOME_TRY(cvt_color_.Apply(src_mat, dst_mat, PixelFormat::kGRAYSCALE)); } auto tensor = to_tensor(dst_mat); if (to_float32_) {