Skip to main content

Simple example of OCRReader in Android.

Hi Friends, Maybe you all heard/used text scanning using camera feature or extracting text from Image. But this sample made it very easy for you. You can made it in very simple line of code.

You can download the source code from OCRSample and import the library as a module into your project.

Example usage : MainActivity.java
public class MainActivity extends AppCompatActivity {

    private TextView textView;
    private final int CAMERA_SCAN_TEXT = 0;
    private final int LOAD_IMAGE_RESULTS = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        textView = findViewById(R.id.textView);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu_main, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.actionCamera:
                //Scan text from camera.
                OCRCapture.Builder(this)
                        .setUseFlash(true)
                        .setAutoFocus(true)
                        .buildWithRequestCode(CAMERA_SCAN_TEXT);
                break;
            case R.id.actionPhoto:
                Intent intentGallery = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(intentGallery, LOAD_IMAGE_RESULTS);
                break;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data != null) {
            if (requestCode == CAMERA_SCAN_TEXT) {
                if (resultCode == CommonStatusCodes.SUCCESS) {
                    textView.setText(data.getStringExtra(TextBlockObject));
                }
            } else if (requestCode == LOAD_IMAGE_RESULTS) {
                Uri pickedImage = data.getData();
                try {
                    //Extract text from image.
                    String text = OCRCapture.Builder(this).getTextFromUri(pickedImage);
                    //You can also use getTextFromBitmap(Bitmap bitmap) or getTextFromImage(String imagePath) buplic APIs from ibrary. 
                    textView.setText(text);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

Here is the video output of this source code


Interesting right?


If you are really interested in this code, then please share this post with your friends, also share your feedback as comment here.


Get it on Google Play

Source code on GitHub


Thank You


Comments

  1. Hi, It can detect chinese language

    ReplyDelete
  2. ๆƒŠไบบ็š„

    ReplyDelete
  3. เคฎเคนाเค•ाเคฒเคธंเคนिเคคा เค•ाเคฎเค•เคฒाเค•ाเคฒी เค–เคฃ्เคก เคชเคŸเคฒ เฅงเฅซ - เค•ाเคฎเค•เคฒाเค•ाเคฒ्เคฏाः เคช्เคฐाเคฃाเคฏुเคคाเค•्เคทเคฐी เคฎเคจ्เคค्เคฐः

    เค“ं เคं เคน्เคฐीं เคถ्เคฐीं เคน्เคฐीं เค•्เคฒीं เคนूं เค›ूीं เคธ्เคค्เคฐीं เคซ्เคฐें เค•्เคฐों เค•्เคทौं เค†ं เคธ्เคซों เคธ्เคตाเคนा เค•ाเคฎเค•เคฒाเค•ाเคฒि, เคน्เคฐीं เค•्เคฐीं เคน्เคฐीं เคน्เคฐीं เคน्เคฐीं เคนूं เคนूं เคน्เคฐीं เคน्เคฐीं เคน्เคฐीं เค•्เคฐीं เค•्เคฐीं เค•्เคฐीं เค ः เค ः เคฆเค•्เคทिเคฃเค•ाเคฒिเค•े, เคं เค•्เคฐीं เคน्เคฐीं เคนूं เคธ्เคค्เคฐी เคซ्เคฐे เคธ्เคค्เคฐीं เค– เคญเคฆ्เคฐเค•ाเคฒि เคนूं เคนूं เคซเคŸ् เคซเคŸ् เคจเคฎः เคธ्เคตाเคนा เคญเคฆ्เคฐเค•ाเคฒि เค“ं เคน्เคฐीं เคน्เคฐीं เคนूं เคนूं เคญเค—เคตเคคि เคถ्เคฎเคถाเคจเค•ाเคฒि เคจเคฐเค•เค™्เค•ाเคฒเคฎाเคฒाเคงाเคฐिเคฃि เคน्เคฐीं เค•्เคฐीं เค•ुเคฃเคชเคญोเคœिเคจि เคซ्เคฐें เคซ्เคฐें เคธ्เคตाเคนा เคถ्เคฎเคถाเคจเค•ाเคฒि เค•्เคฐीं เคนूं เคน्เคฐीं เคธ्เคค्เคฐीं เคถ्เคฐीं เค•्เคฒीं เคซเคŸ् เคธ्เคตाเคนा เค•ाเคฒเค•ाเคฒि, เค“ं เคซ्เคฐें เคธिเคฆ्เคงिเค•เคฐाเคฒि เคน्เคฐीं เคน्เคฐीं เคนूं เคธ्เคค्เคฐीं เคซ्เคฐें เคจเคฎः เคธ्เคตाเคนा เค—ुเคน्เคฏเค•ाเคฒि, เค“ं เค“ं เคนूं เคน्เคฐीं เคซ्เคฐें เค›्เคฐीं เคธ्เคค्เคฐीं เคถ्เคฐीं เค•्เคฐों เคจเคฎो เคงเคจเค•ाเคฒ्เคฏै เคตिเค•เคฐाเคฒเคฐूเคชिเคฃि เคงเคจं เคฆेเคนि เคฆेเคนि เคฆाเคชเคฏ เคฆाเคชเคฏ เค•्เคทं เค•्เคทां เค•्เคทिं เค•्เคทीं เค•्เคทं เค•्เคทं เค•्เคทं เค•्เคทं เค•्เคท्เคฒं เค•्เคท เค•्เคท เค•्เคท เค•्เคท เค•्เคทः เค•्เคฐों เค•्เคฐोः เค†ं เคน्เคฐीं เคน्เคฐीं เคนूं เคนूं เคจเคฎो เคจเคฎः เคซเคŸ् เคธ्เคตाเคนा เคงเคจเค•ाเคฒिเค•े, เค“ं เคं เค•्เคฒीं เคน्เคฐीं เคนूं เคธिเคฆ्เคงिเค•ाเคฒ्เคฏै เคจเคฎः เคธिเคฆ्เคงिเค•ाเคฒि, เคน्เคฐीं เคšเคฃ्เคกाเคŸ्เคŸเคนाเคธเคจि เคœเค—เคฆ्เค—्เคฐเคธเคจเค•ाเคฐिเคฃि เคจเคฐเคฎुเคฃ्เคกเคฎाเคฒिเคจि เคšเคฃ्เคกเค•ाเคฒिเค•े เค•्เคฒीं เคถ्เคฐीं เคนूं เคซ्เคฐें เคธ्เคค्เคฐीं เค›्เคฐीं เคซเคŸ् เคซเคŸ् เคธ्เคตाเคนा เคšเคฃ्เคกเค•ाเคฒिเค•े เคจเคฎः เค•เคฎเคฒเคตाเคธिเคจ्เคฏै เคธ्เคตाเคนाเคฒเค•्เคท्เคฎि เค“ं เคถ्เคฐीं เคน्เคฐीं เคถ्เคฐीं เค•เคฎเคฒे เค•เคฎเคฒाเคฒเคฏे เคช्เคฐเคธीเคฆ เคช्เคฐเคธीเคฆ เคถ्เคฐीं เคน्เคฐीं เคถ्เคฐी เคฎเคนाเคฒเค•्เคท्เคฎ्เคฏै เคจเคฎः เคฎเคนाเคฒเค•्เคท्เคฎि, เคน्เคฐीं เคจเคฎो เคญเค—เคตเคคि เคฎाเคนेเคถ्เคตเคฐि เค…เคจ्เคจเคชूเคฐ्เคฃे เคธ्เคตाเคนा เค…เคจ्เคจเคชूเคฐ्เคฃे, เค“ं เคน्เคฐीं เคนूं เค‰เคค्เคคिเคท्เค เคชुเคฐुเคทि เค•िं เคธ्เคตเคชिเคทि เคญเคฏं เคฎे เคธเคฎुเคชเคธ्เคฅिเคคं เคฏเคฆि เคถเค•्เคฏเคฎเคถเค•्เคฏं เคตा เค•्เคฐोเคงเคฆुเคฐ्เค—े เคญเค—เคตเคคि เคถเคฎเคฏ เคธ्เคตाเคนा เคนूं เคน्เคฐीं เค“ं, เคตเคจเคฆुเคฐ्เค—े เคน्เคฐीं เคธ्เคซुเคฐ เคธ्เคซुเคฐ เคช्เคฐเคธ्เคซुเคฐ เคช्เคฐเคธ्เคซुเคฐ เค˜ोเคฐเค˜ोเคฐเคคเคฐเคคเคจुเคฐूเคชे เคšเคŸ เคšเคŸ เคช्เคฐเคšเคŸ เคช्เคฐเคšเคŸ เค•เคน เค•เคน เคฐเคฎ เคฐเคฎ เคฌเคจ्เคง เคฌเคจ्เคง เค˜ाเคคเคฏ เค˜ाเคคเคฏ เคนूं เคซเคŸ् เคตिเคœเคฏाเค˜ोเคฐे, เคน्เคฐीं เคชเคฆ्เคฎाเคตเคคि เคธ्เคตाเคนा เคชเคฆ्เคฎाเคตเคคि, เคฎเคนिเคทเคฎเคฐ्เคฆिเคจि เคธ्เคตाเคนा เคฎเคนिเคทเคฎเคฐ्เคฆिเคจि, เค“ं เคฆुเคฐ्เค—े เคฆुเคฐ्เค—े เคฐเค•्เคทिเคฃि เคธ्เคตाเคนा เคœเคฏเคฆुเคฐ्เค—े, เค“ं เคน्เคฐीं เคฆुं เคฆुเคฐ्เค—ाเคฏै เคธ्เคตाเคนा, เคं เคน्เคฐीं เคถ्เคฐीं เค“ं เคจเคฎो เคญเค—เคตเคค เคฎाเคคเค™्เค—ेเคถ्เคตเคฐि เคธเคฐ्เคตเคธ्เคค्เคฐीเคชुเคฐुเคทเคตเคถเค™्เค•เคฐि เคธเคฐ्เคตเคฆुเคท्เคŸเคฎृเค—เคตเคถเค™्เค•เคฐि เคธเคฐ्เคตเค—्เคฐเคนเคตเคถเค™्เค•เคฐि เคธเคฐ्เคตเคธเคค्เคค्เคตเคตเคถเค™्เค•เคฐ เคธเคฐ्เคตเคœเคจเคฎเคจोเคนเคฐि เคธเคฐ्เคตเคฎुเค–เคฐเคž्เคœिเคจि เคธเคฐ्เคตเคฐाเคœเคตเคถเค™्เค•เคฐि เคธเคฐ्เคตเคฒोเค•เคฎเคฎुं เคฎे เคตเคถเคฎाเคจเคฏ เคธ्เคตाเคนा, เคฐाเคœเคฎाเคคเค™्เค— เค‰เคš्เค›िเคท्เคŸเคฎाเคคเค™्เค—िเคจि เคนूं เคน्เคฐीं เค“ं เค•्เคฒीं เคธ्เคตाเคนा เค‰เคš्เค›िเคท्เคŸเคฎाเคคเค™्เค—ि, เค‰เคš्เค›िเคท्เคŸเคšाเคฃ्เคกाเคฒिเคจि เคธुเคฎुเค–ि เคฆेเคตि เคฎเคนाเคชिเคถाเคšिเคจि เคน्เคฐीं เค ः เค ः เค ः เค‰เคš्เค›िเคท्เคŸเคšाเคฃ्เคกाเคฒिเคจि, เค“ं เคน्เคฐीं เคฌเค—เคฒाเคฎुเค–ि เคธเคฐ्เคตเคฆुเคท्เคŸाเคจां เคฎुเค–ं เคตाเคšं เคธ्เคค เคฎ्เคญเคฏ เคœिเคน्เคตां เค•ीเคฒเคฏ เค•ीเคฒเคฏ เคฌुเคฆ्เคงिं เคจाเคถเคฏ เคน्เคฐीं เค“ं เคธ्เคตाเคนा เคฌเค—เคฒे, เคं เคถ्เคฐीं เคน्เคฐीं เค•्เคฒीं เคงเคจเคฒเค•्เคท्เคฎि เค“ं เคน्เคฐीं เคं เคน्เคฐीं เค“ं เคธเคฐเคธ्เคตเคค्เคฏै เคจเคฎः เคธเคฐเคธ्เคตเคคि, เค† เคน्เคฐीं เคนूं เคญुเคตเคจेเคถ्เคตเคฐि, เค“ं เคน्เคฐीं เคถ्เคฐीं เคนूं เค•्เคฒीं เค†ं เค…เคถ्เคตाเคฐूเคขाเคฏै เคซเคŸ् เคซเคŸ् เคธ्เคตाเคนा เค…เคถ्เคตाเคฐूเคขे, เค“ं เคं เคน्เคฐीं เคจिเคค्เคฏเค•्เคฒिเคจ्เคจे เคฎเคฆเคฆ्เคฐเคตे เคं เคน्เคฐीं เคธ्เคตाเคนा เคจिเคค्เคฏเค•्เคฒिเคจ्เคจे । เคธ्เคค्เคฐीं เค•्เคทเคฎเค•เคฒเคน्เคฐเคนเคธเคฏूं.... (เคฌाเคฒाเค•ूเคŸ)... (เคฌเค—เคฒाเค•ूเคŸ )... ( เคค्เคตเคฐिเคคाเค•ूเคŸ) เคœเคฏ เคญैเคฐเคตि เคถ्เคฐीं เคน्เคฐीं เคं เคฌ्เคฒूं เค—्เคฒौः เค…ं เค†ं เค‡ं เคฐाเคœเคฆेเคตि เคฐाเคœเคฒเค•्เคท्เคฎि เค—्เคฒं เค—्เคฒां เค—्เคฒिं เค—्เคฒीं เค—्เคฒुं เค—्เคฒूं เค—्เคฒं เค—्เคฒं เค—्เคฒू เค—्เคฒें เค—्เคฒैं เค—्เคฒों เค—्เคฒौं เค—्เคฒ: เค•्เคฒीं เคถ्เคฐीं เคถ्เคฐीं เคं เคน्เคฐीं เค•्เคฒीं เคชौं เคฐाเคœเคฐाเคœेเคถ्เคตเคฐि เคœ्เคตเคฒ เคœ्เคตเคฒ เคถूเคฒिเคจि เคฆुเคท्เคŸเค—्เคฐเคนं เค—्เคฐเคธ เคธ्เคตाเคนा เคถूเคฒिเคจि, เคน्เคฐीं เคฎเคนाเคšเคฃ्เคกเคฏोเค—ेเคถ्เคตเคฐि เคถ्เคฐीं เคถ्เคฐीं เคถ्เคฐीं เคซเคŸ् เคซเคŸ् เคซเคŸ् เคซเคŸ् เคซเคŸ् เคœเคฏ เคฎเคนाเคšเคฃ्เคก- เคฏोเค—ेเคถ्เคตเคฐि, เคถ्เคฐीं เคน्เคฐीं เค•्เคฒीं เคช्เคฒूं เคं เคน्เคฐीं เค•्เคฒीं เคชौं เค•्เคทीं เค•्เคฒीं เคธिเคฆ्เคงिเคฒเค•्เคท्เคฎ्เคฏै เคจเคฎः เค•्เคฒीं เคชौं เคน्เคฐीं เคं เคฐाเคœ्เคฏเคธिเคฆ्เคงिเคฒเค•्เคท्เคฎि เค“ं เค•्เคฐः เคนूं เค†ं เค•्เคฐों เคธ्เคค्เคฐीं เคนूं เค•्เคทौं เคน्เคฐां เคซเคŸ्... ( เคค्เคตเคฐिเคคाเค•ूเคŸ )... (เคจเค•्เคทเคค्เคฐ- เค•ूเคŸ )... เคธเค•เคนเคฒเคฎเค•्เคทเค–เคตूं ... ( เค—्เคฐเคนเค•ूเคŸ )... เคฎ्เคฒเค•เคนเค•्เคทเคฐเคธ्เคค्เคฐी... (เค•ाเคฎ्เคฏเค•ूเคŸ)... เคฏเคฎ्เคฒเคตी... (เคชाเคฐ्เคถ्เคตเค•ूเคŸ)... (เค•ाเคฎเค•ूเคŸ)... เค—्เคฒเค•्เคทเค•เคฎเคนเคต्เคฏเคŠं เคนเคนเคต्เคฏเค•เคŠं เคฎเคซ़เคฒเคนเคฒเคนเค–เคซूं เคฎ्เคฒเคต्เคฏ्เคฐเคตเคŠं.... (เคถเค™्เค–เค•ूเคŸ )... เคฎ्เคฒเค•्เคทเค•เคธเคนเคนूं เค•्เคทเคฎ्เคฒเคฌ्เคฐเคธเคนเคธ्เคนเค•्เคทเค•्เคฒเคธ्เคค्เคฐीं เคฐเค•्เคทเคฒเคนเคฎเคธเคนเค•เคฌ्เคฐूं... (เคฎเคค्เคธ्เคฏเค•ूเคŸ ).... (เคค्เคฐिเคถूเคฒเค•ूเคŸ)... เคเคธเค–เค—्เคฐเคฎเคŠ เคนृเค•्เคท्เคฎเคฒी เคน्เคฐीं เคน्เคฐीं เคนूं เค•्เคฒीं เคธ्เคค्เคฐीं เคं เค•्เคฐौं เค›्เคฐी เคซ्เคฐें เค•्เคฐीं เค—्เคฒเค•्เคทเค•- เคฎเคนเคต्เคฏเคŠ เคนूं เค…เค˜ोเคฐे เคธिเคฆ्เคงिं เคฎे เคฆेเคนि เคฆाเคชเคฏ เคธ्เคตाเคนा เค…เค˜ोเคฐे, เค“ं เคจเคฎเคถ्เคšा ameya jaywant narvekar

    ReplyDelete
  4. ุงูุถู„ ุฎุฏู…ุงุช ุงู„ุชู†ุธูŠู
    ุดุฑูƒุฉ ุชู†ุธูŠู ุจุงู„ุงุญุณุงุก

    ReplyDelete

Post a Comment

Popular posts from this blog

Simple example of using Spinner in Kotlin | Android

Though Kotlin has lot massive features to speedup the development time, here is the simple way of using Spinner in Android. In Kotlin we don't need to declare and initialize Spinner. We can simply access the id of Spinner from xml. Ex : import android.os.Bundle import android.support.v7.app.AppCompatActivity import android.view.View import android.widget.AdapterView import android.widget.ArrayAdapter import android.widget.Toast import android.widget.Toast.LENGTH_LONG import kotlinx.android.synthetic.main.activity_main.* class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) //String array. val myStrings = arrayOf("One", "Two", "Three", "Four", "Five") //Adapter for spinner mySpinner.adapter = ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_i...

Simple example of Navigation view on both side in Android

Hi guys, you can use NavigationView on both side if you want side menu in both left and right side in Android as following. Your drawer layout will be &lt?xml version="1.0" encoding="utf-8"?&gt &ltandroid.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" tools:openDrawer="start"&gt &ltinclude layout="@layout/app_bar_main" android:layout_width="match_parent" android:layout_height="match_parent" /&gt &ltandroid.support.design.widget.NavigationView android:id="@+id/nav_view" ...

Simple RecyclerView example with filter option in Android

Hi Guys, Maybe you all are expert in terms of using RecyclerView in android. This blog is simple example for using filter option with RecyclerView adapter. As for now you will instantiate RecyclerView and set the adapter to RecyclerView as following way. RecyclerView list = (RecyclerView) findViewById(R.id.list); list.setLayoutManager(new LinearLayoutManager(this)); list.setHasFixedSize(true); ArrayList&ltNumber&gt numbers = new ArrayList&lt&gt(); String ONEs[] = {"ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE", "TEN"}; String TENs[] = {"ZERO", "TEN", "TWENTY", "THIRTY", "FOURTY", "FIFTY", "SIXTY", "SEVENTY", "EIGHTY", "NINETY", "HUNDRED"}; String HUNDREDS[] = {"ZERO", "HUNDRED", "TWO HUND...