Getting error "'NoneType' object has no attribute 'astype'"

I have been trying to implement a project on POINT CLOUD COMPLETION but have been facing the error ‘NoneType’ object has not attribute ‘astype’, I have checked the path of the files which is correct and I have installed opencv 3.4.1 on python2.7 because this is an old project and requires old libraries.
I am getting error in add_kinect_v1_noise of pc_cmpletion_util file which is getting called from the main file in load_image “im=add_kinect_v1_noise(im)”
And it shows error on “dm_m = dm.astype(float) * 0.0001 / scale / 1000” in pc_completion_util
The main file of the project is this :

def load_image(self, file_name, add_noise = False):
im = read_png16(file_name)
if add_noise:
im = add_kinect_v1_noise(im)
im = depthmap_16bitTofloat(im)
return im
This is the func from main file which calling the func add_kinect_v1_noise from util files.

def read_png16(file_name):
CV_LOAD_IMAGE_ANYDEPTH = 2 # apparently leftover from cv before cv2
int16_d_image = cv2.imread(file_name, CV_LOAD_IMAGE_ANYDEPTH)
return int16_d_image

def add_kinect_v1_noise(dm): # operates on the uint16
scale = 0.003
dm_m = dm.astype(float) * 0.0001 / scale / 1000

p_world = dm2points(dm_m)
X = np.reshape(p_world[0,:], (128,128))
Y = np.reshape(p_world[1,:], (128,128))
Z = np.reshape(p_world[2,:], (128,128))

if np.min(Z) <= 0.01:
    print ("ZERO?")

nz, angles = surfnorm_fast(X,Y,Z)

dm_m_noise = add_noise(dm_m, Z, angles)

return (dm_m_noise * 1000 * scale / 0.0001).astype(np.uint16)

Hi,
you want us to debug 700 lines?

May be you can try to use a debugger and set a breakpoint before error to investigate…

No I am asking to debug all the lines I have just given all the code for reference, I’ll edit the post so that only the part with issue is left.

this must be the 5162th “imread() returned an empty image, and python user did not expect that” post.

1 Like

But the path is correct I have printed the path to see if it is correct or not

go and check the output from imread(), please

you check that using os.path.exists(), in case you were wondering.