(Java) Conversion between Mat to IplImage or BufferedImage (Feature #3548)
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
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