Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Camera on android #75

Closed
alexsilva opened this issue Dec 16, 2012 · 30 comments · Fixed by #327
Closed

Camera on android #75

alexsilva opened this issue Dec 16, 2012 · 30 comments · Fixed by #327

Comments

@alexsilva
Copy link

Log error: http://pastebin.com/LwgjpMqQ

. / distribute.sh-m "pil Kivy pygame opencv"

error: Recipe opencv does not exit

opencv is not included in the "recipes dir".

How to fix it?
Thank you.

@tito
Copy link
Member

tito commented Dec 16, 2012

There is no camera implementation in Kivy right now. And we never said than opencv was available on python-for-android too.

The list of available recipes can be retrieved with ./distribute.sh -l
Or browisng https://github.com/kivy/python-for-android/tree/master/recipes

The fix is... to do it.

@alexsilva
Copy link
Author

So if I only include "opencv" the process of compiling the camera will work?
Keep in mind that I started using "Kivy" very recently.

@alexsilva
Copy link
Author

I disagree with this statement:

I agree with the statement:

  • "And we never said than opencv was available on python-for-android too"

Ok, no problem.

  • "The fix is... to do it."

@tito
Copy link
Member

tito commented Dec 16, 2012

There is no camera implementation in Kivy "for android platform". :) You are on the python/android project, so the context was implies.

The issue is not only to get opencv compiled for ARM/android, but also implement a provider for android. It seem that OpenCV have now a camera support for android, but it need a closer look to see how it need to be integrated into our java code, and if it's still possible to use their Python API. Or another way.

@barius
Copy link

barius commented Mar 4, 2014

WRT OpenCV for Android, I managed to compile it for Python and successfully imported it in Python. However camera functionality in OpenCV is somehow broken in Kitkat 4.4.2.

@venthur
Copy link

venthur commented May 22, 2014

Do you mean you compiled the OpenCV Python library for arm/android using python-for-android? If yes, would you mind sharing the recipe?

@barius
Copy link

barius commented May 23, 2014

Hi Bastian Venthur,

I did compiled the OpenCV Python library for Android(ARM). However, I
didn't write any recipe files to achieve this. It was done by creating a
new Android project in ADT, and feeding everything the cross compiler
needed into the project.
More specifically, the OpenCV building environment uses some automatic
wrapper for Python library generation. During compile time, some header
files are generated by the wrapper to provide C++-Python interoperability
and functionality. However the OpenCV CMake environment disables Python
library generation for Android, so these header files are not created.
One can simply put the generated headers from a Linux OpenCV for Python
build into the Android project, and put the pre-compiled opencv_java.so
library for Android into the same project and compile. Then you can get a
fully-functional cv2.so for Android (or partially-functional for it doesn't
support HighGUI).
I can send you a copy of the Eclipse project I used to build the library,
if you need.

Regards,

Peng

2014-05-23 6:21 GMT+08:00 Bastian Venthur [email protected]:

Do you mean you compiled the OpenCV Python library for arm/android
using python-for-android? If yes, would you mind sharing the recipe?


Reply to this email directly or view it on GitHubhttps://github.com//issues/75#issuecomment-43951254
.

@AshokEmrys
Copy link

Hi barius,

I am trying to do the same, wrap opencv with python for android.
I am relatively new to android, it would be much helpful if you could share the procedure you followed and the required project files.

Regards,
Ashok

@barius
Copy link

barius commented Jul 24, 2014

@ParokshaX @venthur
Here I attach the Eclipse project I have made to build libcv2.so for Python on Android. It is a little bit messy because I really had a headache working it out, and I'm short on time right now.
Just import it into Eclipse (I use ADT 22.0 and NDK r9c) and it should compile. I took libopencv_java.so into the project so it shall be a dependency. Also libpython2.7.so is a dependency too.
If anyone can make this into a Python for Android recipe then that would be awesome.

The link:
https://drive.google.com/file/d/0B7iBG-Vnm4w1SjFhXzItSmQ5OG8/edit?usp=sharing

Regards,

Peng

@AshokEmrys
Copy link

@barius
Thanks, I managed to build it by using opencv's cmake, however I have problem with the numpy recipe!

@barius
Copy link

barius commented Jul 24, 2014

@ParokshaX
Glad to hear that you worked it out.
About numpy, AFAIK you cannot build P4A w/o Kivy, e.g.this works fine
./distribute.sh -d dist1 -m numpy pil kivy
but
./distribute.sh -d dist1 -m numpy pil
does not.
No idea what your case is, just trying to help.

@AshokEmrys
Copy link

@barius
I used ./distribute.sh -m openssl pil kivy numpy but it failed with numpy as it is trying to build lapack library which requires gfortran for arm which is not provided by android-ndk, the patch provided in the recipe doesn't seem to work, could be relative to the distro (arch linux) i am using. Have to dig into it further to find where it went wrong.

Is it possible that you could share the numpy-android which you built, so I can test run the opencv I built using cmake and verify its integrity?

@barius
Copy link

barius commented Jul 24, 2014

try put numpy in front of kivy first 😁
2014-7-25 上午12:20于 "Ashok Kumar P (ParokshaX)" [email protected]写道:

