haykp
haykp

Reputation: 445

Pygame shows image letters mirrored

Can you please help me understand why pygame shows my image as mirrored? Please see the attached image for more info:

enter image description here

I am capturing an image from PiCamera into PiRGBArray stream, then creating a pygame surface module and displaying the image.

This is the code:

camera = PiCamera()
camera.resolution = (640, 480)
rawCapture = PiRGBArray(camera, size=(640, 480))

pygame.init()
lcdDisplay = pygame.display.set_mode((480,640))

for frame in camera.capture_continuous(rawCapture, format="rgb", 
    image = frame.array

    surf=pygame.surfarray.make_surface(image)
    lcdDisplay.blit(surf, (0,0))    

    pygame.display.update()
    pygame.display.flip()

    # clear the stream 
    rawCapture.truncate(0)

Upvotes: 3

Views: 527

Answers (2)

Gagik Sukiasyan
Gagik Sukiasyan

Reputation: 856

I don't have experience on this but as far as I understand from documentation there are ways to control your camera to flip the video or not, here is comments from tutorial :

Using Camera Controls

Most cameras support controls like flipping the image and changing brightness. set_controls() and get_controls() can be used at any point after using start().

cam.set_controls(hflip = True, vflip = False)

Hope this is your case.

The other strange thing I noticed in your code is when you define camera you use resolution (640, 480), but when defining the display yo use (480, 640), is this intentional or just and error ?

Also there is similar question/answer which might help you more. It has link to nice blog on same topic.

Upvotes: 1

ChatterOne
ChatterOne

Reputation: 3541

You're capturing the image from a camera, and a camera is not a mirror :-)

Think of it this way: if the camera is facing front, and you take a picture, it'll look "correct". If you flip it to face it towards you, the image is flipped.

This is not related to pygame, it's just how cameras (webcams) work.

Upvotes: 1

Related Questions