Ask Your Question
0

4 dimensional Mat in opencv JAVA

asked 2018-10-13 13:11:23 -0600

Sid24 gravatar image

updated 2018-10-14 02:07:00 -0600

I want to create a 4D Mat with dimensions 1x625x1x1 . Specifically I have a 625x1 Mat with zeros and ones. My caffemodel has an input of dimension 1x625x1x1 as given in the .prototxt file. So I want to reshape the 625x1 Mat to 1x625x1x1 blob to be passed as input.

Or suggest a way to create a 1x625x1x1 Mat and fill it with zeros and ones using a loop.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-10-14 01:54:03 -0600

berak gravatar image

please use Dnn.blobFromImage to convert it

edit flag offensive delete link more

Comments

Dnn.blobFromImage will take in as input a 625x1 Mat and output 1x1x625x1 not 1x625x1x1.

Sid24 gravatar imageSid24 ( 2018-10-14 01:59:39 -0600 )edit
1

That is the whole problem. The second dimension is number of channels. blobFromImage can output only 1(for gray scale image) or 3 channels(for RGB image) not 625.

Sid24 gravatar imageSid24 ( 2018-10-14 02:00:42 -0600 )edit

so, please edit your question, describe, how you get to that (very weird) format and let's see again ?

berak gravatar imageberak ( 2018-10-14 02:02:35 -0600 )edit
1

So what I thought was that maybe I can make a 4D Mat myself and pass it as input to caffemodel. But I don't know how to create and operate upon a 4D Mat. It can be done in C++ opencv. But there is no constructor in Java for a multidimensional Mat

Sid24 gravatar imageSid24 ( 2018-10-14 02:04:04 -0600 )edit

That wierd 1x625x1x1 format is the dimension of an input blob as given in the .prototxt file.

Sid24 gravatar imageSid24 ( 2018-10-14 02:07:58 -0600 )edit
1

https://github.com/CSAILVision/GazeCa...

Check the input called "facegrid" in this file

Sid24 gravatar imageSid24 ( 2018-10-14 02:08:49 -0600 )edit

yea, true. being restricted to java is somewhat unfortunate here.

but again it's unclear, how you got that data into a Mat (please show us !)

maybe something can be done, using reshape

forget the latter, opencv is limited to 512 possible channels

berak gravatar imageberak ( 2018-10-14 02:10:21 -0600 )edit
1

The facegrid input of the model is made like this: You have a 25x25 image of a person with a 12x12 bounding box around the face. You declare a 25x25 Mat object and fill it with ones wherever there is a face(inside the bounding box) and zeros wherever there is no face. So the 25x25 Mat will have ones inside the bounding box and zeros everywhere else. The you flatten the Mat to 625x1.

Sid24 gravatar imageSid24 ( 2018-10-14 02:16:49 -0600 )edit
1
Sid24 gravatar imageSid24 ( 2018-10-14 02:22:12 -0600 )edit

One more thing, can we make 1x1x1 Mat objects and then use merge to stack 625 of such objects?

Sid24 gravatar imageSid24 ( 2018-10-14 02:23:36 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-10-13 13:11:23 -0600

Seen: 1,011 times

Last updated: Oct 14 '18