Ask Your Question
0

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

asked 2020-04-11 17:19:21 -0600

Pasteur Jr gravatar image

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

edit retag flag offensive close merge delete

Comments

Your webcam isn't plugged it. Do you have VLC to test webcam working or not? I'm not familiar with Python-Kivy.

supra56 gravatar imagesupra56 ( 2020-04-11 21:35:09 -0600 )edit

You don't need to _think_ where the problem is. You should check in your code that reading the frame succeeds. Letting an app crash uncontrollably when problems arise is not good programming.

As to where the problem is, you should check the app's permissions.

mvuori gravatar imagemvuori ( 2020-04-12 01:44:12 -0600 )edit

@Pasteur Jr. Try this instead of zero. video_capture = cv2.VideoCapture (1)

supra56 gravatar imagesupra56 ( 2020-04-12 04:21:50 -0600 )edit

You cannot used code for Kivy camera. It is similar to Raspberry picamera. Here is link: Kivy camera

supra56 gravatar imagesupra56 ( 2020-04-12 04:28:18 -0600 )edit

In python-Kivy. You cannot use this gray = cv2.cvtColor (frame, cv2.COLOR_BGR2GRAY) Just comment out.

supra56 gravatar imagesupra56 ( 2020-04-12 04:44:18 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-04-19 15:36:13 -0600

I tried this too, the issue is cv2.VideoCapture(1).isOpened() == False , always

I used cv2.VideoCapture(1), and tried -1, 0 , and 2 on Android these last three all gave me:

[WARNING] [Base        ] Unknown <android> provider

So it seems like 1 is the right device, in my case

Android tells me my app has Camera permission, so that is not the issue.

I also built OpenCV 4.2.0, the results were the same.

This used to work last year, so I speculate that Python for Android's (a Kivy sub project) shift to Android NDK 19 requires using the OpenCV Manager to initialize OpenCV.

Can anybody help me to find the documentation for the Python API for OpenCV Manager? (help(cv2) overwhelmed me, and I looked in site-packages on Android but opencv is a .so)

Instructions on how to use the Python API for OpenCV Manager would be even better. :)

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-04-11 17:19:21 -0600

Seen: 5,231 times

Last updated: Apr 11 '20