@barius https://github.com/barius
I used ./distribute.sh -m openssl pil kivy numpy but it failed with numpy
as it is trying to build lapack library which requires gfortran for arm
which is not provided by android-ndk, the patch provided in the recipe
doesn't seem to work, could be relative to the distro (arch linux) i am
using. Have to dig into it further to find where it went wrong.

Is it possible that you could share the numpy-android which you built, so
I can test run the opencv I built using cmake and verify its integrity?


Reply to this email directly or view it on GitHub
#75 (comment)
.

@AshokEmrys
Copy link

@barius
tried, still the same error

@barius
Copy link

barius commented Jul 25, 2014

@ParokshaX
sorry for the delay, here is the numpy library I compiled. have fun
https://drive.google.com/file/d/0B7iBG-Vnm4w1WmxVQS1JREwtRzQ/edit?usp=sharing

@AshokEmrys
Copy link

@barius
Thanks.
anyway, I found the problem and fixed it, built numpy. :-D
but runtime error as opencv requires numpy API 9 (V 1.8.1) but the numpy python-for-android built is API 7 (V 1.7.1). u seem to have used numpy 1.7.1 did opencv work?

currently I am creating a patch for numpy-1.8.1 to build for android.

@barius
Copy link

barius commented Jul 25, 2014

@ParokshaX
It worked like a charm :P
As long as major interfaces are the same between numpy 1.7.1 and 1.8.1 the interop between OpenCV and numpy could be stable, I guess :P

@AshokEmrys
Copy link

@barius weird!,
Runtime Error: Module is built for API 9 but the version of numpy is 7
while importing cv2,
I patched the numpy-1.8.1 and have built one, let me check and report

On 7/25/14, barius [email protected] wrote:

@ParokshaX
It worked like a charm :P
As long as major interfaces are the same between numpy 1.7.1 and 1.8.1 the
interop between OpenCV and numpy could be stable, I guess :P


Reply to this email directly or view it on GitHub:
#75 (comment)

@barius
Copy link

barius commented Jul 25, 2014

@ParokshaX
FYI I used OpenCV 2.4.7 with numpy 1.7.1, and they work fine. Really weird.

@AshokEmrys
Copy link

I patched the numpy1.8.1 for python-for-android, now I have a working
opencv in my android :-D

On 7/25/14, barius [email protected] wrote:

@ParokshaX
FYI I used OpenCV 2.4.7 with numpy 1.7.1, and they work fine. Really weird.


Reply to this email directly or view it on GitHub:
#75 (comment)

@barius
Copy link

barius commented Jul 25, 2014

@ParokshaX
congratz :D
hope we can get an official OpenCV from P4A :P

@AshokEmrys
Copy link

I have a plan of writing a recipe for it, not now, currently I am
quite overwhelmed by others ;-)

On 7/25/14, barius [email protected] wrote:

@ParokshaX
congratz :D
hope we can get an official OpenCV from P4A :P


Reply to this email directly or view it on GitHub:
#75 (comment)

@gorgonaut04
Copy link

Has there been any update on this? Would it be possible to get an official recipe for OpenCV in the near future? I would be extremely grateful! Coffees, all around!

@jxai jxai mentioned this issue Feb 11, 2015
@jxai
Copy link
Contributor

jxai commented Feb 11, 2015

I created a recipe for OpenCV and submitted it as PR #327. The recipe patches OpenCV v2.4.10.1, builds a fully working Python module cv2.so, as well as installs native camera libraries. The Java library (libopencv_java.so) is actually not needed.

I don't have the resource to test the camera functionality on many different devices. It works fine on one phone running Android 4.1, but failed on another phone running 4.4 (as @barius mentioned earlier).

@gorgonaut04
Copy link

Hi again, Jason. Do you have any tips for using the Android camera feature of OpenCV within kivy? This seems to be uncharted territory.

@tito tito closed this as completed in #327 Mar 4, 2015
@cbenhagen
Copy link
Contributor

@jasonxunxu thank you very much for the recipe! Do you mind giving a small example on how one would use the camera? If it should be as simple as

cap = cv2.VideoCapture(0)

it might just not work on my nexus 5. This is the whole code i used to test: https://gist.github.com/cbenhagen/457af62752fba44fff47

@cbenhagen
Copy link
Contributor

oh never mind.. i just found your kivy fork and its camera-android branch

@jxai
Copy link
Contributor

jxai commented Apr 5, 2015

@cbenhagen Thanks for digging out my branch, I just posted a PR for Kivy. Please let me know how it works for you.

@gorgonaut04 I hope it does the trick for you too.

@gorgonaut04
Copy link

@jasonxunxu it looks to me as if this code is good for streaming video data, but can it also be used to actually take full-resolution photo using the shutter? I apologize if I'm just completely missing this, but are there any usage examples for this code? Thanks!

@jxai
Copy link
Contributor

jxai commented Apr 7, 2015

It is a standard camera provider so works transparently with the Camera widget on Android. In addition it has a read_frame method to fetch current frame data (of same resolution as the preview image). It is not designed to take full resolution pictures, for which Plyer camera might be what you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants