python-for-android and opencv

2,293 views
Skip to first unread message

Milos Bulatovic

unread,
Oct 29, 2015, 8:43:02 AM10/29/15
to Kivy users support
Hi,

I am trying to package an application for the android platform and there's the cv2 module in my app. Packaging (with Buildozer) goes successfully, however when I start the app on the phone logcat reports an error "ImportError: No module named cv2" and app shuts down. 
I installed opencv on linux ubuntu and I made a virtualenv with system-site-packages. From the virtual python 2.7 shell I can import cv2. 
What confuses me is that the apk is packaged successfully, yet on the phone it reports cv2 could not be imported. Does this mean that the opencv p4a recipe is including a cv2 installation different from the one my app uses on the desktop?

Alexander Taylor

unread,
Oct 29, 2015, 10:22:53 AM10/29/15
to Kivy users support
Having opencv on your desktop doesn't matter, it has to be built for android and included in the apk's python installation.

It should work if you include 'opencv' in the buildozer requirements line, did you do that?

Milos Bulatovic

unread,
Oct 29, 2015, 12:17:21 PM10/29/15
to Kivy users support
I made the mistake of writing 'cv2' in the requirements, instead of 'opencv'. Now it works. Thanks.

Milos Bulatovic

unread,
Nov 1, 2015, 6:45:06 AM11/1/15
to Kivy users support
I am trying some code I found on the forum http://pastebin.com/a1kDp1aD for using opencv with Kivy camera provider and it works nicely on desktop (linux). I want to do the same on android, where I have successfully packaged the application, including modules opencv and numpy. Starting the application produces error like this http://pastebin.com/Hip0XxR9

These lines
E/OpenCV::camera( 5207): ||libnative_camera_r4.4.0.so
E
/OpenCV::camera( 5207): ||libnative_camera_r2.3.3.so
E
/OpenCV::camera( 5207): ||libnative_camera_r4.2.0.so
E
/OpenCV::camera( 5207): ||libnative_camera_r4.1.1.so
E
/OpenCV::camera( 5207): ||libnative_camera_r2.2.0.so
E
/OpenCV::camera( 5207): ||libnative_camera_r3.0.1.so
E
/OpenCV::camera( 5207): ||libnative_camera_r4.0.0.so
E
/OpenCV::camera( 5207): ||libnative_camera_r4.3.0.so
E
/OpenCV::camera( 5207): ||libnative_camera_r4.0.3.so
D
/OpenCV::camera( 5207): try to load library 'libnative_camera_r4.4.0.so'

look to me like it's trying camera code for different android versions and my version 4.4.2 ain't listed there. It also seems that for the camera provider opencv is used. I am wondering if I can make it use the android provider directly and make it all work like that? Or a different solution? 

Milos Bulatovic

unread,
Nov 9, 2015, 4:00:48 AM11/9/15
to Kivy users support
The problem here is that I wasn't using the master version of Kivy, where there is a camera_android provider added. With the master version the camera now runs successfully.

André Costa

unread,
Mar 11, 2016, 10:54:44 AM3/11/16
to Kivy users support
Is it possible to have the latest opencv working with kivy? Like building it as it says here: http://code.opencv.org/projects/opencv/wiki/Building_OpenCV4Android_from_trunk


Alexander Taylor

unread,
Mar 11, 2016, 3:25:03 PM3/11/16
to kivy-...@googlegroups.com
Sure, you can modify the opencv recipe to build the latest version. If
it's just a different download url, you only need to change that line.
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Kivy users support" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/kivy-users/I47UKutCViU/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> kivy-users+...@googlegroups.com
> <mailto:kivy-users+...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.


signature.asc
Reply all
Reply to author
Forward
0 new messages