Ask Your Question
1

Java/Android access 4-Dim Mat planes

asked 2017-10-04 03:44:28 -0600

SchranzDampf gravatar image

I am building an Android App with uses the DNN module.

The output of the forward pass is a Mat with dims() = 4.

Actually its the output of semantic segmentation (ENet Example) with 1x8x45x80.

mat.total() = 28800 which is also correct.

The problem is that i cannot access the data of this mat with get(0,0,floatbuffer), as cols=-1 and rows=-1 which is normal for dim>2.

Is there any other way? In the end i would like to have 8 Mats (or 8 simple float-arrays) for each plane.

Best Regards

edit retag flag offensive close merge delete

Comments

can you show your code, attempting this ?

berak gravatar imageberak ( 2017-10-04 03:46:46 -0600 )edit

System.out.println(oBlob);

    Mat result = network.forward(oBlob);
    assertNotNull("Net returned no result!", result);

    System.out.println("Elements: " + result.total());

    float data[] = new float[(int)result.total()];

    System.out.println("Extracted elems:" + result.get(0, 0, data));

The output is: I/System.out: l301_Convolution

I/System.out: Elements: 28800

I/System.out: Extracted elems:0

SchranzDampf gravatar imageSchranzDampf ( 2017-10-04 03:53:28 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-10-04 04:18:10 -0600

berak gravatar image

updated 2017-10-04 04:27:33 -0600

you can try to reshape() your 4d blob to a 2d one.

Mat m2 = oBlob.reshape(1, 8 * 80); // assuming W=45, H=80, and C=8

this should result in a Mat with 1 channel, 45 cols and 8*80 rows. (8 planes, stacked on top of each other)

you can now access a single plane easily using submat:

// 2nd plane:
Mat m = m2.submat(80,80+80, 0,45);
edit flag offensive delete link more

Comments

2

that works perfect! Thank you!

SchranzDampf gravatar imageSchranzDampf ( 2017-10-04 07:09:56 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2017-10-04 03:43:08 -0600

Seen: 871 times

Last updated: Oct 04 '17