Value Error : too many values to unpack
Ankitjaiswal1201 opened this issue · 5 comments
When I converted my depth images to .pkl file and ran the code, it gives me this error.
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-13-4693c0abb786> in <module>
1 hole_filter = HoleFilling_Filter(flag='min')
----> 2 hf_image_frame = hole_filter.smooth_image_frames(image_frame)
3 print('hole filled image frames (filled invalid values)')
4 plot_image_frame(hf_image_frame)
~/Desktop/Research Project/Matlab Code/Kinect_Smoothing-master/kinect_smoothing/depth_image_smoothing.py in smooth_image_frames(self, image_frames)
167 imgs=[imgs]
168 for img in imgs:
--> 169 res_img = self.smooth_image(img)
170 smoothed_frames.append(res_img)
171 return smoothed_frames
~/Desktop/Research Project/Matlab Code/Kinect_Smoothing-master/kinect_smoothing/depth_image_smoothing.py in smooth_image(self, image)
149 image = image.copy()
150 if self.flag in ['min','max','mean','mode']:
--> 151 smoothed_image = self.statistical_smoothing(image)
152 elif self.flag in ['fmi','ns']:
153 smoothed_image = self.inpainting_smoothing(image)
~/Desktop/Research Project/Matlab Code/Kinect_Smoothing-master/kinect_smoothing/depth_image_smoothing.py in statistical_smoothing(self, image)
110 """
111 smoothed = image.copy()
--> 112 h, w = image.shape
113 image[image <= self.valid_depth_min] = 0
114 image[image >= self.valid_depth_max] = 0
ValueError: too many values to unpack (expected 2)
Hi,
I think that is because of your depth image has a shape of (height,width , 3)
. In order to use this code, you need to convert your image to gray-scale.
method 1, just used 1st channel of depth image:
old_image_frames = joblib.load(''image_frames.pkl')
new_image_frames = [img[:,:,0] for img in old_image_frames ]
method 2, read the image in grayscale :
img = cv2.imread(imgfile, cv2.IMREAD_GRAYSCALE)
# or
img = plt.imread(imgfile)
Hi,
Yes, my depth image has the shape of (height, width,3).
I have to preserve this format as the next process is of RGB and depth registration/mapping and all the 3 values x, y and z are required later.
Hi,
I think you can save the RGB image in another variable. The function hole_filter.smooth_image_frames
only process the depth image (must be a depth image, not an RGB image) with shape (height, width). Since this function does not change the shape of the depth image, you can easily correspond to the original image after smoothed by the function hole_filter.smooth_image_frames
.
Hi,
Yes, I am using it only for Depth Image but my depth image also has x, y & z coordinates. That's why it is of shape (height, width,3). Later after smoothing the depth image, I have to use it further to generate a point cloud using RGB-Depth registration which has a size (height, width, 6).
So if I change the shape, I will be losing important data from a depth image.
So I think, I will have to check for some other method.
Hi,
I think you can separately process each channel of your depth image.
imgs= joblib.load(''image_frames.pkl')
smoothed_imgs=[img.copy() for img in imgs]
for cnl in range(3):
imgs_cnl = [img[:,:,cnl] for img in imgs] # with a shape of (height, width)
smoothed_imgs_cnl = hole_filter.smooth_image_frames(imgs_cnl)
for ind in range(len(smoothed_imgs)):
smoothed_imgs[ind][:,:,cnl] = smoothed_imgs_cnl[ind]