Fixing import of 2.4 beta samples to eclipse

447 views
Skip to first unread message

Rui Marques

unread,
Apr 13, 2012, 5:33:44 AM4/13/12
to android...@googlegroups.com
I had troubles importing the android samples until I did the following:

- Create "res/values/strings.xml" file in the OpenCV-2.4 project with the following content (i had an error about missing app_name var):

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<resources>
    <string name="app_name">OpenCV</string>
</resources>

- Copy file "project.properties" from "OpenCV-2.4" folder  to each imported example root folder.

Dev platform:

Ubuntu 10.04
Eclipse 3.7.2
Android SDK tools rev. 18

Rui Marques

unread,
Apr 13, 2012, 5:43:57 AM4/13/12
to android...@googlegroups.com
And also changing this from true to false (at strings.xml):

android.library=false

And changing mFrameWidth and mFrameHeight within SampleCvViewBase.java to some value that my Motorola Atrix supports.
Somehow the default code was selecting an unsupported frame size.

Rui Marques

unread,
Apr 13, 2012, 5:59:54 AM4/13/12
to android...@googlegroups.com
Also, if you use samples that use Android Camera and your android target is 2.2 or 2.3.3 and maybe others bellow 3.2 (i know this is no longer an issue with 3.2) you will have a small issue.

Regarding this line at SampleViewBase.java:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
   mCamera.setPreviewTexture( new SurfaceTexture(10) );

Build.VERSION_CODES.HONEYCOMB and SurfaceTexture are not defined with "older" android targets you have to work arround it, maybe by deleting it.

Rui Marques

unread,
Apr 13, 2012, 6:19:54 AM4/13/12
to android...@googlegroups.com
Regarding this line at SampleViewBase.java from "Tutorial 1 - Add Opencv":

params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);


Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO is not defined for Android 2.2.

Andrey Pavlenko

unread,
Apr 13, 2012, 9:32:03 AM4/13/12
to android...@googlegroups.com
You're doing something wrong...
You should import OpenCV library project as an android library project, so the 
android.library=false
looks incorrect.
Also you shouldn't modify the samples target: they have 
<uses-sdk android:minSdkVersion="8" />
in the manifest, so even targeted to newer Android versions they will run in Android 2.2+.

Rui Marques

unread,
Apr 13, 2012, 9:41:24 AM4/13/12
to android...@googlegroups.com
android.library=false

I meant to put the above in the samples, not in the library project.


<uses-sdk android:minSdkVersion="8" />

I did have the above in my manifest, but I have a warning telling it should be placed before <application> tag (this is also true for other <uses-* > tags).

The manifest as described above, was imported this way, I didn't change it.

Roman

unread,
Apr 13, 2012, 10:12:50 AM4/13/12
to android...@googlegroups.com
I can confirm, that. Yesterday I decided to try new opencv and have to set app_name, recopy project.properties (beacuse there was a loop with warnings that is not set) and change islibrary option (I import whole OpenCV folder - samples + library) and Eclipse mark all samples as library.

Dne pátek, 13. dubna 2012 15:41:24 UTC+2 Rui Marques napsal(a):

Andrey Pavlenko

unread,
Apr 13, 2012, 10:59:28 AM4/13/12
to android...@googlegroups.com
Ok, we'll ckeck if we uploaded an incomplete package...

Andrey Pavlenko

unread,
Apr 16, 2012, 5:00:09 AM4/16/12
to android...@googlegroups.com
I've done the following steps to load the 2.4.beta package including samples to Eclipse:

1. download and unpacked tar-ball
2. create a new Eclipse work-space
3. import 'OpenCV-2.4' library project
  - it shows build errors and suggested 'fix project properties' 
  - investigations found incorrect AndroidManifest.xml
4. unload the project, open OpenCV-2.4/AndroidManifest.xml in a text editor, remove the "<application>...</application>" section
5. open the same work-space, now OpenCV-2.4.beta is loaded without errors
6. all the samples don't have necessary files (project.properties) to be imported to Eclipse, so
- open a console session in the 'samples' folder and run the commands:
(make sure your Android SDK has 'android-11' aka '3.0' platform installed)
<pre>
android update project --name "Sample - 15-puzzle" --target android-11 --path ./15-puzzle
android update project --name "Sample - face-detection" --target android-11 --path ./face-detection
android update project --name "Sample - image-manipulations" --target android-11 --path ./image-manipulations
android update project --name "Tutorial 0 (Basic) - Android Camera" --target android-11 --path ./tutorial-0-androidcamera
android update project --name "Tutorial 1 (Basic) - Add OpenCV" --target android-11 --path ./tutorial-1-addopencv
android update project --name "Tutorial 2 (Basic) - Use OpenCV Camera" --target android-11 --path ./tutorial-2-opencvcamera
android update project --name "Tutorial 3 (Advanced) - Add Native OpenCV" --target android-11 --path ./tutorial-3-native
android update project --name "Tutorial 4 (Advanced) - Mix Java+Native OpenCV" --target android-11 --path ./tutorial-4-mixed
</pre>
now the samples are ready to be imported
7. import the 'samples' folder to Eclipse, they may produce warnings in output console and are marked as built with errors
8. right click on each sample project, Properties -> Android, add a library dependency to 'OpenCV-2.4'
the error mark desappears
9. make 'Project -> Clean -> Clean all' to make sure all is built correctly

Andrey Pavlenko

unread,
Apr 16, 2012, 5:01:32 AM4/16/12
to android...@googlegroups.com
We'll think about uploading an updated package with the problems above fixed...

poncho

unread,
Apr 17, 2012, 10:31:05 AM4/17/12
to android...@googlegroups.com
Hi,

Usually it's easier since removing the prefix 'cv' from the method name
and performing a search (text) in Eclipse shows the correct class.
Since 'or' is too common I wasn't able to find the correct Java method
(Core.bitwise_or doesn't seem to be the correct one).

By the way, do you have a better way to discover the encapsulating Java
class if you know the OpenCV method name?

Thanks
/Poncho

Andrey Pavlenko

unread,
Apr 17, 2012, 10:49:52 AM4/17/12
to android...@googlegroups.com
Could you submit new questions in separate threads?

You can use the following algorithm:
- open OpenCV ref man, e.g. http://opencv.itseez.com/
- in the search control on the left pane type 'cvOr' and press Go
- click the most relevant search result, here it is http://opencv.itseez.com/modules/core/doc/operations_on_arrays.html#bitwise-or
- look at the C++ function signature, it will help you to discover the 2.x API function name 
- there is no Java section in this manual, but if you see a Python version starting with cv2.- most likely this function is exported to Java as well
- the Java class (i.e. module name) can be find in URL, e.g. http://opencv.itseez.com/modules/core/doc/operations_on_arrays.html#bitwise-or
Hope this helps...

poncho

unread,
Apr 17, 2012, 11:42:33 AM4/17/12
to android...@googlegroups.com
Thanks, it did help.

Andrew Quitmeyer

unread,
Apr 17, 2012, 10:50:03 PM4/17/12
to android...@googlegroups.com
Thanks for supplying this little guide to finding the correct OpenCV reference stuff for this!
Reply all
Reply to author
Forward
0 new messages