PyKinect2-Mapper-Functions icon indicating copy to clipboard operation
PyKinect2-Mapper-Functions copied to clipboard

when using color_point_2_depth_point, sometime an error will occur

Open jdyjjj opened this issue 2 years ago • 10 comments

as you can see in this picture, this is my code. image and there will always be an error:

Traceback (most recent call last):
  File "video_kinect.py", line 462, in <module>
    x,y = color_point_2_depth_point(a._kinect,_DepthSpacePoint,a._kinect._depth_frame_data,[int(center_x),int(center_y)])
  File "video_kinect.py", line 365, in color_point_2_depth_point
    return [int(depth_x), int(depth_y)]
OverflowError: cannot convert float infinity to integer

I really can not understand why this error occurs. Thank you!

jdyjjj avatar May 27 '22 14:05 jdyjjj

Hello, the problem is with int(center_x), int(center_y). you cannot be sure that the Kinect values will always be numeric (float or int). The kinect is susceptible to external noise, such as light and reflections, and its values can overflow and return as '-inf'.

Thus, the error: cannot convert float infinity to int

i suggest you do int(center_x) if center_x != float('-inf') and center_x != float('inf') else center_x, and the same for center_y

or better:

int(center_x) if center_x != float('-inf') and center_x != float('inf') else 0

KonstantinosAng avatar May 27 '22 14:05 KonstantinosAng

image

jdyjjj avatar May 27 '22 14:05 jdyjjj

Thank you for your answering. But the reason for this error is depth_x and depth_y is inf. And center_x and center_y is int.

jdyjjj avatar May 27 '22 14:05 jdyjjj

Then you have to handle their value:

Also numpy can filter these values faster with:

color2depth_points = color2depth_points[np.all(color2depth_points != float('-inf'), axis=1)] # remove -inf

and then do:

depth_x = color2depth_points[color_point[1] * 1920 + color_point[0] - 1].x depth_y = color2depth_points[color_point[1] * 1920 + color_point[0] - 1].y

KonstantinosAng avatar May 27 '22 14:05 KonstantinosAng

Thank you for your answer. I try your method to remove inf, but this method will make a new error that in this picture: image

jdyjjj avatar May 27 '22 14:05 jdyjjj

try removing the option axis=1

color2depth_points = color2depth_points[np.all(color2depth_points != float('-inf'))] # remove -inf

KonstantinosAng avatar May 27 '22 14:05 KonstantinosAng

This is bug now, but I really don't know why this error occurs.

image

image

jdyjjj avatar May 27 '22 14:05 jdyjjj

ok, I think it is better for me to change it in the library than this. I will push the changes in short in this repo

KonstantinosAng avatar May 27 '22 14:05 KonstantinosAng

run git pull and try again without the:

color2depth_points = color2depth_points[np.all(color2depth_points != float('-inf'))] # remove -inf

KonstantinosAng avatar May 27 '22 14:05 KonstantinosAng

thanks!

---Original--- From: @.> Date: Fri, May 27, 2022 22:54 PM To: @.>; Cc: "Jin @.@.>; Subject: Re: [KonstantinosAng/PyKinect2-Mapper-Functions] when using color_point_2_depth_point, sometime an error will occur (Issue #10)

ok, I think it is better for me to change it in the library than this. I will push the changes in short in this repo

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

jdyjjj avatar Oct 11 '22 07:10 jdyjjj