(Java) Conversion between Mat to IplImage or BufferedImage (Feature #3548)


Added by Ernesto Moyano about 11 years ago. Updated over 9 years ago.


Status:Open Start date:2014-02-15
Priority:Normal Due date:
Assignee:Andrey Pavlenko % Done:

0%

Category:java bindings
Target version:3.0
Difficulty:Medium Pull request:

Description

There's no function to convert the Mat type to swing compatible type. I already been working on a project that needs capture an 1920x1080 image from a webcam an display it into a swing container like a label or jpanel, but Mat type isn't compatible. So i try many ways to to this tasks but take to much time, but with this method i reduced the conversion time:

    public static BufferedImage matToBufferedImage(Mat mat) {

        if (mat.height() > 0 && mat.width() > 0) {
            BufferedImage image = new BufferedImage(mat.width(), mat.height(), BufferedImage.TYPE_3BYTE_BGR);
            WritableRaster raster = image.getRaster();
            DataBufferByte dataBuffer = (DataBufferByte) raster.getDataBuffer();
            byte[] data = dataBuffer.getData();
            mat.get(0, 0, data);
            return image;
        }

        return null;
    }

would be cool a native code for doing this task.


Associated revisions

Revision 6cb93445
Added by Vadim Pisarevsky about 10 years ago

Merge pull request #3548 from alalek:fix_sample_python

History

Updated by Kirill Kornyakov about 11 years ago

Alexander, let's look at it.

  • Status changed from New to Open
  • Assignee changed from Andrey Pavlenko to Alexander Smorkalov

Updated by Alexander Smorkalov almost 11 years ago

  • Description changed from There's no function to convert the Mat type to swing compatible type. I a... to There's no function to convert the Mat type to swing compatible type. I a... More

Updated by Alexander Smorkalov almost 11 years ago

  • Target version changed from 2.4.9 to 3.0

Updated by Andrey Pavlenko almost 11 years ago

  • Assignee changed from Alexander Smorkalov to Andrey Pavlenko

Updated by Maksim Shabunin over 9 years ago

Issue has been transferred to GitHub: https://github.com/Itseez/opencv/issues/4701

Also available in: Atom PDF