2024-09-27 09:37:51 发布
网友
我有pixmap:
pixmap = self._screen.grabWindow(0, self._x, self._y, self._width, self._height)
我想把它转换成OpenCV格式。 我试图将其转换为numpy.ndarray,如here所述,但我得到了错误sip.voidptr object has an unknown size
numpy.ndarray
sip.voidptr object has an unknown size
有没有办法获得numpy数组(与cv2.VideoCaptureread方法返回的格式相同)?在
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))
可以通过执行以下操作来避免复制:
channels_count = 4 pixmap = self._screen.grabWindow(0, self._x, self._y, self._width, self._height) image = pixmap.toImage() b = image.bits() # sip.voidptr must know size to support python buffer interface b.setsize(self._height * self._width * channels_count) arr = np.frombuffer(b, np.uint8).reshape((self._height, self._width, channels_count))
我用这个代码得到了numpy数组:
可以通过执行以下操作来避免复制:
相关问题 更多 >
编程相关推荐