11

I have been working for a few days, trying to use cv2.VideoCapture() in python-for-android. I'm using Kivy with buildozer to build apk for Android. Here is my code

    from kivy.app import App
    from kivy.uix.image import Image
    from kivy.clock import Clock
    from kivy.graphics.texture import Texture
    import cv2


    class KivyCamera(Image):
        def __init__(self, capture, fps, **kwargs):
            super(KivyCamera, self).__init__(**kwargs)
            self.capture = capture
            Clock.schedule_interval(self.update, 1.0 / fps)

        def update(self, dt):
            print 'hello'
            ret, frame = self.capture.read()
            print frame
        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.capture = cv2.VideoCapture(1)
            self.my_camera = KivyCamera(capture=self.capture, fps=30)
            return self.my_camera

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


    if __name__ == '__main__':
        CamApp().run()

This code is totally running on pc and successfully displaying the video feed, but if I build this to apk file using buildozer it will get crashed as soon as application launched. Can someone help me to fix this issue?? Anyway If anyone have done this please comment..

This is the logcat from Android device:

    08-14 10:05:16.807 16826-16826/? A/DEBUG: backtrace:
    08-14 10:05:16.807 16826-16826/? A/DEBUG:     #00 pc 00018b00    /system/lib/libc.so (strlen+71)
    08-14 10:05:16.807 16826-16826/? A/DEBUG:     #01 pc 00505fc9  /data/data/org.test.myapp/files/app/lib/python2.7/site-packages/cv2.so
    08-14 10:05:16.807 16826-16826/? A/DEBUG:     #02 pc 005069fb  /data/data/org.test.myapp/files/app/lib/python2.7/site-packages/cv2.so
    08-14 10:05:16.807 16826-16826/? A/DEBUG:     #03 pc 00506e0d  /data/data/org.test.myapp/files/app/lib/python2.7/site-packages/cv2.so
    08-14 10:05:16.807 16826-16826/? A/DEBUG:     #04 pc 0037a4fb  /data/data/org.test.myapp/files/app/lib/python2.7/site-packages/cv2.so
    08-14 10:05:16.807 16826-16826/? A/DEBUG:     #05 pc 0037aa71  /data/data/org.test.myapp/files/app/lib/python2.7/site-packages/cv2.so
    08-14 10:05:16.807 16826-16826/? A/DEBUG:     #06 pc 0037261d  /data/data/org.test.myapp/files/app/lib/python2.7/site-packages/cv2.so
    08-14 10:05:16.807 16826-16826/? A/DEBUG:     #07 pc 0037291b  /data/data/org.test.myapp/files/app/lib/python2.7/site-packages/cv2.so
    08-14 10:05:16.807 16826-16826/? A/DEBUG:     #08 pc 003729ff  /data/data/org.test.myapp/files/app/lib/python2.7/site-packages/cv2.so
    08-14 10:05:16.807 16826-16826/? A/DEBUG:     #09 pc 0015cf2b  /data/data/org.test.myapp/files/app/lib/python2.7/site-packages/cv2.so
    08-14 10:05:16.807 16826-16826/? A/DEBUG:     #10 pc 000603c5  /data/app/org.test.myapp-1/lib/arm/libpython2.7.so (PyCFunction_Call+144)
Vajira Prabuddhaka
  • 852
  • 4
  • 13
  • 34

0 Answers0