I have a function written in numba to generate 3d point cloud data for pcl_viewer. In order to convert rgb values to encoded float format as required by pcl_viewer, I use the following code
@njit
def rgb2float(r, g, b):
rgb_value = (int(r) << 16) + (int(g) << 8) + int(b)
return struct.unpack('!f', struct.pack('!I', rgb_value))[0]
@njit(parallel=True)
def get_rgb_points(points, view_matrices, img_dict):
for i in prange(len(points)):
... some code
points[i][4] = rgb2float(color[0], color[1], color[2])
return points
However, when calling this function from my main numba optimized function, I get the following error
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Failed in nopython mode pipeline (step: nopython frontend)
Unknown attribute 'unpack' of type Module(<module 'struct' from '/usr/lib/python3.6/struct.py'>)
To check if its a python version issue I checked the struct.py of python3.6, but I found the unpack function there. So I assume it is not a python version issue. I also tried setting "nopython" to True and False for the "rgb2float" function.
Is it possible to use struct.unpack inside a numba function? If not is there an alternative that I can use.
question from:
https://stackoverflow.com/questions/65896852/how-to-use-struct-unpack-in-numba-precompiled-function 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…