新增 images自适应二值化

This commit is contained in:
hyb1996
2018-10-24 21:41:20 +08:00
parent 8864e78af6
commit 245d13c377
4 changed files with 31 additions and 16 deletions

View File

@@ -1,14 +1,14 @@
"ui";
var url = "https://www.autojs.org/assets/uploads/profile/3-profileavatar.png";
var url = "https://www.autojs.org/assets/uploads/files/1540386817060-918021-20160416200702191-185324559.jpg";
var logo = null;
var currentImg = null;
ui.layout(
<vertical>
<img id="img" w="150" h="150" url="{{url}}" />
<img id="img" w="250" h="250" url="{{url}}" />
<button id="grayscale" text="灰度化" />
<button id="binary" text="二值化" />
<button id="adaptiveBinary" text="自适应二值化" />
<button id="hsv" text="RGB转HSV" />
<button id="blur" text="模糊" />
<button id="medianBlur" text="中值滤波" />
@@ -19,14 +19,7 @@ ui.layout(
//把一张图片设置到图片控件中
function setImage(img) {
ui.run(() => {
var curImg = currentImg;
if(oldImg != null){
ui.post(()=>{
oldImg.recycle();
});
}
ui.img.setImageBitmap(img.bitmap);
currentImg = img;
});
}
@@ -57,8 +50,21 @@ ui.grayscale.on("click", () => {
ui.binary.on("click", () => {
processImg(img => {
var g = images.grayscale(img);
//二值化取灰度为30到200之间的图片
return images.threshold(images.grayscale(img), 100, 200);
var result = images.threshold(g, 100, 200);
g.recycle();
return result;
});
});
ui.adaptiveBinary.on("click", () => {
processImg(img => {
var g = images.grayscale(img);
//自适应二值化最大值为200块大小为25
var result = images.adaptiveThreshold(g, 200, "MEAN_C", "BINARY", 25, 10);
g.recycle();
return result;
});
});
@@ -82,6 +88,7 @@ ui.medianBlur.on("click", () => {
return images.medianBlur(img, 5);
});
});
ui.gaussianBlur.on("click", () => {
processImg(img => {
//高斯模糊

View File

@@ -68,12 +68,20 @@ module.exports = function (__runtime__, scope) {
images.threshold = function (img, threshold, maxVal, type) {
var mat = newMat();
type = type || "binary";
type = Imgproc["THRESH_" + type.toUpperCase()];
type = type || "BINARY";
type = Imgproc["THRESH_" + type];
Imgproc.threshold(img.mat, mat, threshold, maxVal, type);
return matToImage(mat);
}
images.adaptiveThreshold = function(img, maxValue, adaptiveMethod, thresholdType, blockSize, C){
var mat = newMat();
adaptiveMethod = Imgproc["ADAPTIVE_THRESH_" + adaptiveMethod];
thresholdType = Imgproc["THRESH_" + thresholdType];
Imgproc.adaptiveThreshold(img.mat, mat, maxValue, adaptiveMethod, thresholdType, blockSize, C);
return matToImage(mat);
}
images.blur = function (img, size, point, type) {
var mat = newMat();
size = newSize(size);

View File

@@ -9,6 +9,7 @@ import com.afollestad.materialdialogs.MaterialDialog;
import org.opencv.android.InstallCallbackInterface;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.imgproc.Imgproc;
/**
@@ -46,7 +47,6 @@ public class OpenCVHelper {
callback.onInitFinish();
return;
}
mInitialized = true;
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_13, activity.getApplicationContext(), new LoaderCallback(activity) {

View File

@@ -1,4 +1,3 @@
// ResourceMonitor$onFinalize$1.java
package com.stardust.util;
import android.os.Handler;
@@ -12,7 +11,8 @@ import java.util.concurrent.ConcurrentHashMap;
public final class ResourceMonitor {
private static final String LOG_TAG = "ResourceTracer";
private static final String LOG_TAG = "ResourceMonitor";
private static final ConcurrentHashMap<Class<?>, SparseArray<UnclosedResourceException>> mResources;
private static Handler mHandler;
private static boolean mEnabled;