← Back to team overview

sikuli-driver team mailing list archive

[Bug 1318624] Re: TextRecognizer using transformed capture still give the same results as original image

 

Ok, looks groovy ;-)

I understand:
You want to use some low level OCR functions on a BufferedImage, that you provide.

Since I cannot really see, what you are doing in detail, I give you the
code used in SikuliX

*** to get a CV::Mat from a Buffered Image:

  protected static org.sikuli.natives.Mat convertBufferedImageToMat(BufferedImage img) {
    if (img != null) {
      byte[] data = convertBufferedImageToByteArray(img);
      return Vision.createMat(img.getHeight(), img.getWidth(), data);
    } else {
      return null;
    }
  }

  protected static byte[] convertBufferedImageToByteArray(BufferedImage img) {
    if (img != null) {
      BufferedImage cvImg = createBufferedImage(img.getWidth(), img.getHeight());
      Graphics2D g = cvImg.createGraphics();
      g.drawImage(img, 0, 0, null);
      g.dispose();
      return ((DataBufferByte) cvImg.getRaster().getDataBuffer()).getData();
    } else {
      return null;
    }
  }

  protected static BufferedImage createBufferedImage(int w, int h) {
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    int[] nBits = {8, 8, 8, 8};
    ColorModel cm = new ComponentColorModel(cs, nBits, true, false, Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE);
    SampleModel sm = cm.createCompatibleSampleModel(w, h);
    DataBufferByte db = new DataBufferByte(w * h * 4);
    WritableRaster r = WritableRaster.createWritableRaster(sm, db, new Point(0, 0));
    BufferedImage bm = new BufferedImage(cm, r, false, null);
    return bm;
  }

The created CV::Mat in turn can be used, to call the respective OCR
functions:

(fom TextRecognizer.listText)

OCRWords words = Vision.recognize_as_ocrtext(mat).getWords();

where mat is the CV::Mat created as mentioned above.

-- 
You received this bug notification because you are a member of Sikuli
Drivers, which is subscribed to Sikuli.
https://bugs.launchpad.net/bugs/1318624

Title:
  TextRecognizer using transformed capture still give the same results
  as original image

Status in Sikuli:
  Incomplete

Bug description:
  Hi,
  I tryed using TextRecognizer listText(ScreenImage simg, Region parent) method passing a newly created ScreenImage that I produce bynarizing the original screen capture so I can read easily a complex image, but the resulting List of Match classes give the same results that are obtained using the original ScreenImage. It seems this method uses the Region instead of the ScreenImage as source for the OCR

To manage notifications about this bug go to:
https://bugs.launchpad.net/sikuli/+bug/1318624/+subscriptions


References