Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert IplImage to lept.PIX

Tags:

I develop OCR system based on JavaCV.

I use following libraries for my project:

  • https://github.com/bytedeco/javacv
  • https://github.com/bytedeco/javacpp-presets/tree/master/tesseract

In one case I need to find some part of an image and recognize letters on it.

I store a part of an image in IplImage type.

But for Tesseract I must use PIX format.

How can I convert IplImage to Pix ?

like image 720
Gorcer Avatar asked Apr 28 '16 14:04

Gorcer


2 Answers

Posting the hack like solution found by the author of the question. It can also be found here.

IplImage prepareImg = ...
cvSaveImage("plate.jpg", prepareImg);               
PIX pixImage = pixRead("/plate.jpg");

And from this question, you can convert IplImage to BufferedImage as follows.

public static BufferedImage toBufferedImage(IplImage src) {
  OpenCVFrameConverter.ToIplImage iplConverter = new OpenCVFrameConverter.ToIplImage();
  Java2DFrameConverter bimConverter = new Java2DFrameConverter();
  Frame frame = iplConverter.convert(src);
  BufferedImage img = bimConverter. convert(frame);
  BufferedImage result = (BufferedImage)img.getScaledInstance(
      img.getWidth(), img.getHeight(), java.awt.Image.SCALE_DEFAULT);  
  img.flush();
  return result;
}
like image 177
Rajind Ruparathna Avatar answered Sep 28 '22 03:09

Rajind Ruparathna


IplImage prepareImg = ...
cvSaveImage("test.jpg", prepareImg);               
PIX pixImage = pixRead("/test.jpg");

--- Source : Same Github issues As mentioned by a comment by rajind ruparathna

like image 29
c0degeas Avatar answered Sep 28 '22 01:09

c0degeas