2013-10-10 191 views
4
def cvimage_to_pygame(image): 
    """Convert cvimage into a pygame image""" 
    return pygame.image.frombuffer(image.tostring(), image.shape[:2], 
            "RGB") 

該函數從cv2攝像頭獲取一個numpy數組。當我在pyGame窗口上顯示返回的pyGame圖像時,它會出現在三張破碎的圖像中。我不知道這是爲什麼!OpenCV cv2圖像到PyGame圖像?

任何幫助將不勝感激。

下面有發生什麼::

(Pygame的左側)

enter image description here

+0

你能提供給我們一個屏幕截圖? – Igonato

+0

可能的重複:http://stackoverflow.com/questions/19240422/display-cv2-videocapture-image-inside-pygame-surface – Igonato

+0

Added Screenshot! –

回答

4

shape字段的寬度和高度參數進行交換。更換的說法:

image.shape[:2] # gives you (height, width) tuple 

隨着

image.shape[1::-1] # gives you (width, height) tuple