Pygame显示镜像字母

2024-04-29 04:26:28 发布

您现在位置:Python中文网/ 问答频道 /正文

你能帮我理解为什么pygame把我的图像显示为镜像吗?更多信息请参见所附图片:

enter image description here

我将从PiCamera捕获一个图像到PiRGBArray流中,然后创建一个pygame surface模块并显示该图像。在

代码如下:

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)

Tags: 图像image信息镜像displaysurfaceframepygame
2条回答

我没有这方面的经验,但据我从文档中了解,有一些方法可以控制您的相机是否翻转视频,以下是来自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)

希望这是你的案子。在

我在代码中注意到的另一个奇怪的地方是,在定义相机时使用分辨率(640480),但在定义显示yo use(480640)时,这是故意的还是只是错误的?在

还有类似的question/answer可能会对你有更多帮助。它有指向同一主题的niceblog的链接。在

您正在从相机捕获图像,而相机不是镜子:-)

如果是正面照的话,你会认为这是对的。如果你翻转它使它面向你,图像就会翻转。在

这与pygame无关,只是摄像头(网络摄像头)的工作原理。在

相关问题 更多 >