Pointer to image problem

asked 2016-12-10 05:55:33 -0600

greenworld gravatar image

Dear everyone, I faced with an error when using below code:

void init(Mat *mF) {
Mat mm = (Mat_<float>(4, 4) << 1, 1, 1, 2,
    2, 1, 0, 1,
    1, 0, 2, 1,
    3, 0, 0, 1);
*mF = mm;

}

The error opened below line:

inline void Mat::release(){
if( u && CV_XADD(&u->refcount, -1) == 1 )
    deallocate();
u = NULL;
datastart = dataend = datalimit = data = 0;
for(int i = 0; i < dims; i++)
    size.p[i] = 0;

} Please helpt o explain, and how I can correct it.

edit retag flag offensive close merge delete

Comments

please use references, not pointers here.

berak gravatar imageberak ( 2016-12-10 09:53:28 -0600 )edit

I want to update a Mat (small size), my idea is: pass a Mat pointer and its values to a function, then the Mat will be updated. How I can do that in a good way? Thank you!

greenworld gravatar imagegreenworld ( 2016-12-10 20:10:33 -0600 )edit

@berak did you delete your answer?

sturkmen gravatar imagesturkmen ( 2016-12-11 06:01:48 -0600 )edit

@sturkmen, indeed ! (got some thingswrong there)

berak gravatar imageberak ( 2016-12-11 06:07:35 -0600 )edit

just wonder what was the wrong?

sturkmen gravatar imagesturkmen ( 2016-12-11 06:39:08 -0600 )edit

Yes I have test program I think it's OK if you do something like this :

int main(int argc, char** argv) {

    Mat x;

    init(&x);
    cout<<x<<"\n";
return 0;
}

of course not like this :

   int main(int argc, char** argv) {

        Mat *x;

        init(x);
        cout<<*x<<"\n";
    return 0;
    }
LBerger gravatar imageLBerger ( 2016-12-11 08:42:22 -0600 )edit