本文整理汇总了Java中com.googlecode.tesseract.android.TessBaseAPI.setPageSegMode方法的典型用法代码示例。如果您正苦于以下问题:Java TessBaseAPI.setPageSegMode方法的具体用法?Java TessBaseAPI.setPageSegMode怎么用?Java TessBaseAPI.setPageSegMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.googlecode.tesseract.android.TessBaseAPI
的用法示例。
在下文中一共展示了TessBaseAPI.setPageSegMode方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: detectText
import com.googlecode.tesseract.android.TessBaseAPI; //导入方法依赖的package包/类
public String detectText(Bitmap bitmap) {
Log.d(TAG, "Initialization of TessBaseApi");
TessDataManager.initTessTrainedData(context);
TessBaseAPI tessBaseAPI = new TessBaseAPI();
String path = TessDataManager.getTesseractFolder();
Log.d(TAG, "Tess folder: " + path);
tessBaseAPI.setDebug(true);
tessBaseAPI.init(path, "eng");
// 白名单
tessBaseAPI.setVariable(TessBaseAPI.VAR_CHAR_WHITELIST, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
// 黑名单
tessBaseAPI.setVariable(TessBaseAPI.VAR_CHAR_BLACKLIST, "[email protected]#$%^&*()_+=-[]}{;:'\"\\|~`,./<>?");
tessBaseAPI.setPageSegMode(TessBaseAPI.PageSegMode.PSM_AUTO_OSD);
Log.d(TAG, "Ended initialization of TessEngine");
Log.d(TAG, "Running inspection on bitmap");
tessBaseAPI.setImage(bitmap);
String inspection = tessBaseAPI.getHOCRText(0);
Log.d(TAG, "Confidence values: " + tessBaseAPI.meanConfidence());
tessBaseAPI.end();
System.gc();
return Tools.getTelNum(inspection);
}
示例2: doInBackground
import com.googlecode.tesseract.android.TessBaseAPI; //导入方法依赖的package包/类
@Override
protected String doInBackground(String... params) {
runOnUiThread(new Runnable() {
@Override
public void run() {
ProgressWheel pBar = (ProgressWheel) findViewById(R.id.progressBar);
pBar.setVisibility(View.VISIBLE);
pBar.spin();
pBar.setText("Fetching...");
}
});
// Sets Up Tesseract for text recognition.
baseApi = new TessBaseAPI();
baseApi.init(Environment.getExternalStorageDirectory() + "/tesseract/", "eng");
//baseApi.setVariable(TessBaseAPI.VAR_CHAR_WHITELIST,"ABCDEFGHIJKLMNOPQRSTUVWXYZ");
baseApi.setVariable("load_system_dawg","F");
baseApi.setVariable("load_freq_dawg","F");
baseApi.setPageSegMode(TessBaseAPI.PageSegMode.PSM_AUTO_OSD);
for (String key : card.getPatternMap().keySet()) {
if(card.getPatternMap().get(key).getResource().matches("[t][e][x][t].*")) fetchTextNew(card.getPattern(key).getResource());
}
baseApi.end();
return "sucess";
}
示例3: onActivityResult
import com.googlecode.tesseract.android.TessBaseAPI; //导入方法依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK) {
return;
}
if (requestCode == cameraResultCode) {
Bundle extras = data.getExtras();
Bitmap bmp = (Bitmap) extras.get("data");
image.setImageBitmap(bmp);
TessBaseAPI baseApi = new TessBaseAPI();
baseApi.init("/mnt/sdcard/tesseract/", "chi_tra");
baseApi.setPageSegMode(TessBaseAPI.PageSegMode.PSM_SINGLE_LINE);
baseApi.setImage(bmp);
String outputText = baseApi.getUTF8Text();
tessResults.setText(outputText);
}
super.onActivityResult(requestCode, resultCode, data);
}
示例4: onCreate
import com.googlecode.tesseract.android.TessBaseAPI; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_orc_bitmap);
findView();
mTextBitmap = getTextImage("你好", 300, 300);
image.setImageBitmap(mTextBitmap);
baseApi = new TessBaseAPI();
baseApi.init("/mnt/sdcard/tesseract/", "chi_tra");
baseApi.setPageSegMode(TessBaseAPI.PageSegMode.PSM_SINGLE_LINE);
baseApi.setImage(mTextBitmap);
String outputText = baseApi.getUTF8Text();
tessResults.setText(outputText);
}
示例5: init
import com.googlecode.tesseract.android.TessBaseAPI; //导入方法依赖的package包/类
/**
* Initializes the OCR helper and readies it for use.
*
* @param dataPath Path the OCR data files.
* @return Bitmap with replaced colors
*/
public static synchronized OcrHelper init(@NonNull String dataPath,
@NonNull PokeInfoCalculator pokeInfoCalculator,
@NonNull GoIVSettings settings) {
if (instance == null) {
tesseract = new TessBaseAPI();
tesseract.init(dataPath, "eng");
tesseract.setPageSegMode(TessBaseAPI.PageSegMode.PSM_SINGLE_LINE);
tesseract.setVariable(TessBaseAPI.VAR_CHAR_WHITELIST,
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789/♀♂");
nidoFemale = pokeInfoCalculator.get(28).name;
nidoMale = pokeInfoCalculator.get(31).name;
nidoUngendered = nidoFemale.replace("♀", "").toLowerCase();
ocrCache = new LruCache<>(200);
appraisalCache = new LruCache<>(200);
candyWordFirst = isCandyWordFirst();
instance = new OcrHelper();
}
isPokeSpamEnabled = settings.isPokeSpamEnabled();
Map<String, String> appraisalMap = settings.loadAppraisalCache();
for (Map.Entry<String, String> entry : appraisalMap.entrySet()) {
appraisalCache.put(entry.getKey(), entry.getValue());
}
return instance;
}
示例6: testGetUTF8Text
import com.googlecode.tesseract.android.TessBaseAPI; //导入方法依赖的package包/类
@SmallTest
public void testGetUTF8Text() {
// First, make sure the eng.traineddata file exists.
assertTrue("Make sure that you've copied " + DEFAULT_LANGUAGE + ".traineddata to "
+ EXPECTED_FILE, new File(EXPECTED_FILE).exists());
final String inputText = "hello baby";
// Attempt to initialize the API.
final TessBaseAPI baseApi = new TessBaseAPI();
baseApi.init(TESSBASE_PATH, DEFAULT_LANGUAGE);
baseApi.setPageSegMode(TessBaseAPI.PSM_SINGLE_LINE);
// Set the image to a Bitmap containing "hello".
final Bitmap bmp = Bitmap.createBitmap(640, 480, Bitmap.Config.ARGB_8888);
final Paint paint = new Paint();
final Canvas canvas = new Canvas(bmp);
paint.setColor(Color.WHITE);
paint.setStyle(Style.FILL);
canvas.drawRect(new Rect(0, 0, 640, 480), paint);
paint.setColor(Color.BLACK);
paint.setStyle(Style.FILL);
paint.setAntiAlias(true);
paint.setTextAlign(Align.CENTER);
paint.setTextSize(24.0f);
canvas.drawText(inputText, 320, 240, paint);
baseApi.setImage(bmp);
// Ensure that the result is correct.
final String outputText = baseApi.getUTF8Text();
assertTrue("\"" + outputText + "\" != \"" + inputText + "\"", inputText.equals(outputText));
// Attempt to shut down the API.
baseApi.end();
bmp.recycle();
}
示例7: populateMap
import com.googlecode.tesseract.android.TessBaseAPI; //导入方法依赖的package包/类
protected void populateMap(Bitmap bmp) throws ExecutionException, InterruptedException
{
Log.i("info", String.format("Image size: %d x %d", bmp.getWidth(), bmp.getHeight()));
// Attempt to initialize the API.
final TessBaseAPI baseApi = new TessBaseAPI();
baseApi.init(sTessBasePath.get(), DEFAULT_LANGUAGE);
baseApi.setPageSegMode(TessBaseAPI.PageSegMode.PSM_SINGLE_BLOCK);
baseApi.setImage(bmp);
Pixa allLinesPixa = baseApi.getTextlines();
Log.i("info", String.format("allLinesPixa.size() == %d", allLinesPixa.size()));
baseApi.setPageSegMode(PageSegMode.PSM_SINGLE_LINE);
Rect boxRect = allLinesPixa.getBoxRect(1);
baseApi.setRectangle(boxRect);
mStatsMap.put(mAgentStr, baseApi.getUTF8Text().replaceFirst(" .*$", ""));
Log.i("info", "Recognized Agent Name: " + mStatsMap.get(mAgentStr));
boolean varStatus = baseApi.setVariable(TessBaseAPI.VAR_CHAR_WHITELIST, "0123456789,");
baseApi.setRectangle(allLinesPixa.getBoxRect(3));
mStatsMap.put(mApStr, baseApi.getUTF8Text().split("\\s")[0]);
varStatus = baseApi.setVariable(TessBaseAPI.VAR_CHAR_WHITELIST, "");
Log.i("info", "AP: " + mStatsMap.get(mApStr));
for (Rect curRect : allLinesPixa.getBoxRects())
{
baseApi.setRectangle(curRect);
String text = baseApi.getUTF8Text();
for (Pair<String, Integer> statNamePair : mStatNames)
{
if (text.startsWith(statNamePair.first))
{
varStatus = baseApi.setVariable(TessBaseAPI.VAR_CHAR_WHITELIST, "0123456789,M");
baseApi.setRectangle(curRect);
String[] splitStatString = baseApi.getUTF8Text().split("\\s");
int pos = statNamePair.second < 0 ? splitStatString.length+statNamePair.second : statNamePair.second;
mStatsMap.put(statNamePair.first, splitStatString[pos]);
varStatus = baseApi.setVariable(TessBaseAPI.VAR_CHAR_WHITELIST, "");
break;
}
}
}
baseApi.end();
}