Another note to myself which I hope will be useful for others searching it.
Add the following lines to your PRO file in Qt, or create a PRI file using the following and include that in your PRO file.
Note that it is assumed here that OpenCV for Android is extracted to “C:/opencv/OpenCV-android-sdk”
INCLUDEPATH += C:/opencv/OpenCV-android-sdk/sdk/native/jni/include
OPENCV3RDPARTYLIBS = C:/opencv/OpenCV-android-sdk/sdk/native/3rdparty/libs/armeabi-v7a
OPENCVNATIVELIBS = C:/opencv/OpenCV-android-sdk/sdk/native/libs/armeabi-v7a
LIBS += $$OPENCV3RDPARTYLIBS/liblibtiff.a \
$$OPENCV3RDPARTYLIBS/liblibjpeg.a \
$$OPENCV3RDPARTYLIBS/liblibjasper.a \
$$OPENCV3RDPARTYLIBS/liblibpng.a \
$$OPENCV3RDPARTYLIBS/libtbb.a \
$$OPENCV3RDPARTYLIBS/libIlmImf.a
LIBS += $$OPENCVNATIVELIBS/libopencv_core.a \
$$OPENCVNATIVELIBS/libopencv_androidcamera.a \
$$OPENCVNATIVELIBS/libopencv_flann.a \
$$OPENCVNATIVELIBS/libopencv_imgproc.a \
$$OPENCVNATIVELIBS/libopencv_highgui.a \
$$OPENCVNATIVELIBS/libopencv_features2d.a \
$$OPENCVNATIVELIBS/libopencv_calib3d.a \
$$OPENCVNATIVELIBS/libopencv_ml.a \
$$OPENCVNATIVELIBS/libopencv_objdetect.a \
$$OPENCVNATIVELIBS/libopencv_photo.a \
$$OPENCVNATIVELIBS/libopencv_stitching.a \
$$OPENCVNATIVELIBS/libopencv_superres.a \
$$OPENCVNATIVELIBS/libopencv_ts.a \
$$OPENCVNATIVELIBS/libopencv_video.a \
$$OPENCVNATIVELIBS/libopencv_videostab.a \
$$OPENCVNATIVELIBS/libopencv_java.so
Note that you need to copy “libopencv_java.so” to “android-sourceslibsarmeabi-v7a” under your project folder. (If you forget this you’ll face an error mentioning the missing Library file!)
Obviously you should also have the following line in your PRO file so that Qt looks for your Android override files and resources here:
ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android-sources
Here OpenCV 2 and Qt 5.4 are used but it should be pretty much the same for other versions. (Later versions perhaps)
(Updated on 2015-12-15)
Or you can just simply download my .PRI file below and include it in your project (if you have OpenCV installed in C drive’s root)
hi,
Nice article. I built this OK except when I run, the camera doesn’t display.
I checked my open-cv-android sdk (from sourecforge pre-builds) and noticed opencv 3.3 doesn’t include libopencv_androidcamera. a. library. Is this something in sdk 3.x? Or does it require build from source? Have you noticed this before?
Thanks
Unfortunately you shouldn’t count on OpenCV handling the camera for you when working with the C++ interface. Here is one reason among many others. Hope it helps.
On the other hand, if you are using Qt, you can access the camera using QML quite easily, although you won’t get a good performance.
Or, you can use the Java interface which has better camera support.
Solve by adding System.loadLibrary(“opencv_java”); in file “QtLoader.java” befor
if (libName != null)
System.loadLibrary(libName);
hi amin
i have problem by crash app after running 🙁
“Unfortunately, op-app has stopped.”
why?
Hi, Can you be a little bit more specific? Try viewing Compile tab in Qt Creator and let me know what results you get.
E/dalvikvm( 6414): dlopen(“/data/app-lib/org.qtproject.example.android1-1/libandroid1.so”) failed: Cannot load library: soinfo_link_image(linker.cpp:1635): could not load library “libopencv_java.so” needed by “libandroid1.so”; caused by load_library(linker.cpp:745): library “libopencv_java.so” not found
Hello I tried the following post and I still get the problem of missing libraries
Hi Luis,
This may sound funny but did you make sure you have OpenCV for android libraries in the path specified by $$OPENCVNATIVELIBS ???
First of all , thanks you for great tutorial . The application gets created successfully.
I have a problem with my android application apk . when i run it, it crashes for unkown reason ? This is the same problem with @Raja application.
Could you help me please, it’s took many days now ?
i have already try all the version of opencv.
1 – my host : debian
2- target android 5.1
3 – Opencv 2.4.10
Hi Diallo
Can you give me a hint at least as to what your application does? Which main functions do you use? (Camera Galley etc.) And most importantly when does it crash? The main reasons for an application building successfully but crashing at runtime are memory access faults and/or missing runtime libraries. One more question, do you use Qt for building Android apps or are you using Java?
i solve the problem with the crash but know i face to another problem. I have a black screen.
I’m using qt to build my application. it crash when i launch it.
I didn’t quite get it. Does it crash or not? You said you solved the crash but it’s still crashing?!?!
Are you able to build Android applications with Qt and without OpenCV? Check if there’s a problem with your Qt for Android configuration.
Sorry for my bad english, i have no problem with Qt and android .
the problem is when i add opencv library, it open the application on my device with a black screen( No activity).
i just want to get frames from camera.
It’s OK. I was just trying to understand the issue.
I really advice against using Camera lib from OpenCV. I never do it myself. It definitely causes problems in all Android devices and it is not reliable at all, at least for now. Even if it works with one version, there is no guarantee that it will continue to run on it after it is updated. But if you insist on using Camera from OpenCV for Android, then you have to make sure you add Camera*.so files. They do not exist on OpenCV 3.X I assume because they gave up on it but you can try for yourself.
I would also recommend taking a look at this article. With a little bit of modification you can use it with Camera.
http://amin-ahmadi.com/2015/12/08/how-to-open-android-image-gallery-in-qt/
Hello Amin,
Thanks you for your advice. As you said it is very hard to get camera frames by using opencv libraries because android does not permit to acces to camera from native code.
So i will try to use JNI method like your article here http://amin-ahmadi.com/2016/06/18/how-to-access-android-camera-using-qtc/ .
This is the most relevant blog if someone want to use qt on android and others libraries.
Thanks you so much .
Thanks for you kind comments. But please note that this approach may need some modifications in the latest Android update. Let me know if you face any issues.
Hi,
My Android Application apk gets created successfully, but when i run it crashes (i installed OpenCV Manager too…)
I used
i)Qt 5.5.0 ii)OpenCV-2.4.10-android-sdk iii)Moto G(2nd Gen – Lollipop)
iv)opencv_android_qt_template.zip and copied libopencv_java.so also..
Could you please help me.
What you are saying simply means that you are facing a run-time error (and not a compile-time error) My first suggestion would be to try out the latest OpenCV Android SDK to make sure it’s not a bug with OpenCV libraries. I believe the latest version compatible with the libraries you have used is 2.4.12?! (By the way you don’t need to install OpenCV manager at all)
thank you for your great post.
Anyway I have a problem, I followed your post and tried to open an image using cv::imread(…) but couldn’t achieve any succeed. qt showed the error “the vtable symbol may be undefined because the class is missing its key function”. Can you help me with this?
Can you give me a little bit of detail about the configuration you are using? Qt version, OpenCV version etc. Are you using Windows, Linux or Mac?
Thanks for your reply,
I’m using OpenCV Android 3.0.0, Qt5.5 on Windows 7.
When I specified the INCLUDEPATH and LIBS in the .pro file, the program builds fine.
Then I added this line: Mat *mat = new Mat(); it still worked.
But if I add mat = cv::imread(“C:/file/somefile.jpg”, CV_LOAD_IMAGE_COLOR); the error came in.
thank you, i will look for it
I followed your new post and the program still showed that error.
However if I download and use the older version, OpenCV Android v2.4.11, the one right before v3.0.0, the program runs perfectly. I don’t know why, but it does.
Anyway thanks for spending time helping me.
As I told you before, seems there are still some imperfections with the OpenCV 3.0.0 build for Android. With some settings it might work for you but I do not recommend using version 3.0.0 for Android as it is unstable currently.
Ok. I have another problem, I can’t get VideoCapture open any video, whether it is a local file on my device, a http url, rtsp url… etc.
this line works on desktop, but it never runs on my android phone:
VideoCapture cap(“rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov”);
cap.isOpened() always return false
Can you help me?
Have you tried opening a local file of a format that is known to work fine with Android? Like MP4 or AVI for example?
Also please send me the path of local file you are trying to open, in Android exact location of files are confusing sometimes, and it really depends on the permissions you give to your app.
yes I have tried. the video i used is an mp4 file which I downloaded from here
http://www.sample-videos.com
here is the path:
/storage/external_SD/SampleVideo_1080x720_20mb.mp4
I take a screenshot of my video’s details if you want to see:
https://drive.google.com/file/d/0BwJafor6ZYTEWHdvVzQ3UTJwakk/view?usp=sharing
I also think that there may be the permission problem, so I gave my program theses 2 permissions:
android.permission.INTERNET
android.permission.WRITE_EXTERNAL_STORAGE
my android is 4.4.2
Thanks for your reply,
I’m using OpenCV Android 3.0.0, Qt5.5 on Windows 7.
When I specified the INCLUDEPATH and LIBS in the .pro file, the program builds fine.
Then I added this line: Mat *mat = new Mat(); it still worked.
But if I add mat = cv::imread(“C:/file/somefile.jpg”, CV_LOAD_IMAGE_COLOR); the error came in.
First of all, I highly recommend using OpenCV 2.4.X (use the highest version) cause it’s much more stable, but generally if you have entered everything correctly then there should not be a problem. (I am also using 2.4.X by the way.)
On the other hand it is obvious that you have a problem with adding the correct libs. I just made a new post and I suggest you to take a look at it first and compare your code with what I have there. Let me know if it solves your problem. You can find the link below:
http://amin-ahmadi.com/2015/11/30/download-template-project-qt-for-android-with-opencv/