Can anyone explain the dtype parameter of OpenCV's c++ multiply [closed]

asked 2014-04-10 17:08:15 -0600

edmoney gravatar image

I have 2 matrices with contents as below

a= 

1 2 3 
4 5 6 
7 8 9 

b=

1 2 3 
4 5 6 
7 8 9

when I multiply with dtype parameter as below

Mat a = Mat(3 3 CV_8U data);
Mat b = Mat(3 3 CV_8U data);

multiply(a b dest 1.0 2);

.... I get this as result I was hoping someone could explain this to me as a noob to the multiply function but not matrix multiplication

1 0 4 
16 0 25 
49 0 64
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-11-13 04:10:51.731730

Comments

2

can't reproduce.

uchar data[] = { 1,2,3,4,5,6,7,8,9 };

Mat a = Mat(3, 3, CV_8U, data);

Mat b = Mat(3, 3, CV_8U, data);

Mat dest;

multiply(a, b, dest, 1.0, 2);

cerr << dest << endl;

[1, 4, 9;
 16, 25, 36;
 49, 64, 81]

(multiply does per-element multiplication, not matrix-wise. and dtype is the type of the result-matrix, CV_16U in your case.)

not only that your code lacks all commas, thus does not compile, i'm amazed, how on earth you produced that 'zero' column ...

well it would make some sense, if you printed out bytes (while having a ushort mat)

berak gravatar imageberak ( 2014-04-10 17:40:07 -0600 )edit

@berak Thanks for your reply, I apologize I put in a quick example, hoping for a dtype explanation. The example was just to get the ball rolling...I could just honestly use a tutorial on how to derive the dtype param...lets say I was working with 2 64 bit float Mats or 32S?. Nothing seems to be online for this, It would be great if this could be the first online resource for this ?

edmoney gravatar imageedmoney ( 2014-04-10 18:42:36 -0600 )edit
1

dtype is not something you derive, but user input. ie, you may have wanted the multiply output to be double (to achieve higher precision).

usually it's set to -1 meaning, take the src type for dst

berak gravatar imageberak ( 2014-04-11 02:02:38 -0600 )edit