kivy texture圖片格式和opencv numpy圖片格式互轉

 # 將Texture格式的圖片對象轉換爲numpy
    def texture_to_numpy(self,data):
        image=numpy.asarray(bytearray(data.pixels), dtype='uint8').reshape((data.height,data.width,4))
        r_chanel=numpy.copy(image[:,:,0])
        g_chanel=numpy.copy(image[:,:,1])
        b_chanel=numpy.copy(image[:,:,2])
        image[:, :, 0]=b_chanel
        image[:, :, 1]=g_chanel
        image[:, :, 2]=r_chanel
# 將numpy格式圖片對象轉爲Texture 
    def numpy_to_texture(self,frame):
        # frame=cv2.imread("ddd.jpg")
        buf1 = cv2.flip(frame, 0)
        buf = buf1.tostring()
        image_texture = Texture.create(size=(frame.shape[1], frame.shape[0]), colorfmt='bgr')
        image_texture.blit_buffer(buf, colorfmt='bgr', bufferfmt='ubyte')
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章