Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

there is no bug here, you're only looking at the wrong variables

(rows and cols can only hold 2 dimensions, so they are not used here, and set to -1).

the dimensions for the dnn blob Mat's are in:

mat.dims();  // blob's dimensions
mat.size(0); // how many images in the blob
mat.size(1); // how many "channels" or "planes"
mat.size(2); // height
mat.size(3); // width

there is no bug here, you're only looking at the wrong variables

(rows and cols can only hold 2 dimensions, so they are not used here, and set to -1).

the dimensions for the dnn blob Mat's are in:

mat.dims();  // blob's dimensions
mat.size(0); // how many images in the blob
mat.size(1); // how many "channels" or "planes"
mat.size(2); // height
mat.size(3); // width

i don't have your data, so i cannot try, but if the network output from the python version is (1,3,480,700) , it means, there are 3 seperate color channels in it. so,

int H = result.size(2);
int W = result.size(3);

// step 1: reshape it to a long vertical strip:
Mat strip = result.reshape(1, H * 3);

// step 2: collect the color planes into a list:
List<Mat> lis = new ArrayList<>();

lis.add(strip.submat(0,H, 0,W));
lis.add(strip.submat(H,2*H, 0,W));
lis.add(strip.submat(2*H,3*H, 0,W));

// step 3: merge planes intop final image
Mat final = new Mat();
Core.merge(lis, final);

there is no bug here, you're only looking at the wrong variables

(rows and cols can only hold 2 dimensions, so they are not used here, and set to -1).

the dimensions for the dnn blob Mat's are in:

mat.dims();  // blob's dimensions
mat.size(0); // how many images in the blob
mat.size(1); // how many "channels" or "planes"
mat.size(2); // height
mat.size(3); // width

i don't have your data, so i cannot try, but if the network output from the python version is (1,3,480,700) , it means, there are 3 seperate color channels in it. so,

int H = result.size(2);
int W = result.size(3);

// step 1: reshape it to a long vertical strip:
Mat strip = result.reshape(1, H * 3);

// step 2: collect the color planes into a list:
List<Mat> lis = new ArrayList<>();

lis.add(strip.submat(0,H, 0,W));
lis.add(strip.submat(H,2*H, 0,W));
lis.add(strip.submat(2*H,3*H, 0,W));

// step 3: merge planes intop into final image
Mat final = new Mat();
Core.merge(lis, final);

there is no bug here, you're only looking at the wrong variables

(rows and cols can only hold 2 dimensions, so they are not used here, and set to -1).

the dimensions for the dnn blob Mat's are in:

mat.dims();  // blob's dimensions
mat.size(0); // how many images in the blob
mat.size(1); // how many "channels" or "planes"
mat.size(2); // height
mat.size(3); // width

i don't have your data, so i cannot try, but if the network output from the python version is (1,3,480,700) , it means, there are 3 seperate color channels in it. so,

int H = result.size(2);
int W = result.size(3);

// step 1: reshape it to a long vertical strip:
Mat strip = result.reshape(1, H * 3);

// step 2: collect the color planes into a list:
List<Mat> lis = new ArrayList<>();
 lis.add(strip.submat(0,H, 0,W));
lis.add(strip.submat(H,2*H, 0,W));
lis.add(strip.submat(2*H,3*H, 0,W));

// step 3: merge planes into final image
Mat final = new Mat();
Core.merge(lis, final);

there is no bug here, you're only looking at the wrong variables

(rows and cols can only hold 2 dimensions, so they are not used here, and set to -1).

the dimensions for the dnn blob Mat's are in:

mat.dims();  // blob's dimensions
mat.size(0); // how many images in the blob
mat.size(1); // how many "channels" or "planes"
mat.size(2); // height
mat.size(3); // width

i don't have your data, so i cannot try, but if the network output from the python version is (1,3,480,700) , it means, there are 3 seperate color channels in it. so,

Mat result = net.forward();

int H = result.size(2);
int W = result.size(3);

// step 1: reshape it to a long vertical strip:
Mat strip = result.reshape(1, H * 3);

// step 2: collect the color planes into a list:
List<Mat> lis = new ArrayList<>();
lis.add(strip.submat(0,H, 0,W));
lis.add(strip.submat(H,2*H, 0,W));
lis.add(strip.submat(2*H,3*H, 0,W));

// step 3: merge planes into final bgr image
Mat final bgr = new Mat();
Core.merge(lis, final);
bgr);

// last: add the mean value
Core.add(bgr, new Scalar(103.939, 116.779, 123.680), bgr);