cv::Mat Input
: pass a copy ofInput
's header. Its header will not be changed outside of this function, but can be changed within the function. For example:void sillyFunc(cv::Mat Input, cv::Mat& Output){ Input = cv::Mat::ones(4, 4, CV_32F); // OK, but only changed within the function //... }
const cv::Mat Input
: pass a copy ofInput
's header. Its header will not be changed outside of or within the function. For example:void sillyFunc(const cv::Mat Input, cv::Mat& Output){ Input = cv::Mat::ones(4, 4, CV_32F); // Error, even when changing within the function //... }
const cv::Mat& Input
: pass a reference ofInput
's header. Guarantees thatInput
's header will not be changed outside of or within the function. For example:void sillyFunc(const cv::Mat& Input, cv::Mat& Output){ Input = cv::Mat::ones(4, 4, CV_32F); // Error when trying to change the header ... }
cv::Mat& Input
: pass a reference ofInput
's header. Changes toInput
's header happen outside of and within the function. For example:void sillyFunc(cv::Mat& Input, cv::Mat& Output){ Input = cv::Mat::ones(4, 4, CV_32F); // totally OK and does change ... }
函数传参cv::Mat, const cv::Mat, const cv::Mat& or cv::Mat& 的区别
引用自:
https://stackoverflow.com/questions/23468537/differences-of-using-const-cvmat-cvmat-cvmat-or-const-cvmat/23486280