I am trying to rewrite a small portion of C++ code in python. Below is a snippet with the unimportant parts removed. It simply assigns to the variable z
the value of the depth_image
at location [x,y]
. However, I don't understand the purpose of the shift operation <<
.
const ::CByteImage& depth_image
const unsigned int offset = (y * width + x) * 3;
const float z = static_cast<unsigned int>(
depth_image.pixels[offset + /* R = */ 0]
+ (depth_image.pixels[offset + /* G = */ 1] << /* sizeof(char) = */ 8)
+ (depth_image.pixels[offset + /* B = */ 2] << /* 2*sizeof(char) = */ 16)
);
If read in python, the variable depth_image
is an array of shape [640,480,3]
. Would the equivalent simply be to sum all 3 channels?
depth_image = cv2.imread(depth_filename)
x,y = 0,0
z = depth_image[y,x,0] + (depth_image[y,x,1] << 8) + (depth_image[y,x,2] << 16)
I have zero knowledge in C++.