void TransformMatToTensor(const cv::Mat &image, Tensor &input_tensor, int input_width, int input_height)
{
    
    int Channel = image.channels();

    int Stride = input_width * Channel;
    float *source_data = (float *)image.data;

    auto input_tensor_mapped = input_tensor.tensor<float, 4>();

    LOG(INFO) << "input_tensorinput_tensorinput_tensor_shape_before : " << input_tensor.shape();
    for (int y = 0; y < input_height; ++y)
    {
        float *source_row = source_data + y * Stride;
        for (int x = 0; x < input_width; ++x)
        {
            float *source_pixel = source_row + (x * Channel);
            for (int ch = 0; ch < Channel; ++ch)
            {
                input_tensor_mapped(0, y, x, ch) = (float)*(source_pixel + ch);
            }
        }
    }
}

 

相关文章:

  • 2021-06-19
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
  • 2021-04-16
  • 2021-10-28
  • 2021-06-30
猜你喜欢
  • 2021-07-23
  • 2021-12-01
  • 2021-06-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-02
相关资源
相似解决方案