View Single Post
  #6   Spotlight this post!  
Unread 29-01-2015, 21:02
MatthewC529 MatthewC529 is offline
Lcom/mattc/halp;
AKA: Matthew
FRC #1554 (Oceanside Sailors)
Team Role: Mentor
 
Join Date: Feb 2014
Rookie Year: 2013
Location: New York
Posts: 39
MatthewC529 is on a distinguished road
Re: OpenCV USBCamera convert to Mat

I don't believe this is the typical way of converting a Mat to a BufferedImage. From my experience it is much similar to use MatOfByte:

Code:
// Lots of code...

Mat mat = getSomeImageMat();
MatOfByte bytes = new MatOfByte();

Highgui.imencode(someFormat, mat, bytes);

byte[] arr = bytes.toArray();
ByteArrayInputStream bis = new ByteArrayInputStream(arr);

BufferedImage img = ImageIO.read(bis);

// Even more code...
// Exceptions and Stream Closing omitted for brevity
This is what I have seen typically used. It's much simpler.

(I noticed you used this algorithm, but I will leave it here for future reference)
http://stackoverflow.com/questions/1...-mat-in-opencv

Is there some limitation where you can't use MatOfByte?
__________________
Team 1554 -- Oceanside Sailors
  • 2013-2014 - Lead/Sole Programmer
  • 2014-2015 - Lead Programmer, President
  • 2015-? - Team 1554 Mentor
Independent Public Projects

Developer at Legend Zero LLC.
Java/C++ Programmer

Last edited by MatthewC529 : 29-01-2015 at 21:25. Reason: Me Being Overzealous with Solutions :)