magicpy icon indicating copy to clipboard operation
magicpy copied to clipboard

TypeError: 'float' object cannot be interpreted as an integer

Open Foxy6670 opened this issue 3 years ago • 2 comments

Every time I try to run ./example.sh, this happens:

Traceback (most recent call last):
  File "/home/user/magicpy/magicpy.py", line 53, in <module>
    pattern = gen_pattern(pattern_width, depth_map.size[1])
  File "/home/user/magicpy/magicpy.py", line 27, in gen_pattern
    return numpy.random.randint(0, 256, (width, height))
  File "mtrand.pyx", line 765, in numpy.random.mtrand.RandomState.randint
  File "_bounded_integers.pyx", line 1256, in numpy.random._bounded_integers._rand_int64
TypeError: 'float' object cannot be interpreted as an integer

Foxy6670 avatar Jan 11 '23 23:01 Foxy6670

This is related to the fact, that the calculation of the patterns with returned a float value, replace:

pattern_width = depth_map.size[0] / args.pattern_div

with:

pattern_width = int(depth_map.size[0] / args.pattern_div)

You are almost certainly are using Python 3 the code is written for Python 2, you'll need to fix few more things:

  • Replace xrange with range
  • Cast values from the pattern array to int, since Numpy uses a different int internally.:
    int(pattern[x, y])
    

cmahnke avatar Jan 22 '23 19:01 cmahnke