當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。