2016-11-23 76 views
-3

我有這個TypeError: capture_and_decode() missing 2 required positional arguments: 'bitrange' and 'axes'Python TypeError:缺少2個必需的位置參數//我該如何解決它?

我的代碼是這一個:

def capture_and_decode(self, bitrange, axes): 
    cam_width, cam_height = self.camera.resolution 
    scr_range = self.display.displaywindow.resolution 
    self.raw_images = numpy.empty((len(axes), cam_height, cam_width, bitrange)) 

    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) 
      img = numpy.tile(vector, (cam_height, 1)) 

     self.display.displaywindow.show(img) 
     time.sleep(0.25) 
     self.raw_images[axis, :, :, bits] = self.camera.capture() 

錯誤是在最後一行。

+0

你在哪裏調用'capture_and_decode(..)'?你能分享你的部分代碼嗎? – gowrath

+3

當你*調用*你沒有提供的函數:* 2需要位置參數*。您還需要發佈Python向您顯示的錯誤消息,因爲您在提供的代碼片斷中沒有對「capture_and_decode」進行調用。 –

回答

1

它看起來像你的代碼看起來是這樣的:

obj.capture_and_decode() 

的第一個參數(self)爲您提供的,但你需要考慮另外兩個

如果它們是可選的,變化你的函數定義,包括默認值,例如:

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

capture_and_decode()方法的目的是取兩個位置參數;即一個比特和軸。無論你在哪裏調用此方法,都需要提供這些參數:

cam = CameraClass() 
cam.capture_and_decode(500, 4) # or whatever the values should be. 
相關問題