Ask Your Question
0

java opencv imdecode returns empty Mat!

asked 2017-03-29 00:55:56 -0600

Leman gravatar image

updated 2020-11-07 03:17:00 -0600

Hello everoyone!

I spent 2 days looking for answers on the Internet but no luck still. My problem is imdecode returns an empty Mat and I'm not sure what is the problem. Below is my code and the debug output:

Byte data[] = ...;
...
Mat compressed_frame = new Mat(1, size, CvType.CV_8UC1);
compressed_frame.put(0, 0, data);

Mat frame = new Mat();
Mat frame1 = new Mat();
frame = Imgcodecs.imdecode(new MatOfByte(data), Imgcodecs.CV_LOAD_IMAGE_COLOR).clone();
frame1 = Imgcodecs.imdecode(compressed_frame, Imgcodecs.CV_LOAD_IMAGE_COLOR).clone();

System.out.println(compressed_frame);
System.out.println(frame);
System.out.println(frame1);

OUTPUTS of println:
Mat [ 1*72643*CV_8UC1, isCont=true, isSubmat=false, nativeObj=0x225551d0, dataAddr=0x225fd6e0 ]
Mat [ 0*0*CV_8UC1, isCont=true, isSubmat=false, nativeObj=0x225550f0, dataAddr=0x0 ]
Mat [ 0*0*CV_8UC1, isCont=true, isSubmat=false, nativeObj=0x22555940, dataAddr=0x0 ]

I tried both methods I could find to decode the compressed_frame but none works. Please help! BTW I use Opencv 3.2.0!

edit retag flag offensive close merge delete

Comments

what is inside "data" ? maybe that's not a valid image ? how do you acquire it ?

berak gravatar imageberak ( 2017-03-29 01:00:05 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-03-29 01:59:00 -0600

Leman gravatar image

Thanks for your hint. I had it working. "data" contains compressed Mat.data sent from a c++ server. I made a mistake to reverse the byte order in "data" because c++ and java store byte differently, but it does not matter in this case. Consider this problem solved. Thanks again!

edit flag offensive delete link more

Comments

Hi there. I am having the same issue under the same circumstances you mentioned above. I haven't changed the byte ordered at all from big endian to little endian. Any suggestions?

kwendt94 gravatar imagekwendt94 ( 2018-07-05 20:51:49 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-03-29 00:55:56 -0600

Seen: 1,452 times

Last updated: Mar 29 '17