升级Opencv版本到3.4.3
This commit is contained in:
@@ -4,19 +4,20 @@ import android.graphics.Bitmap;
|
||||
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.
|
||||
*/
|
||||
@@ -117,7 +118,7 @@ public class ImageWrapper {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
} else {
|
||||
Highgui.imwrite(path, mMat);
|
||||
Imgcodecs.imwrite(path, mMat);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -214,7 +214,7 @@ public class TemplateMatching {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -25,7 +28,7 @@ public class OpenCVHelper {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -51,97 +54,14 @@ public class OpenCVHelper {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user