Ask Your Question

Some functions of opencv showing error on some specific scenerio

asked 2014-03-26 02:52:27 -0500

FLY gravatar image

updated 2014-08-30 08:55:31 -0500

I am using opencv with android , for that I just try my code first on visual studio with opencv , it works fine on it and then I put it on android, but something is confusing in understanding function and their cause of error like in for example the simple program


    vector<Mat> channel; 

    Mat mask = image.clone();            // clone function work fine
    //Mat mask = channel[3].clone();     // clone function show me error         

  //  channel.resize(3);  // show error

    Mat it;


When I use Mat mask = channel[3].clone(); It show me error of Method 'clone' could not be resolved but when I use Mat mask = image.clone(); it works fine. Why is that ?

Same when I use channel.resize(3); it show me error in resize function , error is Invalid arguments 'Candidates are: void resize(?, cv::Mat)'.

and when I move on to multiply function it show me error of Invalid arguments ' Candidates are: void multiply(const cv::_InputArray &, const cv::_InputArray &, const cv::_OutputArray&, double, int)' .

Though these all function are working in visual studio using opencv and they are also working in android when using on different scenario's .

I am working on native environment using eclipse with opencv android version of 2.4.8.

multiply and clone alternate work for me as i tried the code below , but don't know how to merge it

        Mat alpha1 = ch[3];
        Mat alpha =  alpha1.clone();

        Mat I1;
        vector<Mat> ch0 = ch[0];
        vector<Mat> ch1 = ch[1];
        vector<Mat> ch2 = ch[2];
//      I1 = alpha1.mul(ch0);
//      I1 = alpha1.mul(ch1);
//      I1 = alpha1.mul(ch2);
        multiply(alpha, ch0, ch0);
        multiply(alpha, ch1, ch1);
        multiply(alpha, ch2, ch2);
        merge(ch, I1);
edit retag flag offensive close merge delete


Try changing the converto functions to use a clone of the original data. I am not sure if this operator is a safe inplace operator.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-08-27 08:02:58 -0500 )edit

clone is not working in android ndk , but i tried the above as `void Vite(Mat& img1, Mat& img2, Mat& out)



out=img1+img2; }`

But still the same output

FLY gravatar imageFLY ( 2014-08-27 08:37:06 -0500 )edit

Hmm .clone() is a C++ function thus should work right? What error is that one giving you?

StevenPuttemans gravatar imageStevenPuttemans ( 2014-08-27 08:53:18 -0500 )edit

Sorry I deleted my comment , because your comment is valid about .clone() but I didn't explain it well accordingly , lemme edit my question and change it in the way you comment , I can get better answer out of it and can solve my problem easily and quickly

FLY gravatar imageFLY ( 2014-08-28 16:01:34 -0500 )edit

Hmm it seems that the wrapping to android is somewhere failing. To solve the first problem, I think by first assigning channel[3] to a temp Mat element and then calling .clone() on that temporary element should fix the problem, though creating a small overhead. As to the multiply I have no idea why this is happening.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-08-29 02:16:45 -0500 )edit

clone work with alternate way and multiply work for me too but need to create different vector<Mat> everytime (i think there is some index problem with ndk) but don't know how to merge it with the image matrix

FLY gravatar imageFLY ( 2014-08-30 08:57:56 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2014-09-15 15:50:44 -0500

FLY gravatar image

I thing which I got to know and learn about such scenario is that opencv with android have vector indexing error when using with jni , you there are some alternative methods which we can try :

for clone as mention by @StevenPuttemans we need to create temporary Mat like instead of using

Mat x = ch[3].clone();

we can use it like

Mat x = ch[3];
Mat y =  x.clone();

Now move on for multiply channels , as there is indexing error in opencv when using with ndk , you can create Mat and use multiply function with like :

Mat ch0 = ch[0];
Mat ch1 = ch[1];
Mat ch2 = ch[2];

multiply(y, ch0, ch0);
multiply(y, ch1, ch1);
multiply(y, ch2, ch2);

vector<Mat> xx;

merge(x, image);
edit flag offensive delete link more
Login/Signup to Answer

Question Tools


Asked: 2014-03-26 02:52:27 -0500

Seen: 1,661 times

Last updated: Sep 15 '14