Possible bug in matrix multiplication (arithm.cpp) (Bug #1728)
Description
I'm trying do the following function, using Android's Opencv revision 7644.
The function is far from perfect but I don't think the problem is with my code so here is the report.
//img and proj are supposed to be lists with 4 points each. private void getImagetoProjectionMapping(List<Point> img, List<Point> proj) { if(img.size()>=4 && proj.size()>=4) { Mat mA = new Mat(2, 9, CvType.CV_32FC1); Mat mB = Mat.zeros(mA.size(), mA.type()); double[] data0, data1; double X, Y, a, b; for(int i = 0; i<img.size() && i<proj.size(); i++) { X = img.get(i).x; Y = img.get(i).y; a = proj.get(i).x; b = proj.get(i).y; data0 = new double[] {X, Y, 1, 0, 0, 0, -(X*a), -(Y*a), -a}; data1 = new double[] {0, 0, 0, X, Y, 1, -(X*b), -(Y*b), -b}; mA.put(0, 0, data0); mA.put(1, 0, data1); // mB += mA.t * mA Core.add(mB, mA.mul(mA.t()), mB); } } }
I get the following error:
03-29 18:01:06.992: E/AndroidRuntime(14565): CvException [org.opencv.core.CvException: /home/rd/rui.marques/opencv-trunk-src/opencv/modules/core/src/arithm.cpp:1244: error: (-209) The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array' in function void cv::arithm_op(const cv::_InputArray&, const cv::_InputArray&, const cv::_OutputArray&, const cv::_InputArray&, int, void (**)(const uchar*, size_t, const uchar*, size_t, uchar*, size_t, cv::Size, void*), bool, void*) 03-29 18:01:06.992: E/AndroidRuntime(14565): ] 03-29 18:01:06.992: E/AndroidRuntime(14565): at org.opencv.core.Mat.n_mul(Native Method) 03-29 18:01:06.992: E/AndroidRuntime(14565): at org.opencv.core.Mat.mul(Mat.java:1310) 03-29 18:01:06.992: E/AndroidRuntime(14565): at org.opencv.rmarques.project.ImageManipulationsView.getImagetoProjectionMapping(ImageManipulationsView.java:1355)
The sizes, as printed by mA.size(), mA.t().size():
mA.size() = 9x2
mA.t().size() = 2x9
The sizes are indeed different but these matrices should be able to multiply.
Maybe, for multiplication operation, you can add a special case.
Instead of testing "src1.size() == src2.size()" you test "src1.cols == src2.rows && src1.rows == src2.cols", etc, you get the idea.
Associated revisions
Merge pull request #1728 from apavlenko:refactor_vcap_jni
History
Updated by Andrey Kamaev almost 13 years ago
Mat.mul
does per-element multiplication. For true matrix multiplication you should use Core.gemm
- Status changed from Open to Cancelled
- Target version set to 2.4.0
- Assignee set to Andrey Kamaev