Decoding a JPEG from a byte array

470 views
Skip to first unread message

David Robison

unread,
Mar 28, 2017, 7:52:12 PM3/28/17
to javacv
I'm reading a JPEG image into a byte array (byte[]). What I need to do is to decode it, resize it, and then re-encode it. I'm new to opencv and javacv. Can someone point me to where I might find some simple code to do this? I am currently doing it with ImageIO but am having issues with JPEG decoding time and want to see if javacv does a better job at decoding the JPEG in less time. Thanks, David

Samuel Audet

unread,
Mar 28, 2017, 11:48:41 PM3/28/17
to jav...@googlegroups.com

David Robison

unread,
Mar 29, 2017, 8:44:14 AM3/29/17
to javacv
Thanks, this helps. One thing I haven't figured out yet is how to take my JPEG that is in a byte array (byte[]) and create a Mat object that I can then send to the imdecode routine? David

Samuel Audet

unread,
Mar 29, 2017, 10:21:29 AM3/29/17
to jav...@googlegroups.com
Just call `new Mat(byte[])`, that will do what we need it to do.

Samuel

David Robison

unread,
Mar 29, 2017, 11:31:16 AM3/29/17
to javacv
Thanks. If there is an error in imdecode such that it returns mat::data == null, is there a way to retrieve what error was seen? David

Samuel Audet

unread,
Mar 29, 2017, 11:23:32 PM3/29/17
to jav...@googlegroups.com
It might return an exception, but not according to the docs:
http://docs.opencv.org/trunk/d4/da8/group__imgcodecs.html#ga26a67788faa58ade337f8d28ba0eb19e
Reply all
Reply to author
Forward
0 new messages