将 PyQt5 QPixmap 转换为 numpy ndarray

2024-05-07

我有像素图:

pixmap = self._screen.grabWindow(0,
                                 self._x, self._y,
                                 self._width, self._height)

我想将其转换为 OpenCV 格式。 我尝试将其转换为numpy.ndarray如上所述here https://stackoverflow.com/questions/37552924/convert-qpixmap-to-numpy但我得到了错误sip.voidptr object has an unknown size

有没有办法获得 numpy 数组(格式与cv2.VideoCapture read方法返回)?


我使用以下代码得到了 numpy 数组:

channels_count = 4
pixmap = self._screen.grabWindow(0, self._x, self._y, self._width, self._height)
image = pixmap.toImage()
s = image.bits().asstring(self._width * self._height * channels_count)
arr = np.fromstring(s, dtype=np.uint8).reshape((self._height, self._width, channels_count)) 
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将 PyQt5 QPixmap 转换为 numpy ndarray 的相关文章

随机推荐