I have one function to compute convolution (to test whether we are using correct settings for filter2D
), I think the function body is not important, so here's just header and the end:
template<typename T>
cv::Mat conv(const cv::Mat &input, const cv::Mat &kernel) {
cv::Mat output(input); // or should I rather use output( input.rows, input.cols, input.depth())?
...
return output;
}
cv::Mat result = conv( input, kernel);
At this point, I have completely useless results in result
(those aren't even random data, they have some strange pattern which got repeated every time I run the function).
When I rewrite function to:
template<typename T>
void conv(const cv::Mat &input, cv::Mat &output, const cv::Mat &kernel) {
...
}
cv::Mat result(input);
conv( input, result, kernel);
Everything works just fine and result matrix contains exactly what it should.
So my question is: What's wrong on first approach? Am I doing something wrong? Why isn't assign operator/return from function working?
*Note: OpenCv version: extra/opencv 2.3.1_a-3 (archlinux package)*
Something similar happened to me when I was loading external data from opencv storage and data got lost until I used data( loaded.clone())