I have a function that computes and “create” a matrix. My function works well when it is inlined, but when I try to put the code into a function, I have trouble getting back the result matrix.
I want my function call to be like this :
CvMat projectionResult;
project_on_subspace(&projectionResult);
cvShowImage("test", &projectionResult );
(Eventually using *CvMat instead of `CvMat)
What I did was the following :
void project_on_subspace(CvMat * source)
{
source = cvCreateMat( feature_positions[feature_number].height, feature_positions[feature_number].width, CV_32FC1 );
//some more code
}
But the cvCreateMat function changes the value of the source pointer, so when I return from the function, the projectionResult matrix is not initialized.
I am aware this is a really easy question, but I don’t really understand how to make this work?
Is it possible to do it without changing the function prototype, or do I need to to change it to a **CvMat instead of a *CvMat?
Edit : I’d prefer to return my result using in an argument pointer, rather than using a “return” statement, but both are fine.
Do this instead (assuming cvCreateMat does not return a pointer to a cvCreateMat):
And call it like:
Don’t forget to deallocate the projectionResult in due time.