Matrix (Mat) operations with OpenCV 2.3.1 for Android

1,642 views
Skip to first unread message

Ben A.

unread,
Sep 6, 2011, 7:55:12 AM9/6/11
to android-opencv
Hi everyone,

I'm stuck with a very stupid problem : I can't multiply (nor
add,subtract...) Mat data in OpenCV Android. The only method I found
is Mat.mul which performs element-wise multiplication but no real
matrix multiplication.

This method's documentation says : "Note that this is not a matrix
multiplication that corresponds to a simpler "*" operator." Tried it,
but seems that "*" and "+" operators are undefined (or so says my
Eclipse IDE...).

There must be something I didn't configure well, but what ?

Please help me !

Andrey Pavlenko

unread,
Sep 6, 2011, 8:00:47 AM9/6/11
to android-opencv
Look at the following methods:
org.opencv.core.Core.gemm();
org.opencv.core.Core.add();
org.opencv.core.Core.subtract();
org.opencv.core.Core.multiply();

Benjamin Ahsan

unread,
Sep 6, 2011, 9:19:38 AM9/6/11
to android...@googlegroups.com
Thanks a lot ! I don't know how I missed that...

2011/9/6 Andrey Pavlenko <andrey....@itseez.com>

Huidong Bai

unread,
Apr 15, 2012, 1:56:05 AM4/15/12
to android...@googlegroups.com
Which method works?

I tried gemm() and it does not work at all.

Rui Marques

unread,
Apr 15, 2012, 7:26:33 AM4/15/12
to android...@googlegroups.com
What error do you have for gemm() not working?

Huidong Bai

unread,
Apr 16, 2012, 12:51:49 AM4/16/12
to android...@googlegroups.com

I cannot get the error info ...

When I comment the gemm(), the app works well on the cellphone.

However, the app will crash without commenting the gemm() when it runs to the gemm() line.

The wired part is that all these codes are completely OK on PC.

Any idea? Thanks.


在 2012年4月15日星期日UTC+12下午11时26分33秒,Rui Marques写道:

peppschmier

unread,
Apr 18, 2012, 2:40:22 AM4/18/12
to android...@googlegroups.com
gemm(matSrc1, matSrc2, 1, new Mat(), 0, matDest);
 
does the multiplication for me. matSrc1 and matSrc2 must have the right rows and cols, otherwise it will fail.

Andrey Pavlenko

unread,
Apr 18, 2012, 10:48:42 AM4/18/12
to android...@googlegroups.com
use logcat to get error info

Huidong Bai

unread,
Apr 22, 2012, 8:54:17 PM4/22/12
to android...@googlegroups.com

Problem is solved. I googled the gemm() and found this page:

http://www.bytefish.de/wiki/opencv/code_snippets

There are some code snippets for gemm() usage, and I realized that two cv::mat should not only be the same size but also the exactly same data type. I checked my code and found one mat is CV_32FC1, and another one is CV_64FC1, although this works on PC, but for mobile devices, the system may have stricter requirement. After I changed the two mats to the same type, the app worked again.

Cheers!


在 2012年4月18日星期三UTC+12下午6时40分22秒,peppschmier写道:
Reply all
Reply to author
Forward
0 new messages