Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

asked 2017-01-30 23:36:29 -0600

Nbb gravatar image

calcCovarMatrix crashes

I am trying to compute the covariance and mean of my data matrix where each row is a sample of 3 dimensions. I have printed temp_rgb_mat to verify that it has X rows and 3 columns. The code I have below keeps crashing though and even after googling for various threads I still cant seem to figure out the reason behind it.

 //compute mean and covariance matrix of node
 cv::Mat temp_rgb_mat(cv::Size(3, nodes[i].rgb.size()), CV_8UC1, nodes[i].rgb.data());
 cv::calcCovarMatrix(&temp_rgb_mat, 1, nodes[i].covar_rgb, nodes[i].mean_rgb, CV_COVAR_NORMAL | CV_COVAR_ROWS);

calcCovarMatrix crashes

I am trying to compute the covariance and mean of my data matrix where each row is a sample of 3 dimensions. I have printed temp_rgb_mat to verify that it has X rows and 3 columns. The code I have below keeps crashing though and even after googling for various threads I still cant seem to figure out the reason behind it.

 //compute mean and covariance matrix of node
 cv::Mat temp_rgb_mat(cv::Size(3, nodes[i].rgb.size()), CV_8UC1, nodes[i].rgb.data());
 cv::calcCovarMatrix(&temp_rgb_mat, 1, nodes[i].covar_rgb, nodes[i].mean_rgb, CV_COVAR_NORMAL | CV_COVAR_ROWS);

nodes[i].rgb.data is a vector< Vec3b >. This is the error I receive

OpenCV Error: Assertion failed (data[i].size() == size && data[i].type() == type) in cv::calcCovarMatrix, file C:\Bin\opencv-master\source\modules\core\src\matmul.cpp, line 2525