在Android上使用带有kivy和python-for-android的OpenCV库播放视频

Kal*_*llz 5 python android python-2.7 kivy buildozer

尝试使用OpenCV库与kivy和python-for-android 播放视频

这是我的尝试:

import os

import cv2
from kivy.app import App
from kivy.clock import Clock
from kivy.graphics.texture import Texture
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.image import Image


class KivyCamera(Image):
    def __init__(self, capture=None, fps=0, **kwargs):
        super(KivyCamera, self).__init__(**kwargs)
        # self.capture = cv2.VideoCapture("/sdcard2/python-apk/2.mp4")
        print "file path exist :" + str(os.path.exists("/sdcard2/python-apk/1.mkv"))
        self.capture = cv2.VideoCapture("/sdcard2/python-apk/1.mkv")
        Clock.schedule_interval(self.update, 1.0 / fps)

    def update(self, dt):
        ret, frame = self.capture.read()
        print str(os.listdir('/sdcard2/'))
        if ret:
            # convert it to texture
            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')
            # display image from the texture
            self.texture = image_texture


class CamApp(App):
    def build(self):
        self.my_camera = KivyCamera(fps=30)
        self.box = BoxLayout(orientation='vertical')
        btn1 = Button(text="Hello")
        self.box.add_widget(btn1)
        # l = Label(text=cv2.__version__, font_size=150)
        # self.box.add_widget(l)
        self.box.add_widget(self.my_camera)
        return self.box

    def on_stop(self):
        # without this, app will not exit even if the window is closed
        # self.capture.release()
        pass

    def on_pause(self):
        return True


if __name__ == '__main__':
    CamApp().run()
Run Code Online (Sandbox Code Playgroud)

并在bulldozer.spec文件中

# (list) Source files to include (let empty to include all the files)
source.include_exts = py,png,jpg,kv,atlas,zip,mp4



# (list) Application requirements
requirements = plyer,kivy,opencv,numpy,pyjnius,ffmpeg, sqlite3, openssl
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用OpenCV cv2.VideoCapture()方法播放视频,上面的程序在桌面上正常工作,但是当我使用bulldozerAndroid 构建APK 并在Android手机上运行应用程序时,我只得到白屏.我尝试播放.mp4.mkv格式化,但在这两种情况下,我都会看到白屏.我做错了什么或我的错误在哪里?

在此输入图像描述

这是我的日志文件:

日志文件

类似问题:

这个问题也没有任何答案.