IndexError:索引1超出了轴0的范围,大小为1 // Python

时间:2016-11-25 10:49:46

标签: python python-3.x index-error

我收到此代码的错误消息:

    def capture_and_decode(self, bitrange = 2, axes = [1]):

    cam_width, cam_height = self.camera.resolution
    #cam_width = 640
    #cam_height = 480
    print ('a')
    scr_range = self.display.displaywindow.resolution
    self.raw_images = numpy.empty((len(axes), cam_height, cam_width, bitrange))
    imgs = []
    for axis in axes:

       for bits in range(0, bitrange):
           stripe_width = cam_width // 2 ** (bits + 1)
           #print(stripe_width)
           binary = numpy.fromiter(GrayCode(bits + 1).generate_gray(), dtype=numpy.int) % 2
           vector = numpy.repeat(binary, stripe_width)
           imgs = numpy.tile(vector, (cam_height, 1))
           print ('b')
       self.display.displaywindow.show(imgs)  # TODO: handle sleep in display module
       time.sleep(0.25)
       self.raw_images[axis, :, :,  bitrange] = self.camera.capture()

    imgs_v = self.raw_images[0].reshape(cam_height, cam_width, -1)
    print('c')
    imgs_h = self.raw_images[1].reshape(cam_height, cam_width, -1)
    print('C')


    self.registration, self.modulation = decode(imgs_v, imgs_h, bitrange)
    print('d')
    self.sigCaptureDone.emit(self.registration)

    with h5py.File("test.h5", "w") as f:
        f.create_dataset("registration", data=self.registration)
        print('e')
        f.create_dataset("modulation", data=self.modulation)
        print('finish')

文件" ............. / GrayCodeWidget.py",第89行,在capture_and_decode中     self.raw_images [axis,:,:,bitrange] = self.camera.capture() IndexError:索引1超出轴0的大小为1

1 个答案:

答案 0 :(得分:0)

我不熟悉Python,但通常索引应该从0开始。

使用是否合法: def capture_and_decode(self, bitrange = 2, axes = [0]):