Opencv-python kivy app running in Android - Camera does not open, issued error: (-215: Assertion failed)! _src.empty () in function 'cvtColor'
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
Your webcam isn't plugged it. Do you have VLC to test webcam working or not? I'm not familiar with Python-Kivy.
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.
@Pasteur Jr. Try this instead of zero.
video_capture = cv2.VideoCapture (1)
You cannot used code for Kivy camera. It is similar to Raspberry picamera. Here is link: Kivy camera
In python-Kivy. You cannot use this
gray = cv2.cvtColor (frame, cv2.COLOR_BGR2GRAY)
Just comment out.