meghasen / javacv

Automatically exported from code.google.com/p/javacv
0 stars 0 forks source link

Converting java.awt.image to IplImage #2

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi,
Is there a performant method to convert a java.awt.image or an array of
floats or int to an IplImage?
I tried set2D, but it's slow, like 7 seconds for 200x200 on 2GHz.

Original issue reported on code.google.com by markus.l...@gmail.com on 20 Apr 2010 at 3:58

GoogleCodeExporter commented 8 years ago
This can be done in the usual Java way, by first copying the Image object into a
BufferedImage, and then copying that into an IplImage. Although copying is 
efficient,
it still involves two copies, but that's the best that can done. For example, 
given
an Image object "image", this should work:

BufferedImage bufferedImage = new BufferedImage(image.getWidth(null),
image.getHeight(null), BufferedImage.TYPE_3BYTE_BGR /* or whatever type you 
like */);
Graphics g = bufferedImage.getGraphics();
g.drawImage(image, 0, 0, null);
g.dispose();
IplImage iplImage = IplImage.createFrom(bufferedImage);

Original comment by samuel.a...@gmail.com on 21 Apr 2010 at 4:41