本文介紹了在 Kivy 中顯示 numpy/opencv/matplotlib 圖像的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
如何在 Kivy 中以標(biāo)準(zhǔn) numpy/opencv/matplotlib 格式顯示圖像?Kivy 使用不同的圖像內(nèi)存布局,我不知道是哪一個(gè).
How to display image in standard numpy/opencv/matplotlib format in Kivy? Kivy uses different image memory layout and I can't figure out which one.
以下代碼完全正常.使用 cv2 VideoCapture 捕獲圖像.我認(rèn)為圖像是 BGR,數(shù)組維度是 (360, 480, 3):
The following code works totally fine. Image was captured using cv2 VideoCapture. I think image is BGR, array dimensions are (360, 480, 3):
ret, image = video_capture.read()
cv2.imshow('image', image)
cv2.waitKey()
嘗試使用以下代碼顯示它會(huì)產(chǎn)生混亂的結(jié)果:
Trying to display it with the following code produce messy results:
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)
推薦答案
找到了正確的轉(zhuǎn)換.可能不是最理想的:
Found the right transformation. Probably suboptimal:
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')
這篇關(guān)于在 Kivy 中顯示 numpy/opencv/matplotlib 圖像的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!