OpenCV, PY to APK using Kivy, Buildozer having issues

1,384 views
Skip to first unread message

Sabari Vishnu Jayanthan Jaikrishnan

unread,
Sep 29, 2022, 3:37:49 AM9/29/22
to Kivy users support
I have a python file which uses Open CV and Aruco markers. The app works perfectly in the computer. However, it is not open on the android mobile.
  • In my buildozer requirements, I have the following

    # (list) Application requirements
    # comma separated e.g. requirements = sqlite3,kivy
    requirements = python3,kivy,numpy,opencv-python

it gives me the following error

ImportError: OpenCV loader: missing configuration file: ['config.py']. Check OpenCV installation.

  • If I use the following as requirements

    # (list) Application requirements
    # comma separated e.g. requirements = sqlite3,kivy
    requirements = python3,kivy,numpy,opencv

I am getting the following error:

ModuleNotFoundError: No module named 'cv2'

I am stuck here. Could anyone help me out? Thanks in advance.

Robert

unread,
Sep 29, 2022, 5:43:38 PM9/29/22
to Kivy users support

Sabari Vishnu Jayanthan Jaikrishnan

unread,
Sep 30, 2022, 4:22:10 AM9/30/22
to Kivy users support
Thanks Robert, 

I checked and I kept everything to default. Didn't change anything in the bulldozer spec file except the requirements. 

requirements = python3,kivy,numpy,opencv

I am getting the following error in adb logcat:

