1

In openCV code sapmles in it's document, I saw they simply pass the Mat as a refrence and fill it.
But I have a problem in my code. when i call TestMethod, it doese not fill them.

void TestMethod(Mat a, Mat b)
{
a = imread("img1.jpg");
b = imread("img2.jpg");

return;
}
1
  • try to use Mat &a , Mat &b or use Mat* a , Mat* b , one of them should work I don't have time to test it
    – Engine
    Sep 9, 2013 at 6:17

1 Answer 1

5

You might be confused by how OpenCV uses typedefs to hide reference types. I would lookup how typedefs like InputArray are defined, you'll see they have an & in them to make them reference types. cv::Mat is not a typedef so you need to declare it as a reference in the function's argument list.

void TestMethod(Mat& a, Mat& b)
{
    a = imread("img1.jpg");
    b = imread("img2.jpg");

    return;
}

The way you have it written now, a and b are copies of the Mat variables you passed when you called the function. You are just overwriting copies that are deallocating when the function returns.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.