mirror of
https://github.com/opencv/opencv.git
synced 2024-11-24 03:00:14 +08:00
Drop OpenCV Manager from samples initialization.
This commit is contained in:
parent
2c1ec4245d
commit
2830551e89
@ -987,10 +987,6 @@ if(BUILD_EXAMPLES OR BUILD_ANDROID_EXAMPLES OR INSTALL_ANDROID_EXAMPLES OR INSTA
|
||||
add_subdirectory(samples)
|
||||
endif()
|
||||
|
||||
if(ANDROID)
|
||||
add_subdirectory(platforms/android/service)
|
||||
endif()
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Finalization: generate configuration-based files
|
||||
# ----------------------------------------------------------------------------
|
||||
|
@ -1,391 +0,0 @@
|
||||
package org.opencv.android;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.opencv.core.Core;
|
||||
import org.opencv.engine.OpenCVEngineInterface;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.net.Uri;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
|
||||
class AsyncServiceHelper
|
||||
{
|
||||
public static boolean initOpenCV(String Version, final Context AppContext,
|
||||
final LoaderCallbackInterface Callback)
|
||||
{
|
||||
AsyncServiceHelper helper = new AsyncServiceHelper(Version, AppContext, Callback);
|
||||
Intent intent = new Intent("org.opencv.engine.BIND");
|
||||
intent.setPackage("org.opencv.engine");
|
||||
if (AppContext.bindService(intent, helper.mServiceConnection, Context.BIND_AUTO_CREATE))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
AppContext.unbindService(helper.mServiceConnection);
|
||||
InstallService(AppContext, Callback);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected AsyncServiceHelper(String Version, Context AppContext, LoaderCallbackInterface Callback)
|
||||
{
|
||||
mOpenCVersion = Version;
|
||||
mUserAppCallback = Callback;
|
||||
mAppContext = AppContext;
|
||||
}
|
||||
|
||||
protected static final String TAG = "OpenCVManager/Helper";
|
||||
protected static final int MINIMUM_ENGINE_VERSION = 2;
|
||||
protected OpenCVEngineInterface mEngineService;
|
||||
protected LoaderCallbackInterface mUserAppCallback;
|
||||
protected String mOpenCVersion;
|
||||
protected Context mAppContext;
|
||||
protected static boolean mServiceInstallationProgress = false;
|
||||
protected static boolean mLibraryInstallationProgress = false;
|
||||
|
||||
protected static boolean InstallServiceQuiet(Context context)
|
||||
{
|
||||
boolean result = true;
|
||||
try
|
||||
{
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(OPEN_CV_SERVICE_URL));
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected static void InstallService(final Context AppContext, final LoaderCallbackInterface Callback)
|
||||
{
|
||||
if (!mServiceInstallationProgress)
|
||||
{
|
||||
Log.d(TAG, "Request new service installation");
|
||||
InstallCallbackInterface InstallQuery = new InstallCallbackInterface() {
|
||||
private LoaderCallbackInterface mUserAppCallback = Callback;
|
||||
public String getPackageName()
|
||||
{
|
||||
return "OpenCV Manager";
|
||||
}
|
||||
public void install() {
|
||||
Log.d(TAG, "Trying to install OpenCV Manager via Google Play");
|
||||
|
||||
boolean result = InstallServiceQuiet(AppContext);
|
||||
if (result)
|
||||
{
|
||||
mServiceInstallationProgress = true;
|
||||
Log.d(TAG, "Package installation started");
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.d(TAG, "OpenCV package was not installed!");
|
||||
int Status = LoaderCallbackInterface.MARKET_ERROR;
|
||||
Log.d(TAG, "Init finished with status " + Status);
|
||||
Log.d(TAG, "Unbind from service");
|
||||
Log.d(TAG, "Calling using callback");
|
||||
mUserAppCallback.onManagerConnected(Status);
|
||||
}
|
||||
}
|
||||
|
||||
public void cancel()
|
||||
{
|
||||
Log.d(TAG, "OpenCV library installation was canceled");
|
||||
int Status = LoaderCallbackInterface.INSTALL_CANCELED;
|
||||
Log.d(TAG, "Init finished with status " + Status);
|
||||
Log.d(TAG, "Calling using callback");
|
||||
mUserAppCallback.onManagerConnected(Status);
|
||||
}
|
||||
|
||||
public void wait_install()
|
||||
{
|
||||
Log.e(TAG, "Installation was not started! Nothing to wait!");
|
||||
}
|
||||
};
|
||||
|
||||
Callback.onPackageInstall(InstallCallbackInterface.NEW_INSTALLATION, InstallQuery);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.d(TAG, "Waiting current installation process");
|
||||
InstallCallbackInterface WaitQuery = new InstallCallbackInterface() {
|
||||
private LoaderCallbackInterface mUserAppCallback = Callback;
|
||||
public String getPackageName()
|
||||
{
|
||||
return "OpenCV Manager";
|
||||
}
|
||||
public void install()
|
||||
{
|
||||
Log.e(TAG, "Nothing to install we just wait current installation");
|
||||
}
|
||||
public void cancel()
|
||||
{
|
||||
Log.d(TAG, "Waiting for OpenCV canceled by user");
|
||||
mServiceInstallationProgress = false;
|
||||
int Status = LoaderCallbackInterface.INSTALL_CANCELED;
|
||||
Log.d(TAG, "Init finished with status " + Status);
|
||||
Log.d(TAG, "Calling using callback");
|
||||
mUserAppCallback.onManagerConnected(Status);
|
||||
}
|
||||
public void wait_install()
|
||||
{
|
||||
InstallServiceQuiet(AppContext);
|
||||
}
|
||||
};
|
||||
|
||||
Callback.onPackageInstall(InstallCallbackInterface.INSTALLATION_PROGRESS, WaitQuery);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* URL of OpenCV Manager page on Google Play Market.
|
||||
*/
|
||||
protected static final String OPEN_CV_SERVICE_URL = "market://details?id=org.opencv.engine";
|
||||
|
||||
protected ServiceConnection mServiceConnection = new ServiceConnection()
|
||||
{
|
||||
public void onServiceConnected(ComponentName className, IBinder service)
|
||||
{
|
||||
Log.d(TAG, "Service connection created");
|
||||
mEngineService = OpenCVEngineInterface.Stub.asInterface(service);
|
||||
if (null == mEngineService)
|
||||
{
|
||||
Log.d(TAG, "OpenCV Manager Service connection fails. May be service was not installed?");
|
||||
InstallService(mAppContext, mUserAppCallback);
|
||||
}
|
||||
else
|
||||
{
|
||||
mServiceInstallationProgress = false;
|
||||
try
|
||||
{
|
||||
if (mEngineService.getEngineVersion() < MINIMUM_ENGINE_VERSION)
|
||||
{
|
||||
Log.d(TAG, "Init finished with status " + LoaderCallbackInterface.INCOMPATIBLE_MANAGER_VERSION);
|
||||
Log.d(TAG, "Unbind from service");
|
||||
mAppContext.unbindService(mServiceConnection);
|
||||
Log.d(TAG, "Calling using callback");
|
||||
mUserAppCallback.onManagerConnected(LoaderCallbackInterface.INCOMPATIBLE_MANAGER_VERSION);
|
||||
return;
|
||||
}
|
||||
|
||||
Log.d(TAG, "Trying to get library path");
|
||||
String path = mEngineService.getLibPathByVersion(mOpenCVersion);
|
||||
if ((null == path) || (path.length() == 0))
|
||||
{
|
||||
if (!mLibraryInstallationProgress)
|
||||
{
|
||||
InstallCallbackInterface InstallQuery = new InstallCallbackInterface() {
|
||||
public String getPackageName()
|
||||
{
|
||||
return "OpenCV library";
|
||||
}
|
||||
public void install() {
|
||||
Log.d(TAG, "Trying to install OpenCV lib via Google Play");
|
||||
try
|
||||
{
|
||||
if (mEngineService.installVersion(mOpenCVersion))
|
||||
{
|
||||
mLibraryInstallationProgress = true;
|
||||
Log.d(TAG, "Package installation started");
|
||||
Log.d(TAG, "Unbind from service");
|
||||
mAppContext.unbindService(mServiceConnection);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.d(TAG, "OpenCV package was not installed!");
|
||||
Log.d(TAG, "Init finished with status " + LoaderCallbackInterface.MARKET_ERROR);
|
||||
Log.d(TAG, "Unbind from service");
|
||||
mAppContext.unbindService(mServiceConnection);
|
||||
Log.d(TAG, "Calling using callback");
|
||||
mUserAppCallback.onManagerConnected(LoaderCallbackInterface.MARKET_ERROR);
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();;
|
||||
Log.d(TAG, "Init finished with status " + LoaderCallbackInterface.INIT_FAILED);
|
||||
Log.d(TAG, "Unbind from service");
|
||||
mAppContext.unbindService(mServiceConnection);
|
||||
Log.d(TAG, "Calling using callback");
|
||||
mUserAppCallback.onManagerConnected(LoaderCallbackInterface.INIT_FAILED);
|
||||
}
|
||||
}
|
||||
public void cancel() {
|
||||
Log.d(TAG, "OpenCV library installation was canceled");
|
||||
Log.d(TAG, "Init finished with status " + LoaderCallbackInterface.INSTALL_CANCELED);
|
||||
Log.d(TAG, "Unbind from service");
|
||||
mAppContext.unbindService(mServiceConnection);
|
||||
Log.d(TAG, "Calling using callback");
|
||||
mUserAppCallback.onManagerConnected(LoaderCallbackInterface.INSTALL_CANCELED);
|
||||
}
|
||||
public void wait_install() {
|
||||
Log.e(TAG, "Installation was not started! Nothing to wait!");
|
||||
}
|
||||
};
|
||||
|
||||
mUserAppCallback.onPackageInstall(InstallCallbackInterface.NEW_INSTALLATION, InstallQuery);
|
||||
}
|
||||
else
|
||||
{
|
||||
InstallCallbackInterface WaitQuery = new InstallCallbackInterface() {
|
||||
public String getPackageName()
|
||||
{
|
||||
return "OpenCV library";
|
||||
}
|
||||
|
||||
public void install() {
|
||||
Log.e(TAG, "Nothing to install we just wait current installation");
|
||||
}
|
||||
public void cancel()
|
||||
{
|
||||
Log.d(TAG, "OpenCV library installation was canceled");
|
||||
mLibraryInstallationProgress = false;
|
||||
Log.d(TAG, "Init finished with status " + LoaderCallbackInterface.INSTALL_CANCELED);
|
||||
Log.d(TAG, "Unbind from service");
|
||||
mAppContext.unbindService(mServiceConnection);
|
||||
Log.d(TAG, "Calling using callback");
|
||||
mUserAppCallback.onManagerConnected(LoaderCallbackInterface.INSTALL_CANCELED);
|
||||
}
|
||||
public void wait_install() {
|
||||
Log.d(TAG, "Waiting for current installation");
|
||||
try
|
||||
{
|
||||
if (!mEngineService.installVersion(mOpenCVersion))
|
||||
{
|
||||
Log.d(TAG, "OpenCV package was not installed!");
|
||||
Log.d(TAG, "Init finished with status " + LoaderCallbackInterface.MARKET_ERROR);
|
||||
Log.d(TAG, "Calling using callback");
|
||||
mUserAppCallback.onManagerConnected(LoaderCallbackInterface.MARKET_ERROR);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.d(TAG, "Waiting for package installation");
|
||||
}
|
||||
|
||||
Log.d(TAG, "Unbind from service");
|
||||
mAppContext.unbindService(mServiceConnection);
|
||||
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
Log.d(TAG, "Init finished with status " + LoaderCallbackInterface.INIT_FAILED);
|
||||
Log.d(TAG, "Unbind from service");
|
||||
mAppContext.unbindService(mServiceConnection);
|
||||
Log.d(TAG, "Calling using callback");
|
||||
mUserAppCallback.onManagerConnected(LoaderCallbackInterface.INIT_FAILED);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
mUserAppCallback.onPackageInstall(InstallCallbackInterface.INSTALLATION_PROGRESS, WaitQuery);
|
||||
}
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.d(TAG, "Trying to get library list");
|
||||
mLibraryInstallationProgress = false;
|
||||
String libs = mEngineService.getLibraryList(mOpenCVersion);
|
||||
Log.d(TAG, "Library list: \"" + libs + "\"");
|
||||
Log.d(TAG, "First attempt to load libs");
|
||||
int status;
|
||||
if (initOpenCVLibs(path, libs))
|
||||
{
|
||||
Log.d(TAG, "First attempt to load libs is OK");
|
||||
String eol = System.getProperty("line.separator");
|
||||
for (String str : Core.getBuildInformation().split(eol))
|
||||
Log.i(TAG, str);
|
||||
|
||||
status = LoaderCallbackInterface.SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.d(TAG, "First attempt to load libs fails");
|
||||
status = LoaderCallbackInterface.INIT_FAILED;
|
||||
}
|
||||
|
||||
Log.d(TAG, "Init finished with status " + status);
|
||||
Log.d(TAG, "Unbind from service");
|
||||
mAppContext.unbindService(mServiceConnection);
|
||||
Log.d(TAG, "Calling using callback");
|
||||
mUserAppCallback.onManagerConnected(status);
|
||||
}
|
||||
}
|
||||
catch (RemoteException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
Log.d(TAG, "Init finished with status " + LoaderCallbackInterface.INIT_FAILED);
|
||||
Log.d(TAG, "Unbind from service");
|
||||
mAppContext.unbindService(mServiceConnection);
|
||||
Log.d(TAG, "Calling using callback");
|
||||
mUserAppCallback.onManagerConnected(LoaderCallbackInterface.INIT_FAILED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onServiceDisconnected(ComponentName className)
|
||||
{
|
||||
mEngineService = null;
|
||||
}
|
||||
};
|
||||
|
||||
private boolean loadLibrary(String AbsPath)
|
||||
{
|
||||
boolean result = true;
|
||||
|
||||
Log.d(TAG, "Trying to load library " + AbsPath);
|
||||
try
|
||||
{
|
||||
System.load(AbsPath);
|
||||
Log.d(TAG, "OpenCV libs init was ok!");
|
||||
}
|
||||
catch(UnsatisfiedLinkError e)
|
||||
{
|
||||
Log.d(TAG, "Cannot load library \"" + AbsPath + "\"");
|
||||
e.printStackTrace();
|
||||
result = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean initOpenCVLibs(String Path, String Libs)
|
||||
{
|
||||
Log.d(TAG, "Trying to init OpenCV libs");
|
||||
if ((null != Path) && (Path.length() != 0))
|
||||
{
|
||||
boolean result = true;
|
||||
if ((null != Libs) && (Libs.length() != 0))
|
||||
{
|
||||
Log.d(TAG, "Trying to load libs by dependency list");
|
||||
StringTokenizer splitter = new StringTokenizer(Libs, ";");
|
||||
while(splitter.hasMoreTokens())
|
||||
{
|
||||
String AbsLibraryPath = Path + File.separator + splitter.nextToken();
|
||||
result &= loadLibrary(AbsLibraryPath);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// If the dependencies list is not defined or empty.
|
||||
String AbsLibraryPath = Path + File.separator + "libopencv_java4.so";
|
||||
result = loadLibrary(AbsLibraryPath);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.d(TAG, "Library path \"" + Path + "\" is empty");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,141 +0,0 @@
|
||||
package org.opencv.android;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* Basic implementation of LoaderCallbackInterface.
|
||||
*/
|
||||
public abstract class BaseLoaderCallback implements LoaderCallbackInterface {
|
||||
|
||||
public BaseLoaderCallback(Context AppContext) {
|
||||
mAppContext = AppContext;
|
||||
}
|
||||
|
||||
public void onManagerConnected(int status)
|
||||
{
|
||||
switch (status)
|
||||
{
|
||||
/** OpenCV initialization was successful. **/
|
||||
case LoaderCallbackInterface.SUCCESS:
|
||||
{
|
||||
/** Application must override this method to handle successful library initialization. **/
|
||||
} break;
|
||||
/** OpenCV loader can not start Google Play Market. **/
|
||||
case LoaderCallbackInterface.MARKET_ERROR:
|
||||
{
|
||||
Log.e(TAG, "Package installation failed!");
|
||||
AlertDialog MarketErrorMessage = new AlertDialog.Builder(mAppContext).create();
|
||||
MarketErrorMessage.setTitle("OpenCV Manager");
|
||||
MarketErrorMessage.setMessage("Package installation failed!");
|
||||
MarketErrorMessage.setCancelable(false); // This blocks the 'BACK' button
|
||||
MarketErrorMessage.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
MarketErrorMessage.show();
|
||||
} break;
|
||||
/** Package installation has been canceled. **/
|
||||
case LoaderCallbackInterface.INSTALL_CANCELED:
|
||||
{
|
||||
Log.d(TAG, "OpenCV library installation was canceled by user");
|
||||
finish();
|
||||
} break;
|
||||
/** Application is incompatible with this version of OpenCV Manager. Possibly, a service update is required. **/
|
||||
case LoaderCallbackInterface.INCOMPATIBLE_MANAGER_VERSION:
|
||||
{
|
||||
Log.d(TAG, "OpenCV Manager Service is uncompatible with this app!");
|
||||
AlertDialog IncomatibilityMessage = new AlertDialog.Builder(mAppContext).create();
|
||||
IncomatibilityMessage.setTitle("OpenCV Manager");
|
||||
IncomatibilityMessage.setMessage("OpenCV Manager service is incompatible with this app. Try to update it via Google Play.");
|
||||
IncomatibilityMessage.setCancelable(false); // This blocks the 'BACK' button
|
||||
IncomatibilityMessage.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
IncomatibilityMessage.show();
|
||||
} break;
|
||||
/** Other status, i.e. INIT_FAILED. **/
|
||||
default:
|
||||
{
|
||||
Log.e(TAG, "OpenCV loading failed!");
|
||||
AlertDialog InitFailedDialog = new AlertDialog.Builder(mAppContext).create();
|
||||
InitFailedDialog.setTitle("OpenCV error");
|
||||
InitFailedDialog.setMessage("OpenCV was not initialised correctly. Application will be shut down");
|
||||
InitFailedDialog.setCancelable(false); // This blocks the 'BACK' button
|
||||
InitFailedDialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new OnClickListener() {
|
||||
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
InitFailedDialog.show();
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
public void onPackageInstall(final int operation, final InstallCallbackInterface callback)
|
||||
{
|
||||
switch (operation)
|
||||
{
|
||||
case InstallCallbackInterface.NEW_INSTALLATION:
|
||||
{
|
||||
AlertDialog InstallMessage = new AlertDialog.Builder(mAppContext).create();
|
||||
InstallMessage.setTitle("Package not found");
|
||||
InstallMessage.setMessage(callback.getPackageName() + " package was not found! Try to install it?");
|
||||
InstallMessage.setCancelable(false); // This blocks the 'BACK' button
|
||||
InstallMessage.setButton(AlertDialog.BUTTON_POSITIVE, "Yes", new OnClickListener()
|
||||
{
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
callback.install();
|
||||
}
|
||||
});
|
||||
|
||||
InstallMessage.setButton(AlertDialog.BUTTON_NEGATIVE, "No", new OnClickListener() {
|
||||
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
callback.cancel();
|
||||
}
|
||||
});
|
||||
|
||||
InstallMessage.show();
|
||||
} break;
|
||||
case InstallCallbackInterface.INSTALLATION_PROGRESS:
|
||||
{
|
||||
AlertDialog WaitMessage = new AlertDialog.Builder(mAppContext).create();
|
||||
WaitMessage.setTitle("OpenCV is not ready");
|
||||
WaitMessage.setMessage("Installation is in progress. Wait or exit?");
|
||||
WaitMessage.setCancelable(false); // This blocks the 'BACK' button
|
||||
WaitMessage.setButton(AlertDialog.BUTTON_POSITIVE, "Wait", new OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
callback.wait_install();
|
||||
}
|
||||
});
|
||||
WaitMessage.setButton(AlertDialog.BUTTON_NEGATIVE, "Exit", new OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
callback.cancel();
|
||||
}
|
||||
});
|
||||
|
||||
WaitMessage.show();
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void finish()
|
||||
{
|
||||
((Activity) mAppContext).finish();
|
||||
}
|
||||
|
||||
protected Context mAppContext;
|
||||
private final static String TAG = "OCV/BaseLoaderCallback";
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
package org.opencv.android;
|
||||
|
||||
/**
|
||||
* Installation callback interface.
|
||||
*/
|
||||
public interface InstallCallbackInterface
|
||||
{
|
||||
/**
|
||||
* New package installation is required.
|
||||
*/
|
||||
static final int NEW_INSTALLATION = 0;
|
||||
/**
|
||||
* Current package installation is in progress.
|
||||
*/
|
||||
static final int INSTALLATION_PROGRESS = 1;
|
||||
|
||||
/**
|
||||
* Target package name.
|
||||
* @return Return target package name.
|
||||
*/
|
||||
public String getPackageName();
|
||||
/**
|
||||
* Installation is approved.
|
||||
*/
|
||||
public void install();
|
||||
/**
|
||||
* Installation is canceled.
|
||||
*/
|
||||
public void cancel();
|
||||
/**
|
||||
* Wait for package installation.
|
||||
*/
|
||||
public void wait_install();
|
||||
};
|
@ -1,40 +0,0 @@
|
||||
package org.opencv.android;
|
||||
|
||||
/**
|
||||
* Interface for callback object in case of asynchronous initialization of OpenCV.
|
||||
*/
|
||||
public interface LoaderCallbackInterface
|
||||
{
|
||||
/**
|
||||
* OpenCV initialization finished successfully.
|
||||
*/
|
||||
static final int SUCCESS = 0;
|
||||
/**
|
||||
* Google Play Market cannot be invoked.
|
||||
*/
|
||||
static final int MARKET_ERROR = 2;
|
||||
/**
|
||||
* OpenCV library installation has been canceled by the user.
|
||||
*/
|
||||
static final int INSTALL_CANCELED = 3;
|
||||
/**
|
||||
* This version of OpenCV Manager Service is incompatible with the app. Possibly, a service update is required.
|
||||
*/
|
||||
static final int INCOMPATIBLE_MANAGER_VERSION = 4;
|
||||
/**
|
||||
* OpenCV library initialization has failed.
|
||||
*/
|
||||
static final int INIT_FAILED = 0xff;
|
||||
|
||||
/**
|
||||
* Callback method, called after OpenCV library initialization.
|
||||
* @param status status of initialization (see initialization status constants).
|
||||
*/
|
||||
public void onManagerConnected(int status);
|
||||
|
||||
/**
|
||||
* Callback method, called in case the package installation is needed.
|
||||
* @param callback answer object with approve and cancel methods and the package description.
|
||||
*/
|
||||
public void onPackageInstall(final int operation, InstallCallbackInterface callback);
|
||||
};
|
@ -7,102 +7,26 @@ import android.content.Context;
|
||||
*/
|
||||
public class OpenCVLoader
|
||||
{
|
||||
/**
|
||||
* OpenCV Library version 2.4.2.
|
||||
*/
|
||||
public static final String OPENCV_VERSION_2_4_2 = "2.4.2";
|
||||
|
||||
/**
|
||||
* OpenCV Library version 2.4.3.
|
||||
*/
|
||||
public static final String OPENCV_VERSION_2_4_3 = "2.4.3";
|
||||
|
||||
/**
|
||||
* OpenCV Library version 2.4.4.
|
||||
*/
|
||||
public static final String OPENCV_VERSION_2_4_4 = "2.4.4";
|
||||
|
||||
/**
|
||||
* OpenCV Library version 2.4.5.
|
||||
*/
|
||||
public static final String OPENCV_VERSION_2_4_5 = "2.4.5";
|
||||
|
||||
/**
|
||||
* OpenCV Library version 2.4.6.
|
||||
*/
|
||||
public static final String OPENCV_VERSION_2_4_6 = "2.4.6";
|
||||
|
||||
/**
|
||||
* OpenCV Library version 2.4.7.
|
||||
*/
|
||||
public static final String OPENCV_VERSION_2_4_7 = "2.4.7";
|
||||
|
||||
/**
|
||||
* OpenCV Library version 2.4.8.
|
||||
*/
|
||||
public static final String OPENCV_VERSION_2_4_8 = "2.4.8";
|
||||
|
||||
/**
|
||||
* OpenCV Library version 2.4.9.
|
||||
*/
|
||||
public static final String OPENCV_VERSION_2_4_9 = "2.4.9";
|
||||
|
||||
/**
|
||||
* OpenCV Library version 2.4.10.
|
||||
*/
|
||||
public static final String OPENCV_VERSION_2_4_10 = "2.4.10";
|
||||
|
||||
/**
|
||||
* OpenCV Library version 2.4.11.
|
||||
*/
|
||||
public static final String OPENCV_VERSION_2_4_11 = "2.4.11";
|
||||
|
||||
/**
|
||||
* OpenCV Library version 2.4.12.
|
||||
*/
|
||||
public static final String OPENCV_VERSION_2_4_12 = "2.4.12";
|
||||
|
||||
/**
|
||||
* OpenCV Library version 2.4.13.
|
||||
*/
|
||||
public static final String OPENCV_VERSION_2_4_13 = "2.4.13";
|
||||
|
||||
/**
|
||||
* OpenCV Library version 3.0.0.
|
||||
*/
|
||||
public static final String OPENCV_VERSION_3_0_0 = "3.0.0";
|
||||
|
||||
/**
|
||||
* OpenCV Library version 3.1.0.
|
||||
*/
|
||||
public static final String OPENCV_VERSION_3_1_0 = "3.1.0";
|
||||
|
||||
/**
|
||||
* OpenCV Library version 3.2.0.
|
||||
*/
|
||||
public static final String OPENCV_VERSION_3_2_0 = "3.2.0";
|
||||
|
||||
/**
|
||||
* OpenCV Library version 3.3.0.
|
||||
*/
|
||||
public static final String OPENCV_VERSION_3_3_0 = "3.3.0";
|
||||
|
||||
/**
|
||||
* OpenCV Library version 3.4.0.
|
||||
*/
|
||||
public static final String OPENCV_VERSION_3_4_0 = "3.4.0";
|
||||
|
||||
/**
|
||||
* Current OpenCV Library version
|
||||
*/
|
||||
public static final String OPENCV_VERSION = "@OPENCV_VERSION_MAJOR@.@OPENCV_VERSION_MINOR@.@OPENCV_VERSION_PATCH@";
|
||||
|
||||
|
||||
/**
|
||||
* Synonym for initLocal. Deprecated.
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean initDebug()
|
||||
{
|
||||
return StaticHelper.initOpenCV(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads and initializes OpenCV library from current application package. Roughly, it's an analog of system.loadLibrary("opencv_java").
|
||||
* @return Returns true is initialization of OpenCV was successful.
|
||||
*/
|
||||
public static boolean initDebug()
|
||||
public static boolean initLocal()
|
||||
{
|
||||
return StaticHelper.initOpenCV(false);
|
||||
}
|
||||
@ -112,21 +36,9 @@ public class OpenCVLoader
|
||||
* @param InitCuda load and initialize CUDA runtime libraries.
|
||||
* @return Returns true is initialization of OpenCV was successful.
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean initDebug(boolean InitCuda)
|
||||
{
|
||||
return StaticHelper.initOpenCV(InitCuda);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads and initializes OpenCV library using OpenCV Engine service.
|
||||
* @param Version OpenCV library version.
|
||||
* @param AppContext application context for connecting to the service.
|
||||
* @param Callback object, that implements LoaderCallbackInterface for handling the connection status.
|
||||
* @return Returns true if initialization of OpenCV is successful.
|
||||
*/
|
||||
public static boolean initAsync(String Version, Context AppContext,
|
||||
LoaderCallbackInterface Callback)
|
||||
{
|
||||
return AsyncServiceHelper.initOpenCV(Version, AppContext, Callback);
|
||||
}
|
||||
}
|
||||
|
@ -1,33 +0,0 @@
|
||||
package org.opencv.engine;
|
||||
|
||||
/**
|
||||
* Class provides a Java interface for OpenCV Engine Service. It's synchronous with native OpenCVEngine class.
|
||||
*/
|
||||
interface OpenCVEngineInterface
|
||||
{
|
||||
/**
|
||||
* @return Returns service version.
|
||||
*/
|
||||
int getEngineVersion();
|
||||
|
||||
/**
|
||||
* Finds an installed OpenCV library.
|
||||
* @param OpenCV version.
|
||||
* @return Returns path to OpenCV native libs or an empty string if OpenCV can not be found.
|
||||
*/
|
||||
String getLibPathByVersion(String version);
|
||||
|
||||
/**
|
||||
* Tries to install defined version of OpenCV from Google Play Market.
|
||||
* @param OpenCV version.
|
||||
* @return Returns true if installation was successful or OpenCV package has been already installed.
|
||||
*/
|
||||
boolean installVersion(String version);
|
||||
|
||||
/**
|
||||
* Returns list of libraries in loading order, separated by semicolon.
|
||||
* @param OpenCV version.
|
||||
* @return Returns names of OpenCV libraries, separated by semicolon.
|
||||
*/
|
||||
String getLibraryList(String version);
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
if(NOT ANDROID_PROJECTS_BUILD_TYPE STREQUAL "ANT")
|
||||
message(STATUS "Android OpenCV Manager is ignored")
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(BUILD_ANDROID_SERVICE)
|
||||
add_subdirectory(engine)
|
||||
endif()
|
||||
|
||||
install(FILES "readme.txt" DESTINATION "apk/" COMPONENT libs)
|
@ -1,30 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.opencv.engine"
|
||||
android:versionCode="345@ANDROID_PLATFORM_ID@"
|
||||
android:versionName="3.45">
|
||||
|
||||
<uses-sdk android:minSdkVersion="@ANDROID_NATIVE_API_LEVEL@" android:targetSdkVersion="22"/>
|
||||
<uses-feature android:name="android.hardware.touchscreen" android:required="false"/>
|
||||
|
||||
<application
|
||||
android:icon="@drawable/icon"
|
||||
android:label="@string/app_name" android:allowBackup="true">
|
||||
|
||||
<service android:exported="true" android:name="OpenCVEngineService" android:process=":OpenCVEngineProcess">
|
||||
<intent-filter>
|
||||
<action android:name="org.opencv.engine.BIND"></action>
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<activity
|
||||
android:name="org.opencv.engine.manager.ManagerActivity"
|
||||
android:label="@string/app_name"
|
||||
android:screenOrientation="portrait">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
@ -1,3 +0,0 @@
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/${ANDROID_MANIFEST_FILE}" "${OpenCV_BINARY_DIR}/platforms/android/service/engine/.build/${ANDROID_MANIFEST_FILE}" @ONLY)
|
||||
unset(__android_project_chain CACHE)
|
||||
add_android_project(opencv_engine "${CMAKE_CURRENT_SOURCE_DIR}" SDK_TARGET 9 ${ANDROID_SDK_TARGET} IGNORE_JAVA ON IGNORE_MANIFEST ON COPY_LIBS ON)
|
Binary file not shown.
Before Width: | Height: | Size: 2.0 KiB |
@ -1,49 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/ScrollBox"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" >
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical|center_horizontal"
|
||||
android:orientation="vertical"
|
||||
android:scrollbarStyle="insideInset" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView4"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/about"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewIntro"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:autoLink="web"
|
||||
android:text="@string/intro"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView5"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView6"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/CheckEngineUpdate"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical|center_horizontal"
|
||||
android:text="@string/checkUpdate" />
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">OpenCV Manager</string>
|
||||
<string name="about">About</string>
|
||||
<string name="checkUpdate">Check for update</string>
|
||||
<string name="intro">OpenCV library is used by other applications for image enhancement, panorama stitching, object detection, recognition and tracking and so on. OpenCV Manager provides the best version of the OpenCV for your hardware. See opencv.org for details.</string>
|
||||
</resources>
|
@ -1,118 +0,0 @@
|
||||
package org.opencv.engine;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.Matcher;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
public class HardwareDetector {
|
||||
private static String TAG = "OpenCVEngine/HardwareDetector";
|
||||
|
||||
public static final int ARCH_UNKNOWN = -1;
|
||||
|
||||
public static final int ARCH_X86 = 0x01000000;
|
||||
public static final int ARCH_X86_64 = 0x02000000;
|
||||
public static final int ARCH_ARM = 0x04000000;
|
||||
public static final int ARCH_ARMv7 = 0x10000000;
|
||||
public static final int ARCH_ARMv8 = 0x20000000;
|
||||
public static final int ARCH_MIPS = 0x40000000;
|
||||
public static final int ARCH_MIPS_64 = 0x80000000;
|
||||
|
||||
// Return CPU flags list
|
||||
public static List<String> getFlags() {
|
||||
Map<String, String> raw = getRawCpuInfo();
|
||||
String f = raw.get("flags");
|
||||
if (f == null)
|
||||
f = raw.get("Features");
|
||||
if (f == null)
|
||||
return Arrays.asList();
|
||||
return Arrays.asList(TextUtils.split(f, " "));
|
||||
}
|
||||
|
||||
// Return CPU arch
|
||||
public static int getAbi() {
|
||||
List<String> abis = Arrays.asList(Build.CPU_ABI, Build.CPU_ABI2);
|
||||
Log.i(TAG, "ABIs: " + abis.toString());
|
||||
if (abis.contains("x86_64")) {
|
||||
return ARCH_X86_64;
|
||||
} else if (abis.contains("x86")) {
|
||||
return ARCH_X86;
|
||||
} else if (abis.contains("arm64-v8a")) {
|
||||
return ARCH_ARMv8;
|
||||
} else if (abis.contains("armeabi-v7a")
|
||||
|| abis.contains("armeabi-v7a-hard")) {
|
||||
return ARCH_ARMv7;
|
||||
} else if (abis.contains("armeabi")) {
|
||||
return ARCH_ARM;
|
||||
} else if (abis.contains("mips64")) {
|
||||
return ARCH_MIPS_64;
|
||||
} else if (abis.contains("mips")) {
|
||||
return ARCH_MIPS;
|
||||
}
|
||||
return ARCH_UNKNOWN;
|
||||
}
|
||||
|
||||
// Return hardware platform name
|
||||
public static String getHardware() {
|
||||
Map<String, String> raw = getRawCpuInfo();
|
||||
return raw.get("Hardware");
|
||||
}
|
||||
|
||||
// Return processor count
|
||||
public static int getProcessorCount() {
|
||||
int result = 0;
|
||||
try {
|
||||
Pattern pattern = Pattern.compile("(\\d)+(-(\\d+))?");
|
||||
Scanner s = new Scanner(
|
||||
new File("/sys/devices/system/cpu/possible"));
|
||||
if (s.hasNextLine()) {
|
||||
String line = s.nextLine();
|
||||
Log.d(TAG, "Got CPUs: " + line);
|
||||
Matcher m = pattern.matcher(line);
|
||||
while (m.find()) {
|
||||
int start = Integer.parseInt(m.group(1));
|
||||
int finish = start;
|
||||
if (m.group(3) != null) {
|
||||
finish = Integer.parseInt(m.group(3));
|
||||
}
|
||||
result += finish - start + 1;
|
||||
Log.d(TAG, "Got CPU range " + start + " ~ " + finish);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Failed to read cpu count");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
// Return parsed cpuinfo contents
|
||||
public static Map<String, String> getRawCpuInfo() {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
try {
|
||||
Scanner s = new Scanner(new File("/proc/cpuinfo"));
|
||||
while (s.hasNextLine()) {
|
||||
String line = s.nextLine();
|
||||
String[] vals = line.split(": ");
|
||||
if (vals.length > 1) {
|
||||
map.put(vals[0].trim(), vals[1].trim());
|
||||
} else {
|
||||
Log.d(TAG, "Failed to parse cpuinfo: " + line);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Failed to read cpuinfo");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package org.opencv.engine;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
|
||||
public class MarketConnector {
|
||||
protected static final String OpenCVPackageNamePreffix = "org.opencv.lib";
|
||||
private static final String TAG = "OpenCVEngine/MarketConnector";
|
||||
protected Context mContext;
|
||||
|
||||
public MarketConnector(Context context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
public boolean InstallAppFromMarket(String AppID) {
|
||||
Log.d(TAG, "Installing app: " + AppID);
|
||||
boolean result = true;
|
||||
try {
|
||||
Uri uri = Uri.parse("market://details?id=" + AppID);
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
mContext.startActivity(intent);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Installation failed");
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
package org.opencv.engine;
|
||||
|
||||
/**
|
||||
* Class provides Java interface to OpenCV Engine Service. Is synchronous with native OpenCVEngine class.
|
||||
*/
|
||||
interface OpenCVEngineInterface
|
||||
{
|
||||
/**
|
||||
* @return Return service version
|
||||
*/
|
||||
int getEngineVersion();
|
||||
|
||||
/**
|
||||
* Find installed OpenCV library
|
||||
* @param OpenCV version
|
||||
* @return Returns path to OpenCV native libs or empty string if OpenCV was not found
|
||||
*/
|
||||
String getLibPathByVersion(String version);
|
||||
|
||||
/**
|
||||
* Try to install defined version of OpenCV from Google Play (Android Market).
|
||||
* @param OpenCV version
|
||||
* @return Returns true if installation was successful or OpenCV package has been already installed
|
||||
*/
|
||||
boolean installVersion(String version);
|
||||
|
||||
/**
|
||||
* Return list of libraries in loading order separated by ";" symbol
|
||||
* @param OpenCV version
|
||||
* @return Returns OpenCV libraries names separated by symbol ";" in loading order
|
||||
*/
|
||||
String getLibraryList(String version);
|
||||
}
|
@ -1,165 +0,0 @@
|
||||
package org.opencv.engine;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.res.XmlResourceParser;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
import android.text.TextUtils;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
public class OpenCVEngineService extends Service {
|
||||
private static final String TAG = "OpenCVEngine/Service";
|
||||
private IBinder mEngineInterface = null;
|
||||
private List<LibVariant> variants = new ArrayList<LibVariant>();
|
||||
|
||||
private class LibVariant {
|
||||
public String version;
|
||||
public List<String> files;
|
||||
|
||||
public void parseFile(XmlResourceParser p) {
|
||||
try {
|
||||
int eventType = p.getEventType();
|
||||
while (eventType != XmlPullParser.END_DOCUMENT) {
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
if (p.getName().equals("library")) {
|
||||
parseLibraryTag(p);
|
||||
} else if (p.getName().equals("file")) {
|
||||
parseFileTag(p);
|
||||
}
|
||||
}
|
||||
eventType = p.next();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Failed to parse xml library descriptor");
|
||||
}
|
||||
}
|
||||
|
||||
private void parseLibraryTag(XmlResourceParser p) {
|
||||
version = p.getAttributeValue(null, "version");
|
||||
files = new ArrayList<String>();
|
||||
}
|
||||
|
||||
private void parseFileTag(XmlResourceParser p) {
|
||||
files.add(p.getAttributeValue(null, "name"));
|
||||
}
|
||||
|
||||
public boolean hasAllFiles(String path) {
|
||||
boolean result = true;
|
||||
List<String> actualFiles = Arrays.asList((new File(path)).list());
|
||||
for (String f : files)
|
||||
result &= actualFiles.contains(f);
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean isCompatible(String v) {
|
||||
String[] expected = v.split("\\.");
|
||||
String[] actual = version.split("\\.");
|
||||
int i = 0;
|
||||
for (; i < Math.min(expected.length, actual.length); ++i) {
|
||||
int diff = Integer.valueOf(expected[i])
|
||||
- Integer.valueOf(actual[i]);
|
||||
if (diff > 0 || (diff != 0 && i == 0)) {
|
||||
// requested version is greater than actual OR major version differs
|
||||
return false;
|
||||
} else if (diff < 0) {
|
||||
// version is compatible
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (expected.length > i) {
|
||||
// requested version is longer than actual - 2.4.11.2 and 2.4.11
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getFileList() {
|
||||
return TextUtils.join(";", files);
|
||||
}
|
||||
}
|
||||
|
||||
public void onCreate() {
|
||||
Log.d(TAG, "Service starting");
|
||||
for (Field field : R.xml.class.getDeclaredFields()) { // Build error here means that all config.xml files are missing (configuration problem)
|
||||
Log.d(TAG, "Found config: " + field.getName());
|
||||
final LibVariant lib = new LibVariant();
|
||||
try {
|
||||
final int id = field.getInt(R.xml.class);
|
||||
final XmlResourceParser p = getResources().getXml(id);
|
||||
lib.parseFile(p);
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (lib.version != null
|
||||
&& lib.files.size() != 0
|
||||
&& lib.hasAllFiles(getApplication().getApplicationInfo().nativeLibraryDir)) {
|
||||
variants.add(lib);
|
||||
Log.d(TAG, "Added config: " + lib.version);
|
||||
}
|
||||
}
|
||||
super.onCreate();
|
||||
mEngineInterface = new OpenCVEngineInterface.Stub() {
|
||||
|
||||
@Override
|
||||
public boolean installVersion(String version)
|
||||
throws RemoteException {
|
||||
// DO NOTHING
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLibraryList(String version) throws RemoteException {
|
||||
Log.i(TAG, "getLibraryList(" + version + ")");
|
||||
for (LibVariant lib : variants) {
|
||||
Log.i(TAG, "checking " + lib.version + " ...");
|
||||
if (lib.isCompatible(version))
|
||||
return lib.getFileList();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLibPathByVersion(String version)
|
||||
throws RemoteException {
|
||||
// TODO: support API 8
|
||||
return getApplication().getApplicationInfo().nativeLibraryDir;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEngineVersion() throws RemoteException {
|
||||
int version = 3450;
|
||||
try {
|
||||
version = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
|
||||
} catch (NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return version / 1000;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public IBinder onBind(Intent intent) {
|
||||
Log.i(TAG, "Service onBind called for intent " + intent.toString());
|
||||
return mEngineInterface;
|
||||
}
|
||||
|
||||
public boolean onUnbind(Intent intent) {
|
||||
Log.i(TAG, "Service onUnbind called for intent " + intent.toString());
|
||||
return true;
|
||||
}
|
||||
|
||||
public void OnDestroy() {
|
||||
Log.i(TAG, "OpenCV Engine service destruction");
|
||||
}
|
||||
|
||||
}
|
@ -1,113 +0,0 @@
|
||||
package org.opencv.engine.manager;
|
||||
|
||||
import org.opencv.engine.MarketConnector;
|
||||
import org.opencv.engine.HardwareDetector;
|
||||
import org.opencv.engine.OpenCVEngineInterface;
|
||||
import org.opencv.engine.OpenCVEngineService;
|
||||
import org.opencv.engine.R;
|
||||
import android.app.Activity;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class ManagerActivity extends Activity {
|
||||
protected static final String TAG = "OpenCVEngine/Activity";
|
||||
protected MarketConnector mMarket;
|
||||
protected TextView mVersionText;
|
||||
protected boolean mExtraInfo = false;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.main);
|
||||
|
||||
final Class<OpenCVEngineService> c = OpenCVEngineService.class;
|
||||
final String packageName = c.getPackage().getName();
|
||||
|
||||
mMarket = new MarketConnector(this);
|
||||
|
||||
Button updateButton = (Button) findViewById(R.id.CheckEngineUpdate);
|
||||
updateButton.setOnClickListener(new OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
if (!mMarket.InstallAppFromMarket(packageName)) {
|
||||
Toast toast = Toast.makeText(getApplicationContext(),
|
||||
"Google Play is not available", Toast.LENGTH_SHORT);
|
||||
toast.show();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
TextView aboutText = (TextView) findViewById(R.id.textView4);
|
||||
aboutText.setText("About (" + packageName + ")");
|
||||
|
||||
if (mExtraInfo) {
|
||||
TextView extraText = (TextView) findViewById(R.id.textView6);
|
||||
extraText.setText(
|
||||
"CPU count: "
|
||||
+ HardwareDetector.getProcessorCount()
|
||||
+ "\nABI: 0x"
|
||||
+ Integer.toHexString(HardwareDetector.getAbi())
|
||||
+ "\nFlags: "
|
||||
+ TextUtils.join(";", HardwareDetector.getFlags())
|
||||
+ "\nHardware: "
|
||||
+ HardwareDetector.getHardware());
|
||||
}
|
||||
|
||||
mVersionText = (TextView) findViewById(R.id.textView5);
|
||||
if (!bindService(new Intent(this, c),
|
||||
new OpenCVEngineServiceConnection(), Context.BIND_AUTO_CREATE)) {
|
||||
Log.e(TAG, "Failed to bind to service:" + c.getName());
|
||||
mVersionText.setText("not available");
|
||||
} else {
|
||||
Log.d(TAG, "Successfully bound to service:" + c.getName());
|
||||
mVersionText.setText("available");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected class OpenCVEngineServiceConnection implements ServiceConnection {
|
||||
public void onServiceDisconnected(ComponentName name) {
|
||||
Log.d(TAG, "Handle: service disconnected");
|
||||
}
|
||||
|
||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||
Log.d(TAG, "Handle: service connected");
|
||||
OpenCVEngineInterface engine = OpenCVEngineInterface.Stub
|
||||
.asInterface(service);
|
||||
if (engine == null) {
|
||||
Log.e(TAG, "Cannot connect to OpenCV Manager Service!");
|
||||
unbindService(this);
|
||||
return;
|
||||
}
|
||||
Log.d(TAG, "Successful connection");
|
||||
try {
|
||||
String[] vars = { "2.4", "3.0" };
|
||||
String res = new String();
|
||||
for (String piece : vars) {
|
||||
res += "\n\t" + piece + " -> "
|
||||
+ engine.getLibraryList(piece);
|
||||
}
|
||||
mVersionText.setText("Path: "
|
||||
+ engine.getLibPathByVersion(null) + res);
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "Call failed");
|
||||
}
|
||||
unbindService(this);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
How to select the proper version of OpenCV Manager
|
||||
--------------------------------------------------
|
||||
|
||||
Since version 1.7 several packages of OpenCV Manager are built. Every package is targeted for some
|
||||
specific hardware platform and includes corresponding OpenCV binaries. So, in all cases OpenCV
|
||||
Manager uses built-in version of OpenCV. The new package selection logic in most cases simplifies
|
||||
OpenCV installation on end user devices. In most cases OpenCV Manager may be installed automatically
|
||||
from Google Play.
|
||||
|
||||
If Google Play is not available (i.e. on emulator, developer board, etc), you can install it
|
||||
manually using adb tool:
|
||||
|
||||
adb install <path-to-OpenCV-sdk>/apk/OpenCV_<version>_Manager_<app_version>_<platform>.apk
|
||||
|
||||
Example: OpenCV_3.4.5-dev_Manager_3.45_armeabi-v7a.apk
|
||||
|
||||
Use the list of platforms below to determine proper OpenCV Manager package for your device:
|
||||
|
||||
- armeabi (ARMv5, ARMv6)
|
||||
- armeabi-v7a (ARMv7-A + NEON)
|
||||
- arm64-v8a
|
||||
- mips
|
||||
- mips64
|
||||
- x86
|
||||
- x86_64
|
@ -1,8 +1,6 @@
|
||||
package org.opencv.samples.puzzle15;
|
||||
|
||||
import org.opencv.android.BaseLoaderCallback;
|
||||
import org.opencv.android.CameraActivity;
|
||||
import org.opencv.android.LoaderCallbackInterface;
|
||||
import org.opencv.android.OpenCVLoader;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.android.CameraBridgeViewBase;
|
||||
@ -16,6 +14,7 @@ import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@ -29,36 +28,22 @@ public class Puzzle15Activity extends CameraActivity implements CvCameraViewList
|
||||
private MenuItem mItemHideNumbers;
|
||||
private MenuItem mItemStartNewGame;
|
||||
|
||||
|
||||
private int mGameWidth;
|
||||
private int mGameHeight;
|
||||
|
||||
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
|
||||
|
||||
@Override
|
||||
public void onManagerConnected(int status) {
|
||||
switch (status) {
|
||||
case LoaderCallbackInterface.SUCCESS:
|
||||
{
|
||||
Log.i(TAG, "OpenCV loaded successfully");
|
||||
|
||||
/* Now enable camera view to start receiving frames */
|
||||
mOpenCvCameraView.setOnTouchListener(Puzzle15Activity.this);
|
||||
mOpenCvCameraView.enableView();
|
||||
} break;
|
||||
default:
|
||||
{
|
||||
super.onManagerConnected(status);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
|
||||
if (OpenCVLoader.initLocal()) {
|
||||
Log.i(TAG, "OpenCV loaded successfully");
|
||||
} else {
|
||||
Log.e(TAG, "OpenCV initialization failed!");
|
||||
(Toast.makeText(this, "OpenCV initialization failed!", Toast.LENGTH_LONG)).show();
|
||||
return;
|
||||
}
|
||||
|
||||
Log.d(TAG, "Creating and setting view");
|
||||
mOpenCvCameraView = (CameraBridgeViewBase) new JavaCameraView(this, -1);
|
||||
setContentView(mOpenCvCameraView);
|
||||
@ -80,12 +65,9 @@ public class Puzzle15Activity extends CameraActivity implements CvCameraViewList
|
||||
public void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
if (!OpenCVLoader.initDebug()) {
|
||||
Log.d(TAG, "Internal OpenCV library not found. Using OpenCV Manager for initialization");
|
||||
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, this, mLoaderCallback);
|
||||
} else {
|
||||
Log.d(TAG, "OpenCV library found inside package. Using it!");
|
||||
mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
|
||||
if (mOpenCvCameraView != null) {
|
||||
mOpenCvCameraView.setOnTouchListener(Puzzle15Activity.this);
|
||||
mOpenCvCameraView.enableView();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,12 +13,10 @@
|
||||
|
||||
package org.opencv.samples.cameracalibration;
|
||||
|
||||
import org.opencv.android.BaseLoaderCallback;
|
||||
import org.opencv.android.CameraActivity;
|
||||
import org.opencv.android.CameraBridgeViewBase;
|
||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame;
|
||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
|
||||
import org.opencv.android.LoaderCallbackInterface;
|
||||
import org.opencv.android.OpenCVLoader;
|
||||
import org.opencv.core.Mat;
|
||||
|
||||
@ -49,24 +47,6 @@ public class CameraCalibrationActivity extends CameraActivity implements CvCamer
|
||||
private int mWidth;
|
||||
private int mHeight;
|
||||
|
||||
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
|
||||
@Override
|
||||
public void onManagerConnected(int status) {
|
||||
switch (status) {
|
||||
case LoaderCallbackInterface.SUCCESS:
|
||||
{
|
||||
Log.i(TAG, "OpenCV loaded successfully");
|
||||
mOpenCvCameraView.enableView();
|
||||
mOpenCvCameraView.setOnTouchListener(CameraCalibrationActivity.this);
|
||||
} break;
|
||||
default:
|
||||
{
|
||||
super.onManagerConnected(status);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public CameraCalibrationActivity() {
|
||||
Log.i(TAG, "Instantiated new " + this.getClass());
|
||||
}
|
||||
@ -75,6 +55,15 @@ public class CameraCalibrationActivity extends CameraActivity implements CvCamer
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
Log.i(TAG, "called onCreate");
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (OpenCVLoader.initLocal()) {
|
||||
Log.i(TAG, "OpenCV loaded successfully");
|
||||
} else {
|
||||
Log.e(TAG, "OpenCV initialization failed!");
|
||||
(Toast.makeText(this, "OpenCV initialization failed!", Toast.LENGTH_LONG)).show();
|
||||
return;
|
||||
}
|
||||
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
|
||||
setContentView(R.layout.camera_calibration_surface_view);
|
||||
@ -96,12 +85,9 @@ public class CameraCalibrationActivity extends CameraActivity implements CvCamer
|
||||
public void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
if (!OpenCVLoader.initDebug()) {
|
||||
Log.d(TAG, "Internal OpenCV library not found. Using OpenCV Manager for initialization");
|
||||
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, this, mLoaderCallback);
|
||||
} else {
|
||||
Log.d(TAG, "OpenCV library found inside package. Using it!");
|
||||
mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
|
||||
if (mOpenCvCameraView != null) {
|
||||
mOpenCvCameraView.enableView();
|
||||
mOpenCvCameraView.setOnTouchListener(CameraCalibrationActivity.this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,10 +3,8 @@ package org.opencv.samples.colorblobdetect;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.opencv.android.BaseLoaderCallback;
|
||||
import org.opencv.android.CameraActivity;
|
||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame;
|
||||
import org.opencv.android.LoaderCallbackInterface;
|
||||
import org.opencv.android.OpenCVLoader;
|
||||
import org.opencv.core.Core;
|
||||
import org.opencv.core.CvType;
|
||||
@ -28,6 +26,7 @@ import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.view.View.OnTouchListener;
|
||||
import android.view.SurfaceView;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class ColorBlobDetectionActivity extends CameraActivity implements OnTouchListener, CvCameraViewListener2 {
|
||||
private static final String TAG = "OCVSample::Activity";
|
||||
@ -43,24 +42,6 @@ public class ColorBlobDetectionActivity extends CameraActivity implements OnTouc
|
||||
|
||||
private CameraBridgeViewBase mOpenCvCameraView;
|
||||
|
||||
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
|
||||
@Override
|
||||
public void onManagerConnected(int status) {
|
||||
switch (status) {
|
||||
case LoaderCallbackInterface.SUCCESS:
|
||||
{
|
||||
Log.i(TAG, "OpenCV loaded successfully");
|
||||
mOpenCvCameraView.enableView();
|
||||
mOpenCvCameraView.setOnTouchListener(ColorBlobDetectionActivity.this);
|
||||
} break;
|
||||
default:
|
||||
{
|
||||
super.onManagerConnected(status);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public ColorBlobDetectionActivity() {
|
||||
Log.i(TAG, "Instantiated new " + this.getClass());
|
||||
}
|
||||
@ -70,6 +51,15 @@ public class ColorBlobDetectionActivity extends CameraActivity implements OnTouc
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
Log.i(TAG, "called onCreate");
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (OpenCVLoader.initLocal()) {
|
||||
Log.i(TAG, "OpenCV loaded successfully");
|
||||
} else {
|
||||
Log.e(TAG, "OpenCV initialization failed!");
|
||||
(Toast.makeText(this, "OpenCV initialization failed!", Toast.LENGTH_LONG)).show();
|
||||
return;
|
||||
}
|
||||
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
|
||||
@ -92,12 +82,9 @@ public class ColorBlobDetectionActivity extends CameraActivity implements OnTouc
|
||||
public void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
if (!OpenCVLoader.initDebug()) {
|
||||
Log.d(TAG, "Internal OpenCV library not found. Using OpenCV Manager for initialization");
|
||||
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, this, mLoaderCallback);
|
||||
} else {
|
||||
Log.d(TAG, "OpenCV library found inside package. Using it!");
|
||||
mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
|
||||
if (mOpenCvCameraView != null) {
|
||||
mOpenCvCameraView.enableView();
|
||||
mOpenCvCameraView.setOnTouchListener(ColorBlobDetectionActivity.this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,10 +7,8 @@ import java.io.InputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.opencv.android.BaseLoaderCallback;
|
||||
import org.opencv.android.CameraActivity;
|
||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame;
|
||||
import org.opencv.android.LoaderCallbackInterface;
|
||||
import org.opencv.android.OpenCVLoader;
|
||||
import org.opencv.core.Core;
|
||||
import org.opencv.core.Mat;
|
||||
@ -30,6 +28,7 @@ import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class FdActivity extends CameraActivity implements CvCameraViewListener2 {
|
||||
|
||||
@ -58,58 +57,6 @@ public class FdActivity extends CameraActivity implements CvCameraViewListener2
|
||||
|
||||
private CameraBridgeViewBase mOpenCvCameraView;
|
||||
|
||||
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
|
||||
@Override
|
||||
public void onManagerConnected(int status) {
|
||||
switch (status) {
|
||||
case LoaderCallbackInterface.SUCCESS:
|
||||
{
|
||||
Log.i(TAG, "OpenCV loaded successfully");
|
||||
|
||||
// Load native library after(!) OpenCV initialization
|
||||
System.loadLibrary("detection_based_tracker");
|
||||
|
||||
try {
|
||||
// load cascade file from application resources
|
||||
InputStream is = getResources().openRawResource(R.raw.lbpcascade_frontalface);
|
||||
File cascadeDir = getDir("cascade", Context.MODE_PRIVATE);
|
||||
mCascadeFile = new File(cascadeDir, "lbpcascade_frontalface.xml");
|
||||
FileOutputStream os = new FileOutputStream(mCascadeFile);
|
||||
|
||||
byte[] buffer = new byte[4096];
|
||||
int bytesRead;
|
||||
while ((bytesRead = is.read(buffer)) != -1) {
|
||||
os.write(buffer, 0, bytesRead);
|
||||
}
|
||||
is.close();
|
||||
os.close();
|
||||
|
||||
mJavaDetector = new CascadeClassifier(mCascadeFile.getAbsolutePath());
|
||||
if (mJavaDetector.empty()) {
|
||||
Log.e(TAG, "Failed to load cascade classifier");
|
||||
mJavaDetector = null;
|
||||
} else
|
||||
Log.i(TAG, "Loaded cascade classifier from " + mCascadeFile.getAbsolutePath());
|
||||
|
||||
mNativeDetector = new DetectionBasedTracker(mCascadeFile.getAbsolutePath(), 0);
|
||||
|
||||
cascadeDir.delete();
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "Failed to load cascade. Exception thrown: " + e);
|
||||
}
|
||||
|
||||
mOpenCvCameraView.enableView();
|
||||
} break;
|
||||
default:
|
||||
{
|
||||
super.onManagerConnected(status);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public FdActivity() {
|
||||
mDetectorName = new String[2];
|
||||
mDetectorName[JAVA_DETECTOR] = "Java";
|
||||
@ -123,6 +70,49 @@ public class FdActivity extends CameraActivity implements CvCameraViewListener2
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
Log.i(TAG, "called onCreate");
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (OpenCVLoader.initLocal()) {
|
||||
Log.i(TAG, "OpenCV loaded successfully");
|
||||
} else {
|
||||
Log.e(TAG, "OpenCV initialization failed!");
|
||||
(Toast.makeText(this, "OpenCV initialization failed!", Toast.LENGTH_LONG)).show();
|
||||
return;
|
||||
}
|
||||
|
||||
// Load native library after(!) OpenCV initialization
|
||||
System.loadLibrary("detection_based_tracker");
|
||||
|
||||
try {
|
||||
// load cascade file from application resources
|
||||
InputStream is = getResources().openRawResource(R.raw.lbpcascade_frontalface);
|
||||
File cascadeDir = getDir("cascade", Context.MODE_PRIVATE);
|
||||
mCascadeFile = new File(cascadeDir, "lbpcascade_frontalface.xml");
|
||||
FileOutputStream os = new FileOutputStream(mCascadeFile);
|
||||
|
||||
byte[] buffer = new byte[4096];
|
||||
int bytesRead;
|
||||
while ((bytesRead = is.read(buffer)) != -1) {
|
||||
os.write(buffer, 0, bytesRead);
|
||||
}
|
||||
is.close();
|
||||
os.close();
|
||||
|
||||
mJavaDetector = new CascadeClassifier(mCascadeFile.getAbsolutePath());
|
||||
if (mJavaDetector.empty()) {
|
||||
Log.e(TAG, "Failed to load cascade classifier");
|
||||
mJavaDetector = null;
|
||||
} else
|
||||
Log.i(TAG, "Loaded cascade classifier from " + mCascadeFile.getAbsolutePath());
|
||||
|
||||
mNativeDetector = new DetectionBasedTracker(mCascadeFile.getAbsolutePath(), 0);
|
||||
|
||||
cascadeDir.delete();
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "Failed to load cascade. Exception thrown: " + e);
|
||||
}
|
||||
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
|
||||
setContentView(R.layout.face_detect_surface_view);
|
||||
@ -144,13 +134,8 @@ public class FdActivity extends CameraActivity implements CvCameraViewListener2
|
||||
public void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
if (!OpenCVLoader.initDebug()) {
|
||||
Log.d(TAG, "Internal OpenCV library not found. Using OpenCV Manager for initialization");
|
||||
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, this, mLoaderCallback);
|
||||
} else {
|
||||
Log.d(TAG, "OpenCV library found inside package. Using it!");
|
||||
mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
|
||||
}
|
||||
if (mOpenCvCameraView != null)
|
||||
mOpenCvCameraView.enableView();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -4,10 +4,8 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.opencv.android.BaseLoaderCallback;
|
||||
import org.opencv.android.CameraActivity;
|
||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame;
|
||||
import org.opencv.android.LoaderCallbackInterface;
|
||||
import org.opencv.android.OpenCVLoader;
|
||||
import org.opencv.core.Core;
|
||||
import org.opencv.core.CvType;
|
||||
@ -26,6 +24,7 @@ import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class ImageManipulationsActivity extends CameraActivity implements CvCameraViewListener2 {
|
||||
private static final String TAG = "OCVSample::Activity";
|
||||
@ -67,23 +66,6 @@ public class ImageManipulationsActivity extends CameraActivity implements CvCame
|
||||
|
||||
public static int viewMode = VIEW_MODE_RGBA;
|
||||
|
||||
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
|
||||
@Override
|
||||
public void onManagerConnected(int status) {
|
||||
switch (status) {
|
||||
case LoaderCallbackInterface.SUCCESS:
|
||||
{
|
||||
Log.i(TAG, "OpenCV loaded successfully");
|
||||
mOpenCvCameraView.enableView();
|
||||
} break;
|
||||
default:
|
||||
{
|
||||
super.onManagerConnected(status);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public ImageManipulationsActivity() {
|
||||
Log.i(TAG, "Instantiated new " + this.getClass());
|
||||
}
|
||||
@ -93,6 +75,15 @@ public class ImageManipulationsActivity extends CameraActivity implements CvCame
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
Log.i(TAG, "called onCreate");
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (OpenCVLoader.initLocal()) {
|
||||
Log.i(TAG, "OpenCV loaded successfully");
|
||||
} else {
|
||||
Log.e(TAG, "OpenCV initialization failed!");
|
||||
(Toast.makeText(this, "OpenCV initialization failed!", Toast.LENGTH_LONG)).show();
|
||||
return;
|
||||
}
|
||||
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
|
||||
setContentView(R.layout.image_manipulations_surface_view);
|
||||
@ -114,13 +105,8 @@ public class ImageManipulationsActivity extends CameraActivity implements CvCame
|
||||
public void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
if (!OpenCVLoader.initDebug()) {
|
||||
Log.d(TAG, "Internal OpenCV library not found. Using OpenCV Manager for initialization");
|
||||
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, this, mLoaderCallback);
|
||||
} else {
|
||||
Log.d(TAG, "OpenCV library found inside package. Using it!");
|
||||
mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
|
||||
}
|
||||
if (mOpenCvCameraView != null)
|
||||
mOpenCvCameraView.enableView();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -6,11 +6,9 @@ import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.Log;
|
||||
|
||||
import org.opencv.android.BaseLoaderCallback;
|
||||
import org.opencv.android.CameraBridgeViewBase;
|
||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame;
|
||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
|
||||
import org.opencv.android.LoaderCallbackInterface;
|
||||
import org.opencv.android.OpenCVLoader;
|
||||
import org.opencv.core.Core;
|
||||
import org.opencv.core.Mat;
|
||||
@ -25,36 +23,29 @@ import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class MainActivity extends AppCompatActivity implements CvCameraViewListener2 {
|
||||
|
||||
// Initialize OpenCV manager.
|
||||
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
|
||||
@Override
|
||||
public void onManagerConnected(int status) {
|
||||
switch (status) {
|
||||
case LoaderCallbackInterface.SUCCESS: {
|
||||
Log.i(TAG, "OpenCV loaded successfully");
|
||||
mOpenCvCameraView.enableView();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
super.onManagerConnected(status);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION, this, mLoaderCallback);
|
||||
if (mOpenCvCameraView != null)
|
||||
mOpenCvCameraView.enableView();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (OpenCVLoader.initLocal()) {
|
||||
Log.i(TAG, "OpenCV loaded successfully");
|
||||
} else {
|
||||
Log.e(TAG, "OpenCV initialization failed!");
|
||||
(Toast.makeText(this, "OpenCV initialization failed!", Toast.LENGTH_LONG)).show();
|
||||
return;
|
||||
}
|
||||
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
// Set up camera listener.
|
||||
|
@ -1,9 +1,7 @@
|
||||
package org.opencv.samples.tutorial1;
|
||||
|
||||
import org.opencv.android.BaseLoaderCallback;
|
||||
import org.opencv.android.CameraActivity;
|
||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame;
|
||||
import org.opencv.android.LoaderCallbackInterface;
|
||||
import org.opencv.android.OpenCVLoader;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.android.CameraBridgeViewBase;
|
||||
@ -14,6 +12,7 @@ import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
import android.view.SurfaceView;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@ -25,23 +24,6 @@ public class Tutorial1Activity extends CameraActivity implements CvCameraViewLis
|
||||
private boolean mIsJavaCamera = true;
|
||||
private MenuItem mItemSwitchCamera = null;
|
||||
|
||||
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
|
||||
@Override
|
||||
public void onManagerConnected(int status) {
|
||||
switch (status) {
|
||||
case LoaderCallbackInterface.SUCCESS:
|
||||
{
|
||||
Log.i(TAG, "OpenCV loaded successfully");
|
||||
mOpenCvCameraView.enableView();
|
||||
} break;
|
||||
default:
|
||||
{
|
||||
super.onManagerConnected(status);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public Tutorial1Activity() {
|
||||
Log.i(TAG, "Instantiated new " + this.getClass());
|
||||
}
|
||||
@ -51,6 +33,15 @@ public class Tutorial1Activity extends CameraActivity implements CvCameraViewLis
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
Log.i(TAG, "called onCreate");
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (OpenCVLoader.initLocal()) {
|
||||
Log.i(TAG, "OpenCV loaded successfully");
|
||||
} else {
|
||||
Log.e(TAG, "OpenCV initialization failed!");
|
||||
(Toast.makeText(this, "OpenCV initialization failed!", Toast.LENGTH_LONG)).show();
|
||||
return;
|
||||
}
|
||||
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
|
||||
setContentView(R.layout.tutorial1_surface_view);
|
||||
@ -74,13 +65,8 @@ public class Tutorial1Activity extends CameraActivity implements CvCameraViewLis
|
||||
public void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
if (!OpenCVLoader.initDebug()) {
|
||||
Log.d(TAG, "Internal OpenCV library not found. Using OpenCV Manager for initialization");
|
||||
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, this, mLoaderCallback);
|
||||
} else {
|
||||
Log.d(TAG, "OpenCV library found inside package. Using it!");
|
||||
mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
|
||||
}
|
||||
if (mOpenCvCameraView != null)
|
||||
mOpenCvCameraView.enableView();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,9 +1,7 @@
|
||||
package org.opencv.samples.tutorial2;
|
||||
|
||||
import org.opencv.android.BaseLoaderCallback;
|
||||
import org.opencv.android.CameraActivity;
|
||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame;
|
||||
import org.opencv.android.LoaderCallbackInterface;
|
||||
import org.opencv.android.OpenCVLoader;
|
||||
import org.opencv.core.CvType;
|
||||
import org.opencv.core.Mat;
|
||||
@ -16,6 +14,7 @@ import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@ -40,27 +39,6 @@ public class Tutorial2Activity extends CameraActivity implements CvCameraViewLis
|
||||
|
||||
private CameraBridgeViewBase mOpenCvCameraView;
|
||||
|
||||
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
|
||||
@Override
|
||||
public void onManagerConnected(int status) {
|
||||
switch (status) {
|
||||
case LoaderCallbackInterface.SUCCESS:
|
||||
{
|
||||
Log.i(TAG, "OpenCV loaded successfully");
|
||||
|
||||
// Load native library after(!) OpenCV initialization
|
||||
System.loadLibrary("mixed_sample");
|
||||
|
||||
mOpenCvCameraView.enableView();
|
||||
} break;
|
||||
default:
|
||||
{
|
||||
super.onManagerConnected(status);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public Tutorial2Activity() {
|
||||
Log.i(TAG, "Instantiated new " + this.getClass());
|
||||
}
|
||||
@ -70,6 +48,15 @@ public class Tutorial2Activity extends CameraActivity implements CvCameraViewLis
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
Log.i(TAG, "called onCreate");
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (OpenCVLoader.initLocal()) {
|
||||
Log.i(TAG, "OpenCV loaded successfully");
|
||||
} else {
|
||||
Log.e(TAG, "OpenCV initialization failed!");
|
||||
(Toast.makeText(this, "OpenCV initialization failed!", Toast.LENGTH_LONG)).show();
|
||||
return;
|
||||
}
|
||||
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
|
||||
setContentView(R.layout.tutorial2_surface_view);
|
||||
@ -101,13 +88,8 @@ public class Tutorial2Activity extends CameraActivity implements CvCameraViewLis
|
||||
public void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
if (!OpenCVLoader.initDebug()) {
|
||||
Log.d(TAG, "Internal OpenCV library not found. Using OpenCV Manager for initialization");
|
||||
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, this, mLoaderCallback);
|
||||
} else {
|
||||
Log.d(TAG, "OpenCV library found inside package. Using it!");
|
||||
mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
|
||||
}
|
||||
if (mOpenCvCameraView != null)
|
||||
mOpenCvCameraView.enableView();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -6,11 +6,9 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
import org.opencv.android.BaseLoaderCallback;
|
||||
import org.opencv.android.CameraActivity;
|
||||
import org.opencv.android.CameraBridgeViewBase;
|
||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame;
|
||||
import org.opencv.android.LoaderCallbackInterface;
|
||||
import org.opencv.android.OpenCVLoader;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
|
||||
@ -43,24 +41,6 @@ public class Tutorial3Activity extends CameraActivity implements CvCameraViewLis
|
||||
private MenuItem[] mResolutionMenuItems;
|
||||
private SubMenu mResolutionMenu;
|
||||
|
||||
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
|
||||
@Override
|
||||
public void onManagerConnected(int status) {
|
||||
switch (status) {
|
||||
case LoaderCallbackInterface.SUCCESS:
|
||||
{
|
||||
Log.i(TAG, "OpenCV loaded successfully");
|
||||
mOpenCvCameraView.enableView();
|
||||
mOpenCvCameraView.setOnTouchListener(Tutorial3Activity.this);
|
||||
} break;
|
||||
default:
|
||||
{
|
||||
super.onManagerConnected(status);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public Tutorial3Activity() {
|
||||
Log.i(TAG, "Instantiated new " + this.getClass());
|
||||
}
|
||||
@ -70,6 +50,15 @@ public class Tutorial3Activity extends CameraActivity implements CvCameraViewLis
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
Log.i(TAG, "called onCreate");
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (OpenCVLoader.initLocal()) {
|
||||
Log.i(TAG, "OpenCV loaded successfully");
|
||||
} else {
|
||||
Log.e(TAG, "OpenCV initialization failed!");
|
||||
(Toast.makeText(this, "OpenCV initialization failed!", Toast.LENGTH_LONG)).show();
|
||||
return;
|
||||
}
|
||||
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
|
||||
setContentView(R.layout.tutorial3_surface_view);
|
||||
@ -93,12 +82,9 @@ public class Tutorial3Activity extends CameraActivity implements CvCameraViewLis
|
||||
public void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
if (!OpenCVLoader.initDebug()) {
|
||||
Log.d(TAG, "Internal OpenCV library not found. Using OpenCV Manager for initialization");
|
||||
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, this, mLoaderCallback);
|
||||
} else {
|
||||
Log.d(TAG, "OpenCV library found inside package. Using it!");
|
||||
mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
|
||||
if (mOpenCvCameraView != null) {
|
||||
mOpenCvCameraView.enableView();
|
||||
mOpenCvCameraView.setOnTouchListener(Tutorial3Activity.this);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user