title: Extract specific string from image in android using google cloud vision Api
body: <p>I am working on application where I am entering data by capturing or selecting images to keep user interaction minimum and application will read data or text in an image. I want to extract any price of product in the image and for that I am using google's cloud vision API. it is working very well but it extracts all the text in an image. How can I extract just pricing information such as any string contaning $,Rs,euro sign etc from that image? Here is my code for selecting image from gallery and extracting text from it.</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
      //SurfaceView cameraView;
      TextView textView;
      ImageView imageView;
      Button select , take ;
      ImageButton process;
      private static final int PICK_IMAGE=100;
      Uri image_URI;
      // CameraSource cameraSource;
      final int  RequestCameraPermissionID = 1001;
      Bitmap bitmap ;
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          // inialize all the views
          process = (ImageButton) findViewById(R.id.process);
          textView = (TextView) findViewById(R.id.view_text);
          imageView =(ImageView)findViewById(R.id.image);
          select = (Button) findViewById(R.id.select);
          take = (Button) findViewById(R.id.take);
  
          // set listener of take photo button
          take.setOnClickListener(new View.OnClickListener(){
              public void onClick(View view){
                  Intent intent = new Intent(MainActivity.this,CameraActivity.class);
                  startActivity(intent);
              }
          });
  
          //set listener of select photo button
          select.setOnClickListener(
                  new View.OnClickListener() {
                      @Override
                      public void onClick(View v) {
                          openGallery(); // call openGallery function
                      }
                  });
  
          //set listener of button which will process the image ie extract text from it
          process.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  TextRecognizer textRecognizer = new TextRecognizer.Builder(getApplicationContext()).build();
                  if (!textRecognizer.isOperational()) {
                      Toast.makeText(getApplicationContext(), "Detector is not available yet", Toast.LENGTH_LONG);
                  }
                  Frame frame = new Frame.Builder().setBitmap(bitmap).build();
                  final SparseArray&lt;TextBlock&gt; items = textRecognizer.detect(frame);
                  if (items.size() != 0) {
                      textView.post(new Runnable() {
                          @Override
                          public void run() {
                              StringBuilder stringBuilder = new StringBuilder();
                              for (int i = 0; i &lt; items.size(); i++) {
                                  TextBlock item = items.valueAt(i);
                                  stringBuilder.append(item.getValue());
                                  stringBuilder.append("\n");
                              }
                              textView.setText(stringBuilder.toString());
                          }
                      });
                  }
              }
          });
  
  
      }
  
  
  
      private void openGallery(){
  
          Intent gallery = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
          startActivityForResult(gallery,PICK_IMAGE);
      }
  
      //
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data){
          super.onActivityResult(requestCode,resultCode,data);
          if(resultCode == RESULT_OK &amp;&amp; requestCode==PICK_IMAGE){
              image_URI = data.getData();
              imageView.setImageURI(image_URI);
              try {
                  InputStream pic = getContentResolver().openInputStream(image_URI);
                  bitmap = BitmapFactory.decodeStream(pic);
              } catch (FileNotFoundException e) {
                  e.printStackTrace();
              }
          }
      }
  }
  </code></pre>
  
  <p>here is the output:</p>
  
  <p><a href="https://i.stack.imgur.com/XkXmD.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XkXmD.jpg" alt="enter image description here"></a></p>