I have reviewed your C++ code. The issue lies in the fact that your code does not utilize cv::split to separate the channels of the input image for the tensor data. It is necessary to split the channels and employ a buffer that is sufficiently large to rearrange the data into the following format: [r0, r1, r2, ..., rn], [g0, g1, g2, ..., gn], [b0, b1, b2, ..., bn]. Additionally, for the output tensor data, you should apply the reverse process and use cv::merge to reassemble the channels back into an RGB image.