2014-12-23 1 views
0

결과 이미지를 반전시키기 위해 진정한 접근법을 찾을 수 없습니다. pygame.transform.threshold 메서드 내에서 inverse = True 인수를 사용하려고 시도했지만 오류가 발생합니다. 다시 말하면, 나는 역치를 취할 필요가있다.파이 게임을 사용하여 임계 값 이미지를 반전하려면 어떻게해야합니까?

def threshold_image(self, image): 

    """Applies a threshold to an image and returns the thresholded image 

    arguments 
    image   -- the image that should be thresholded, a 
         pygame.surface.Surface instance 

    returns 
    thresholded  -- the thresholded image, a 
         pygame.surface.Surface instance 
    """ 

    # surface to apply threshold to surface 
    thimg = pygame.surface.Surface(self.get_size(), 0, image) 

    # perform thresholding 
    th = (self.settings['threshold'], self.settings['threshold'], 
      self.settings['threshold']) 
    pygame.transform.threshold(thimg, image, self.settings['pupilcol'], th, 
           self.settings['nonthresholdcol'], 1) 

    return thimg 
+0

어떤 오류가 발생합니까? – ryanpattison

+0

[documentation] (http://www.pygame.org/docs/ref/transform.html#pygame.transform.threshold)에서 적절한 인수를'pygame.transform '에 전달하는 것처럼 보이지 않습니다. 임계 값()'. 'threshold' 인자는'th'에있는 세 가지가 아닌 네 가지 값의 튜플로 보여줍니다. – martineau

+0

파이 게임 GUI가 열리지 않습니다. 이미지를 가져 오기 위해 웹캠을 사용하고 있습니다. –

답변

0

는 잘 모르겠어요하지만 추가 라인을 다음과 같이 뭔가 return thimg 사항이이 방법을 받고있어 그 결과 당신이 원하는 반전해야하기 전에 잘 될 :

- 테스트되지 않은 -

def threshold_image(self, image): 

    """Applies a threshold to an image and returns the thresholded image 

    arguments 
    image   -- the image that should be thresholded, a 
         pygame.surface.Surface instance 

    returns 
    thresholded  -- the thresholded image, a 
         pygame.surface.Surface instance 
    """ 

    # surface to apply threshold to surface 
    thimg = pygame.surface.Surface(self.get_size(), 0, image) 

    # perform thresholding 
    th = (self.settings['threshold'], self.settings['threshold'], 
      self.settings['threshold']) 
    pygame.transform.threshold(thimg, image, self.settings['pupilcol'], th, 
           self.settings['nonthresholdcol'], 1) 

    # Additional statements to invert results 
    inv = pygame.Surface(thimg.get_rect().size) 
    inv.fill((255,255,255)) 
    inv.blit(thimg, (0,0), None, pygame.BLEND_RGB_SUB) 

    return thimg 
관련 문제