Dik*_*rAz 7 python opencv kivy
如何在Kivy中以标准numpy/opencv/matplotlib格式显示图像?Kivy使用不同的图像内存布局,我无法弄清楚哪一个.
以下代码完全正常.使用cv2 VideoCapture捕获图像.我认为图像是BGR,数组尺寸是(360,480,3):
ret, image = video_capture.read()
cv2.imshow('image', image)
cv2.waitKey()
Run Code Online (Sandbox Code Playgroud)
尝试使用以下代码显示它会产生混乱的结果:
video_texture = Texture.create(size=image.shape[:2])
video_texture.blit_buffer(image.tostring(), colorfmt='rgb', bufferfmt='ubyte')
# ...
video_panel = self.ids['video_panel']
with video_panel.canvas:
Rectangle(texture=video_texture, pos=video_panel.pos, size=video_panel.size)
Run Code Online (Sandbox Code Playgroud)
找到了正确的转变。可能不是最理想的:
ret, image = video_capture.read()
image = np.rot90(np.swapaxes(image, 0, 1))
video_texture = Texture.create(size=(image.shape[1], image.shape[0]), colorfmt='rgb')
video_texture.blit_buffer(image.tostring(), colorfmt='bgr', bufferfmt='ubyte')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1650 次 |
| 最近记录: |