- 1android mainfest
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.example.raj.imagetowordconverter">
- <application
- android:allowBackup="true"
- android:icon="@mipmap/ic_launcher"
- android:label="@string/app_name"
- android:roundIcon="@mipmap/ic_launcher_round"
- android:supportsRtl="true"
- android:theme="@style/AppTheme">
- <activity android:name=".MainActivity">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- <meta-data
- android:name="com.google.android.gms.vision.DEPENDENCIES"
- android:value="ocr">
- </meta-data>
- </application>
- </manifest>
- 2 xml
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout 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:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context=".MainActivity"
- android:orientation="vertical">
- <ImageView
- android:layout_gravity="center_horizontal"
- android:scaleType="center"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:id="@+id/image_view"/>
- <Button
- android:layout_below="@id/image_view"
- android:layout_gravity="center_horizontal"
- android:id="@+id/button_process"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="PROCESS"
- />
- <TextView
- android:layout_below="@id/button_process"
- android:id="@+id/result"
- android:gravity="center_horizontal"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="NO TEXT"
- android:textSize="24sp"
- />
- </RelativeLayout>
- 2 main activity
- package com.example.raj.imagetowordconverter;
- import android.graphics.Bitmap;
- import android.graphics.BitmapFactory;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.util.Log;
- import android.util.SparseArray;
- import android.view.View;
- import android.widget.Button;
- import android.widget.ImageView;
- import android.widget.TextView;
- import com.google.android.gms.vision.Frame;
- import com.google.android.gms.vision.text.TextBlock;
- import com.google.android.gms.vision.text.TextRecognizer;
- public class MainActivity extends AppCompatActivity {
- ImageView imageView;
- Button btnp_rocess;
- TextView txtResult;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- imageView=(ImageView)findViewById(R.id.image_view);
- btnp_rocess=(Button)findViewById(R.id.button_process);
- txtResult=(TextView)findViewById(R.id.result);
- final Bitmap bitmap= BitmapFactory.decodeResource(
- getApplicationContext().getResources(),R.drawable.txt
- );
- imageView.setImageBitmap(bitmap);
- btnp_rocess.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- TextRecognizer textRecognizer=new TextRecognizer.Builder(getApplicationContext()).build();
- if (!textRecognizer.isOperational())
- Log.e("ERROR","DECTOR ARE OT FUNCTIONAL");
- else {
- Frame frame=new Frame.Builder().setBitmap(bitmap).build();
- SparseArray<TextBlock> items=textRecognizer.detect(frame);
- StringBuilder stringBuilder=new StringBuilder();
- for (int i=0;i<items.size();++i)
- {
- TextBlock item=items.valueAt(i);
- stringBuilder.append(item.getValue());
- stringBuilder.append("\n");
- }
- txtResult.setText(stringBuilder.toString());
- }
- }
- });
- }
- }
0 comments:
Post a Comment