Hi guys,
I have not been so frustrated in long time. After a full day, I am still unable to compile an hello world in Android.
OpenCV for android 4.7.0 as downloaded
Android Studio Flamingo | 2022.2.1
Installed multiple SDK version, SDK built tools, NDK, command line tools, platform tools + some irrelevant extras.
Successfully tested a simple camera capture program using only android (not opencv).
Followed the tutorial:
However, I am unable to get it compiled:
error: package org.opencv.engine does not exist
import org.opencv.engine.OpenCVEngineInterface;
I found hundred of “solutions” on the internet. NONE of them works.
Ended up copying all the opencv java into the project,
i have the whole org/opencv/ tree in main, i have added the jniLibs folder, fixed version inconsistencies in gradle files etc…
Still, nothing works.
I was assuming that maybe I need to compile the opencv sdk.
Attempting to import the opencv/sdk in Android Studio to see if it compile. It does not:
A problem occurred evaluating root project ‘sdk’.
Plugin with id ‘com.android.library’ not found.
Questions:
The android packet is ready to go or need compiled ?
How to get OpenCV to compile in Android Studio, if this is the problem?
If no, any hints to alleviate a nerve-racking experience ?
You could have a try to add “android.defaults.buildfeatures.aidl=true” to the gradle.properties. to enable the aidl buildfeature.
ref: BuildFeatures | Android Developers
Thank you @ankit_sachan for documenting this. I followed the documentation and the build went smoothly. But when I try to run the app, I get an error that “OpenCV Manager” package not installed and it redirects me to Google Playstore. Any idea what needs to be done to tackle this?
OK, just after I posted this, I happened to look at the OpenCV build.gradle file that had this comment:
// Load OpenCV native library before using:
//
// - avoid using of "OpenCVLoader.initAsync()" approach - it is deprecated
// It may load library with different version (from OpenCV Android Manager, which is installed separatelly on device)
//
// - use "System.loadLibrary("opencv_java4")" or "OpenCVLoader.initDebug()"
@Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
Imgproc.cvtColor(inputFrame.rgba(), rgb, Imgproc.COLOR_RGBA2RGB);
/*
--- Your logic
// Do your processing before rotating the image so that the corner/pose estimations are not affected
*/
Mat localRGB;
// Ref: https://stackoverflow.com/a/28601634
Core.rotate(rgb, localRGB, Core.ROTATE_90_CLOCKWISE);
//ref: https://stackoverflow.com/a/37972813
Imgproc.resize(localRGB, rgb, rgb.size());
return rgb;
}