Ask Your Question
0

blobFromImage is giving wrong value.

asked 2019-04-21 02:04:56 -0600

iamM gravatar image

updated 2019-04-21 02:14:55 -0600

berak gravatar image

Hi @dkurt i am creating 4-dimensional blob from image cv::dnn::blobFromImage() function but it is giving rows = -1, cols = -1 and data = " ". i am using simple code as shown below.

Mat inImage = imread("A_1.ppm", 1);
Mat rgbImage;
cvtColor(inImage, rgbImage, COLOR_BGRA2RGB );
Mat 4DImage = dnn::blobFromImage (rgbImage, 1.0, Size(rgbImage.rows, rgbImage.cols), Scalar(0, 0, 0), false, false);

return 0;
edit retag flag offensive close merge delete

Comments

can you look at your broken code above again, and try to repair it ?

(so folks can try to repeat the problem ?)

berak gravatar imageberak ( 2019-04-21 02:09:41 -0600 )edit
1

Sorry @berak now i corrected.

iamM gravatar imageiamM ( 2019-04-21 02:13:27 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-04-21 02:33:27 -0600

berak gravatar image

updated 2019-04-21 02:42:27 -0600

first, your cvtColor call is useless, beacuse ppm's can have at most 3 channels, and you're reading it as bgr.

then, you got rows and cols wrong in Size(rgbImage.rows, rgbImage.cols)

and last, for a multi-dimensional Mat you cannot use rows and cols, those apply only in a 2d world. use Mat::size instead:

int N = blob.size[0], C = blob.size[1], H = blob.size[2], W = blob.size[3];

there's also an operator for printing:

cout << blob.size << endl; // NO () !
edit flag offensive delete link more

Comments

Thank you @berak i understood but blob.data = " " is coming empty.

iamM gravatar imageiamM ( 2019-04-21 02:48:12 -0600 )edit

that might be just a few "black" pixels

berak gravatar imageberak ( 2019-04-21 05:17:25 -0600 )edit

Hi @berak all fine, but I am getting blob.size = 1 x 3 64 x 64 format. But Tensrflow module accepts in form of 1 x 64 x64 x 3 means in NWHC can we do something to change access?

iamM gravatar imageiamM ( 2019-04-22 00:02:21 -0600 )edit

opencv's dnn needs NCHW order (wherever the model comes from), so that's ok.

i doubt, that you try to access tf from c++, and then it's more likely a python/numpy qurestion, not a opencv one.

berak gravatar imageberak ( 2019-04-22 02:11:41 -0600 )edit

@my_opencv, From the docs:

the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions

source: https://docs.opencv.org/master/d3/d63...

But Tensrflow module accepts in form of 1 x 64 x64 x 3 means in NWHC can we do something to change access?

OpenCV works in NCHW for any model. Just put the output of blobFromImage to network and enjoy. See the samples: https://github.com/opencv/opencv/tree...

dkurt gravatar imagedkurt ( 2019-04-22 02:15:57 -0600 )edit

@berak and @dkurt, basically i am deploying a tensflow model in C++ using tvm, so this TF model accepting input as NWHC form.

iamM gravatar imageiamM ( 2019-04-22 02:43:08 -0600 )edit

i am deploying a tensflow model in C++ using tvm

just saying, why ask on opencv, then ?

berak gravatar imageberak ( 2019-04-22 02:46:01 -0600 )edit
1

Where is my favorite :confused: emojis from GitHub when it's so actual :)

dkurt gravatar imagedkurt ( 2019-04-22 03:10:34 -0600 )edit

Sorry, @dkurt I changed it.

iamM gravatar imageiamM ( 2019-04-23 22:47:14 -0600 )edit

Hi @dkurt, @berak how to create 4 dims array using CvMatND, I have to create an array for (1 x 64 x 64 x 3) matrix.

iamM gravatar imageiamM ( 2019-04-24 06:50:41 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-04-21 02:04:56 -0600

Seen: 2,291 times

Last updated: Apr 21 '19