mardi 1 septembre 2020

How to read graph plots for automation testing

I'm trying to test graph in my android app using Appium. I tried to read the plots from my graph using OCR with libraries like Tesseract, Asprise etc, but none of them read all the numbers in my graph. Is there any way to automation test my graph in any other way, or is there any way I can make those OCR libraries read all the numbers in my graph?

This is my Tesseract code to do OCR on my graph screenshot:

public static void
    processImg(BufferedImage ipimage, 
               float scaleFactor, 
               float offset) 
        throws IOException, TesseractException 
    { 
        // Making an empty image buffer 
        // to store image later 
        // ipimage is an image buffer 
        // of input image 
        BufferedImage opimage 
            = new BufferedImage(1050, 
                                1024, 
                                ipimage.getType()); 
  
        // creating a 2D platform 
        // on the buffer image 
        // for drawing the new image 
        Graphics2D graphic 
            = opimage.createGraphics(); 
  
        // drawing new image starting from 0 0 
        // of size 1050 x 1024 (zoomed images) 
        // null is the ImageObserver class object 
        graphic.drawImage(ipimage, 0, 0, 
                          1050, 1024, null); 
        graphic.dispose(); 
  
        // rescale OP object 
        // for gray scaling images 
        RescaleOp rescale 
            = new RescaleOp(scaleFactor, offset, null); 
  
        // performing scaling 
        BufferedImage fopimage 
            = rescale.filter(opimage, null); 

        // Instantiating the Tesseract class 
        // which is used to perform OCR 
        Tesseract it = new Tesseract(); 
  
        it.setDatapath("C:\\Program Files (x86)\\Tess4J\\tessdata"); 

  
        // doing OCR on the image 
        // and storing result in string str 
        String str = it.doOCR(fopimage); 
        System.out.println(str); 
    } 



public void myMethod()
{

      BufferedImage ipimage = ImageIO.read(f); 

      // getting RGB content of the whole image file 
      double d = ipimage.getRGB(ipimage.getTileWidth() / 2, ipimage.getTileHeight() / 2); 

      // comparing the values 
      // and setting new scaling values 
      // that are later on used by RescaleOP 
      if (d >= -1.4211511E7 && d < -7254228) { 
          processImg(ipimage, 3f, -10f); 
      } 
      else if (d >= -7254228 && d < -2171170) { 
          processImg(ipimage, 1.455f, -47f); 
      } 
      else if (d >= -2171170 && d < -1907998) { 
          processImg(ipimage, 1.35f, -10f); 
      } 
      else if (d >= -1907998 && d < -257) { 
          processImg(ipimage, 1.19f, 0.5f); 
      } 
      else if (d >= -257 && d < -1) { 
          processImg(ipimage, 1f, 0.5f); 
      } 
      else if (d >= -1 && d < 2) { 
          processImg(ipimage, 1f, 0.35f); 
      } 
      

This is screenshot of my graph:

Graph

The output of OCR is:

9000 131 13,000 12,000 11,000 10,000 9,630 9,000 g I I I I I I Cells

As you can see, the value of the first column in my graph has been extracted as 'g' instead of 9000. How do I make this work? Or is there any alternative way to automation test graphs?

PLEASE PLEASE HELP!

Aucun commentaire:

Enregistrer un commentaire