Skip to content

Commit

Permalink
升级Opencv版本到3.4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
hyb1996 committed Dec 16, 2018
1 parent f31e3e5 commit ce00205
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 103 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
Binary file removed app/src/main/jniLibs/armeabi-v7a/libopencv_core.a
Binary file not shown.
Binary file removed app/src/main/jniLibs/armeabi-v7a/libopencv_imgproc.a
Binary file not shown.
Binary file not shown.
5 changes: 3 additions & 2 deletions autojs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ dependencies {
})
api 'com.google.android.material:material:1.1.0-alpha01'
api 'com.github.hyb1996:EnhancedFloaty:0.31'
api 'com.github.hyb1996:OpenCvLib:2.4.13.4-imgproc'
api 'com.makeramen:roundedimageview:2.3.0'
// OpenCv
api(name: 'opencv-3.4.3', ext: 'aar')
// OkHttp
api 'com.squareup.okhttp3:okhttp:3.10.0'
//JDeferred
// JDeferred
api 'org.jdeferred:jdeferred-android-aar:1.2.6'
//RootShell
api 'com.github.Stericson:RootShell:1.6'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
import android.graphics.Color;
import android.media.Image;
import android.os.Build;
import androidx.annotation.RequiresApi;

import com.stardust.autojs.core.opencv.Mat;
import com.stardust.autojs.core.opencv.OpenCVHelper;
import com.stardust.pio.UncheckedIOException;

import org.opencv.android.Utils;
import com.stardust.autojs.core.opencv.Mat;
import org.opencv.highgui.Highgui;
import org.opencv.imgcodecs.Imgcodecs;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.nio.ByteBuffer;

import androidx.annotation.RequiresApi;

