Opencv-python kivy app running in Android - Camera does not open, issued error: (-215: Assertion failed)! _src.empty () in function 'cvtColor'

902 views
Skip to first unread message

Pasteur Miranda

unread,
Apr 11, 2020, 6:03:24 PM4/11/20
to Kivy users support
Hello,

 I have an application developed in Python-Kivy for Android, using buildozer. This application uses Opencv to activate the smartphone's camera, 
and capture frames from the camera to analyze. The application is generated normally, but when it starts on the smartphone, 
it crashes. This occurs in the following opencv statement: 
             
            gray = cv2.cvtColor (frame, cv2.COLOR_BGR2GRAY)

where the following error is issued in logcat:

             cv2.error: OpenCV (4.0.1) ... error: (-215: Assertion failed)! _src.empty () in function 'cvtColor'

I think the problem is in the frame captured by the camera, and the lines of code that start the camera and 
capture the frame are as follows:

            video_capture = cv2.VideoCapture (0)
        while (True):
               ret, frame = video_capture.read ()
               gray = cv2.cvtColor (frame, cv2.COLOR_BGR2GRAY) <== Error issued here

The code was generated by buildozer using Python 3.7. Opencv 4.0.1 for arm64-V8a, Android 9.

Does anyone have any solution for this error? Is There some special initialization in the statement
video_capture = cv2.VideoCapture (0) so that it can starts the camera correctly when in Android environment?

Thank you very much

Robert Flatt

unread,
Apr 11, 2020, 11:35:45 PM4/11/20
to Kivy users support
Is permission set?

android.permissions = CAMERA

Also there is an example which might help  https://github.com/liyuanrui/kivy-for-android-opencv-demo

Alex Guryanow

unread,
Mar 8, 2023, 8:45:24 AM3/8/23
to Kivy users support
It seems that OpenCV before 4.5.2 does not support camera on Android. For more info look at https://stackoverflow.com/a/69445715
Reply all
Reply to author
Forward
0 new messages