本文整理汇总了Java中com.cv4j.core.binary.Threshold类的典型用法代码示例。如果您正苦于以下问题:Java Threshold类的具体用法?Java Threshold怎么用?Java Threshold使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Threshold类属于com.cv4j.core.binary包,在下文中一共展示了Threshold类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startOCR
import com.cv4j.core.binary.Threshold; //导入依赖的package包/类
/**
* don't run this code in main thread - it stops UI thread. Create AsyncTask instead.
* http://developer.android.com/intl/ru/reference/android/os/AsyncTask.html
*
* @param imgUri
*/
private void startOCR(Uri imgUri) {
try {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 4; // 1 - means max size. 4 - means maxsize/4 size. Don't use value <4, because you need more memory in the heap to store your data.
Bitmap bitmap = BitmapFactory.decodeFile(imgUri.getPath(), options);
CV4JImage cv4JImage = new CV4JImage(bitmap);
Threshold threshold = new Threshold();
threshold.adaptiveThresh((ByteProcessor)(cv4JImage.convert2Gray().getProcessor()), Threshold.ADAPTIVE_C_MEANS_THRESH, 12, 30, Threshold.METHOD_THRESH_BINARY);
Bitmap newBitmap = cv4JImage.getProcessor().getImage().toBitmap(Bitmap.Config.ARGB_8888);
ivImage2.setImageBitmap(newBitmap);
String result = extractText(newBitmap);
resultView.setText(result);
} catch (Exception e) {
Log.e(TAG, e.getMessage());
}
}
示例2: initData
import com.cv4j.core.binary.Threshold; //导入依赖的package包/类
private void initData() {
toolbar.setTitle("< "+title);
Resources res = getResources();
final Bitmap bitmap = BitmapFactory.decodeResource(res, R.drawable.test_lines);
image0.setImageBitmap(bitmap);
CV4JImage cv4JImage = new CV4JImage(bitmap);
Threshold threshold = new Threshold();
threshold.process((ByteProcessor)(cv4JImage.convert2Gray().getProcessor()),Threshold.THRESH_OTSU,Threshold.METHOD_THRESH_BINARY,255);
image1.setImageBitmap(cv4JImage.getProcessor().getImage().toBitmap());
HoughLinesP houghLinesP = new HoughLinesP();
List<Line> lines = new ArrayList();
houghLinesP.process((ByteProcessor)cv4JImage.getProcessor(),12,10,50,lines);
Bitmap bm2 = Bitmap.createBitmap(cv4JImage.getProcessor().getImage().toBitmap());
Canvas canvas = new Canvas(bm2);
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL_AND_STROKE);
paint.setStrokeWidth(4);
paint.setColor(Color.RED);
for(Line line:lines) {
canvas.drawLine(line.x1,line.y1,line.x2,line.y2,paint);
}
image2.setImageBitmap(bm2);
}
示例3: initData
import com.cv4j.core.binary.Threshold; //导入依赖的package包/类
private void initData() {
toolbar.setTitle("< "+title);
Resources res = getResources();
final Bitmap bitmap = BitmapFactory.decodeResource(res, R.drawable.test_binary1);
image0.setImageBitmap(bitmap);
CV4JImage cv4JImage = new CV4JImage(bitmap);
Threshold threshold = new Threshold();
threshold.process((ByteProcessor)(cv4JImage.convert2Gray().getProcessor()),Threshold.THRESH_TRIANGLE,Threshold.METHOD_THRESH_BINARY_INV,255);
image1.setImageBitmap(cv4JImage.getProcessor().getImage().toBitmap());
MorphOpen morphOpen = new MorphOpen();
cv4JImage.resetBitmap();
morphOpen.process((ByteProcessor)cv4JImage.getProcessor(),new Size(5));
image2.setImageBitmap(cv4JImage.getProcessor().getImage().toBitmap());
ConnectedAreaLabel connectedAreaLabel = new ConnectedAreaLabel();
int[] mask = new int[cv4JImage.getProcessor().getWidth() * cv4JImage.getProcessor().getHeight()];
List<Rect> rectangles = new ArrayList<>();
connectedAreaLabel.process((ByteProcessor)cv4JImage.getProcessor(),mask,rectangles,true);
cv4JImage.resetBitmap();
Bitmap newBitmap = cv4JImage.getProcessor().getImage().toBitmap();
if (Preconditions.isNotBlank(rectangles)) {
Tools.drawRects(newBitmap,rectangles);
}
image3.setImageBitmap(newBitmap);
}