gpt4 book ai didi

python - OpenCV cv2 图像到 PyGame 图像?

转载 作者:太空狗 更新时间:2023-10-30 01:08:50 27 4
gpt4 key购买 nike

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 图像时,它出现在三个损坏的图像中。我不知道这是为什么!

如有任何帮助,我们将不胜感激。

这是发生了什么::

(左边是Pygame)

enter image description here

最佳答案

shape 字段中,宽度和高度参数被交换。替换参数:

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

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

关于python - OpenCV cv2 图像到 PyGame 图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19306211/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com