Ask Your Question
2

Product of two matrices

asked 2013-04-04 17:04:56 -0500

Dominik gravatar image

Hi,

I use OpenCV 2.4.4 with Java. I have problem with simple multiplication of two matrices. I define it in my code in following way:

Mat m1 = Mat.ones(3, 3, CvType.CV_16SC1);

Mat m2 = Mat.ones(3, 3, CvType.CV_16SC1);

In case if I multiply:

Mat m3 = m1 * m2;

I achieved error that operator * is undefined.

I know that OpenCv for Java provides function mul and i can use it:

Mat m3 = m1.mul(m2);

but in this way I receive only product of elementwise multiplication what is not my objective.

Is there some replacement function which allow me to multiply two matrices like * operator?

Thanks in advance :)

edit retag flag offensive close merge delete

Comments

1

i think you need float mat's for this

berak gravatar imageberak ( 2013-04-05 01:28:25 -0500 )edit

Hi, When I define my matrix like: Mat m1 = Mat.ones(3, 3, CvType.CV_32FC1); I achieved error that I am not able to use operator * too. There have to be another way to solve it...

Dominik gravatar imageDominik ( 2013-04-05 02:31:40 -0500 )edit

Thank You berek for interest of my problem. The problem was with CvType and used gemm function. Tomorrow I will present final solution, today I am not able because of some rules of forum.

Dominik gravatar imageDominik ( 2013-04-05 04:27:57 -0500 )edit

2 answers

Sort by ยป oldest newest most voted
1

answered 2013-04-08 10:59:43 -0500

Dominik gravatar image

Ok, below I present solution of my problem:

Mat m1 = Mat.zeros(3, 3, CvType.CV_32F);

Mat m2 = Mat.ones(3, 3, CvType.CV_32F);

Mat m3 = Mat.ones(3, 3, CvType.CV_32F);

Core.gemm(m2, m3, 1, new Mat(), 0, m1, 0);

My problem was connected with wrong type used in declaration of matrices and to multiply them we can use gemm function as it is presented above.

Thanks for help:)

edit flag offensive delete link more

Comments

Glad to hear that you resolved your issue.

Guanta gravatar imageGuanta ( 2013-04-08 12:56:23 -0500 )edit

Thanks Dominik for the solution. Solved my issue as well.

Anuj Potnis gravatar imageAnuj Potnis ( 2014-01-20 20:26:03 -0500 )edit
3

answered 2013-04-04 17:22:08 -0500

Guanta gravatar image

updated 2013-04-08 12:54:31 -0500

edit flag offensive delete link more

Comments

Hi, Yes, I have to use gemm function like this:

Core.gemm(m2, m3, 1,null, 0, m1,0);

But after that I achieved error: Exception in thread "main" java.lang.NullPointerException at org.opencv.core.Core.gemm(Core.java:3647)

Any suggestion how can I solve that?

Dominik gravatar imageDominik ( 2013-04-05 02:28:55 -0500 )edit

oh, sorry, i can only speak of c++ . but i looked up gemm, and both m2 and m3 must be float types. also, you probably have to supply a valid result Mat there, too (the null pointer)

berak gravatar imageberak ( 2013-04-05 02:46:29 -0500 )edit
2

Thank You Guanta for interest of my problem. The problem was with CvType and used gemm function. Tomorrow I will present final solution, today I am not able because of some rules of forum.

Dominik gravatar imageDominik ( 2013-04-05 04:28:38 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-04-04 17:04:56 -0500

Seen: 10,683 times

Last updated: Apr 08 '13