当前位置: 首页>>代码示例>>Java>>正文


Java Threshold类代码示例

本文整理汇总了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());
    }
}
 
开发者ID:fengzhizi715,项目名称:Tess-TwoDemo,代码行数:27,代码来源:TestChineseWithCV4JActivity.java

示例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);
}
 
开发者ID:imageprocessor,项目名称:cv4j,代码行数:27,代码来源:LineDetectionActivity.java

示例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);
}
 
开发者ID:imageprocessor,项目名称:cv4j,代码行数:31,代码来源:MorphologyActivity.java


注:本文中的com.cv4j.core.binary.Threshold类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。