09-30 14:31:54.198  8460  8534 I python  : Android kivy bootstrap done. __name__ is __main__
09-30 14:31:54.198  8460  8534 I python  : AND: Ran string
09-30 14:31:54.198  8460  8534 I python  : Run user program, change dir and execute entrypoint
09-30 14:31:54.301  8460  8534 I python  : [INFO   ] [Logger      ] Record log in /data/user/0/org.test.myapp/files/app/.kivy/logs/kivy_22-09-30_5.txt
09-30 14:31:54.301  8460  8534 I python  : [INFO   ] [Kivy        ] v2.1.0
09-30 14:31:54.301  8460  8534 I python  : [INFO   ] [Kivy        ] Installed at "/data/user/0/org.test.myapp/files/app/_python_bundle/site-packages/kivy/__init__.pyc"
09-30 14:31:54.301  8460  8534 I python  : [INFO   ] [Python      ] v3.9.9 (main, Sep 30 2022, 06:10:51)
09-30 14:31:54.301  8460  8534 I python  : [Clang 12.0.8 (https://android.googlesource.com/toolchain/llvm-project c935d99d
09-30 14:31:54.301  8460  8534 I python  : [INFO   ] [Python      ] Interpreter at ""
09-30 14:31:54.301  8460  8534 I python  : [INFO   ] [Logger      ] Purge log fired. Processing...
09-30 14:31:54.302  8460  8534 I python  : [INFO   ] [Logger      ] Purge finished!
09-30 14:31:54.817  8460  8534 I python  : [INFO   ] [Factory     ] 189 symbols loaded
09-30 14:31:54.977  8460  8534 I python  : [INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2 (img_pil, img_ffpyplayer ignored)
09-30 14:31:55.186  8460  8534 I python  :  Traceback (most recent call last):
09-30 14:31:55.186  8460  8534 I python  :    File "/content/.buildozer/android/app/main.py", line 15, in <module>
09-30 14:31:55.186  8460  8534 I python  :  ImportError: cannot import name 'aruco' from 'cv2' (/data/user/0/org.test.myapp/files/app/_python_bundle/site-packages/cv2.so)
09-30 14:31:55.186  8460  8534 I python  : Python for android ended.


I added "opencv-contrib-python" in the requirements. 
requirements = python3,kivy,numpy,opencv,opencv-contrib-python

it gives me the following error

ImportError: OpenCV loader: missing configuration file: ['config.py']. Check OpenCV installation.


Robert

unread,
Sep 30, 2022, 1:12:09 PM9/30/22
to Kivy users support

Bill Marriott

unread,
Oct 20, 2022, 1:01:58 PM10/20/22
to Kivy users support
I am having the same problem - were you able to resolve and if so how?

Sabari Vishnu Jayanthan Jaikrishnan

unread,
Oct 23, 2022, 11:50:14 PM10/23/22
to Kivy users support
No. I tried a lot of ways I couldn't find a way to include open CV into an android application using Kivy. It always shows the above mentioned error 

Robert

unread,
Oct 24, 2022, 2:23:58 AM10/24/22
to Kivy users support

Gogi Chip

unread,
Apr 14, 2023, 4:13:58 AM4/14/23
to Kivy users support
Hi guys!! Maybe someone fixed this problem?? I have the same mistake. And I can't decide...

понедельник, 24 октября 2022 г. в 13:23:58 UTC+7, Robert:

Gogi Chip

unread,
Apr 14, 2023, 4:21:49 AM4/14/23
to Kivy users support
# (str) The directory in which python-for-android should look for your own build recipes (if any)
p4a.local_recipes = p4a-recipes/opencv_extras

I added this recipe to the Bulldozer spec. But unfortunately it didn't help...
пятница, 14 апреля 2023 г. в 15:13:58 UTC+7, Gogi Chip:

Robert

unread,
Apr 14, 2023, 12:55:08 PM4/14/23
to Kivy users support

Leis Al Ayoubi

unread,
Apr 23, 2023, 3:45:10 AM4/23/23
to Kivy users support
I got it to work after a looong time tuning my buildozer.spec file.
Figured out since python-for-android repo gets cloned automatically you dont actually need to add local p4a recipes for opencv or opencv-extras.
The official p4a-repo has opencv and opencv_extras (opencv-contrib) recipes included.

Just add to requirements in buildozer.spec:
requirements = opencv, opencv_extras

Gogi Chip

unread,
Apr 24, 2023, 1:14:05 AM4/24/23
to Kivy users support
from kivy.clock import mainthread
from kivy.graphics import Color, Rectangle
from kivy.graphics.texture import Texture
import numpy as np
import cv2
from camera4kivy import Preview

aruco_dict = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_ARUCO_ORIGINAL)
parameters = cv2.aruco.DetectorParameters()

I added opencv_extras to the spec. 
requirements = python3,kivy,camera4kivy,gestures4kivy,opencv,opencv_extras,numpy

Error when trying to debug in Android Studio:

I/python:  Traceback (most recent call last):
I/python:    File "/home/greka/PycharmProjects/C4K_no_sound_MAIN/.buildozer/android/app/main.py", line 6, in <module>
I/python:    File "/home/greka/PycharmProjects/C4K_no_sound_MAIN/.buildozer/android/app/applayout.py", line 7, in <module>
I/python:    File "/home/greka/PycharmProjects/C4K_no_sound_MAIN/.buildozer/android/app/edgedetect.py", line 16, in <module>
I/python:  AttributeError: module 'cv2.aruco' has no attribute 'DetectorParameters'
I/python: Python for android ended.

воскресенье, 23 апреля 2023 г. в 14:45:10 UTC+7, leis...@gmail.com:
Message has been deleted

Robert

unread,
Apr 24, 2023, 4:12:34 PM4/24/23
to Kivy users support
> I/python:  AttributeError: module 'cv2.aruco' has no attribute 'DetectorParameters'

I have no specific knowledge.

Assuming this works on the desktop, I'd check the ocv version requirements for DetectorParameters.

Aakash Aarya

unread,
Apr 25, 2023, 12:21:16 PM4/25/23
to kivy-...@googlegroups.com
you have to android studio for building ooencv library 

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/bbaab0e2-2924-44ae-bbb6-6bf1a50f6f35n%40googlegroups.com.

Robert

unread,
Apr 25, 2023, 2:06:11 PM4/25/23
to Kivy users support
This answer is incorrect.
Reply all
Reply to author
Forward
0 new messages