/**
* Created by Stardust on 2017/11/25.
*/
Expand Down Expand Up @@ -117,7 +118,7 @@ public void saveTo(String path) {
throw new UncheckedIOException(e);
}
} else {
Highgui.imwrite(path, mMat);
Imgcodecs.imwrite(path, mMat);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ private static void getBestMatched(Mat tmResult, Mat template, int matchMethod,
break;
}
outResult.add(bestMatched);
Core.rectangle(tmResult, bestMatched.point,
Imgproc.rectangle(tmResult, bestMatched.point,
new Point(bestMatched.point.x + template.cols(), bestMatched.point.y + template.rows()),
new Scalar(0, 255, 0), -1);
}
Expand Down
102 changes: 11 additions & 91 deletions autojs/src/main/java/com/stardust/autojs/core/opencv/OpenCVHelper.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.stardust.autojs.core.opencv;

import android.content.Context;

import androidx.annotation.Nullable;

import android.os.Looper;
import android.util.Log;

import com.afollestad.materialdialogs.MaterialDialog;
Expand All @@ -25,7 +28,7 @@ public interface InitializeCallback {
private static final String LOG_TAG = "OpenCVHelper";
private static boolean sInitialized = false;

public static MatOfPoint newMatOfPoint(Mat mat){
public static MatOfPoint newMatOfPoint(Mat mat) {
return new MatOfPoint(mat);
}

Expand All @@ -51,97 +54,14 @@ public synchronized static void initIfNeeded(Context context, InitializeCallback
return;
}
sInitialized = true;
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_13, context.getApplicationContext(), new LoaderCallback(context) {

@Override
protected void finish() {
if (Looper.getMainLooper() == Looper.myLooper()) {
new Thread(() -> {
OpenCVLoader.initDebug();
callback.onInitFinish();
}
});
}


public static class LoaderCallback implements LoaderCallbackInterface {
private Context mContext;

public LoaderCallback(Context context) {
this.mContext = context;
}

public void onManagerConnected(int status) {
switch (status) {
case 0:
finish();
break;
case 1:
default:
Log.e(LOG_TAG, "OpenCV loading failed!");
DialogUtils.showDialog(new MaterialDialog.Builder(mContext)
.title("OpenCV error")
.content("OpenCV was not initialised correctly. Application will be shut down")
.cancelable(false)
.positiveText("OK")
.onPositive((dialog, which) -> finish())
.build());
break;
case 2:
Log.e(LOG_TAG, "Package installation failed!");
DialogUtils.showDialog(new MaterialDialog.Builder(mContext)
.title("OpenCV Manager")
.content("Package installation failed!")
.cancelable(false)
.positiveText("OK")
.onPositive((dialog, which) -> finish())
.build());
break;
case 3:
Log.d(LOG_TAG, "OpenCV library instalation was canceled by user");
finish();
break;
case 4:
Log.d(LOG_TAG, "OpenCV Manager Service is uncompatible with this app!");
DialogUtils.showDialog(new MaterialDialog.Builder(mContext)
.title("OpenCV Manager")
.content("OpenCV Manager service is incompatible with this app. Try to update it via Google Play.")
.cancelable(false)
.positiveText("OK")
.onPositive((dialog, which) -> finish())
.build());
}

}

public void onPackageInstall(int operation, final InstallCallbackInterface callback) {
switch (operation) {
case 0:
DialogUtils.showDialog(new MaterialDialog.Builder(mContext)
.title("Package not found")
.content(callback.getPackageName() + " package was not found! Try to install it?")
.cancelable(false)
.positiveText("Yes")
.onPositive((dialog, which) -> callback.install())
.negativeText("No")
.onNegative(((dialog, which) -> callback.cancel()))
.build());
break;
case 1:
DialogUtils.showDialog(new MaterialDialog.Builder(mContext)
.title("OpenCV is not ready")
.content("Installation is in progress. Wait or exit?")
.cancelable(false)
.positiveText("Wait")
.onPositive((dialog, which) -> callback.wait_install())
.negativeText("Exit")
.onNegative(((dialog, which) -> callback.cancel()))
.build());
default:
finish();
}

}

protected void finish() {
}).start();
} else {
OpenCVLoader.initDebug();
callback.onInitFinish();
}
}

}
2 changes: 1 addition & 1 deletion common/release/output.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":454,"versionName":"4.1.0 Alpha4","enabled":true,"outputFile":"commonRelease-4.1.0 Alpha4.apk","fullName":"commonRelease","baseName":"common-release"},"path":"commonRelease-4.1.0 Alpha4.apk","properties":{}}]
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":455,"versionName":"4.1.0 Alpha5","enabled":true,"outputFile":"commonRelease-4.1.0 Alpha5.apk","fullName":"commonRelease","baseName":"common-release"},"path":"commonRelease-4.1.0 Alpha5.apk","properties":{}}]
14 changes: 12 additions & 2 deletions common/src/main/java/com/stardust/app/DialogUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.content.Context;
import android.content.ContextWrapper;
import android.os.Build;
import android.os.Looper;
import android.view.Window;
import android.view.WindowManager;

Expand All @@ -14,7 +15,7 @@

public class DialogUtils {

public static <T extends Dialog> T showDialog(T dialog) {
public static <T extends Dialog> T showDialog(final T dialog) {
Context context = dialog.getContext();

if (!isActivityContext(context)) {
Expand All @@ -28,7 +29,16 @@ public static <T extends Dialog> T showDialog(T dialog) {
if (window != null)
window.setType(type);
}
dialog.show();
if (Looper.getMainLooper() == Looper.myLooper()) {
dialog.show();
} else {
GlobalAppContext.post(new Runnable() {
@Override
public void run() {
dialog.show();
}
});
}
return dialog;
}

Expand Down
4 changes: 2 additions & 2 deletions project-versions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"appVersionCode": 454,
"appVersionName": "4.1.0 Alpha4",
"appVersionCode": 455,
"appVersionName": "4.1.0 Alpha5",
"target": 28,
"mini": 17,
"compile": 28,
Expand Down

0 comments on commit ce00205

Please sign in to comment.