Kinect / PyKinect2

Wrapper to expose Kinect for Windows v2 API in Python
MIT License
496 stars 236 forks source link

X,Y Joint coordinates- OverflowError: cannot convert float infinity to integer #60

Closed avpai closed 5 years ago

avpai commented 5 years ago

When I come close to the sensor , I get an error saying " OverflowError: cannot convert float infinity to integer"

for the lines of code which I use to get the x,y,z co-ordinates of the joints. I tried this:

def round_int(self,x):         
        if x == float("inf") or x == float("-inf"):
            return 0 # or x or return whatever makes sense
        else:
            return int(round(x))

and used this function on the below sample or stuffs like that that gives me a x,y coordinate rightelbow_y = self.round_int(int(joint_points[PyKinectV2.JointType_ElbowRight].y))

But I am still getting this error. Any ideas or suggestions to improve this, will be much appreciated

nitzel commented 5 years ago

General idea: surround with try catch and in the catch take a closer look at the value in question to see why it doesn't equal float("inf")

nitzel commented 5 years ago

Your problem probably lies in the int(...) cast which I removed here:

rightelbow_y = self.round_int(joint_points[PyKinectV2.JointType_ElbowRight].y)

So your round_int method is probably fine but the error is created before it's invoked.

avpai commented 5 years ago

Yup. Thant seems to do the trick. Thank you so much :)