I have an Image<Gray, Byte>
and i want to calculate the covariance matrix for the image.
Therefore i use the function CvInvoke.cvCalcCovarMatrix(imageptr, 2, cov, avg, COVAR_METHOD.CV_COVAR_NORMAL);
Here my code:
Image<Gray, Byte> image_gray = _image.Convert<Gray, Byte>();
Matrix<float> cov = new Matrix<float>(image_gray.Rows, image_gray.Cols);
Matrix<float> avg = new Matrix<float>(image_gray.Cols, 1);
Matrix<float>[] input = new Matrix<float>[image_gray.Rows];
float[] temp = new float[image_gray.Rows];
for (int j = 0; j <image_gray.Rows; j++)
{
for (int i = 0; i < image_gray.Cols; i++)
{
temp[i] = (float)image_gray[j, i].Intensity;
}
input[j] =new Matrix<float>(temp);
}
IntPtr[] imageptr = Array.ConvertAll<Matrix<Single>, IntPtr>(input, delegate(Matrix<Single> mat) { return mat.Ptr; });
CvInvoke.cvCalcCovarMatrix(imageptr, 2, cov, avg, COVAR_METHOD.CV_COVAR_NORMAL);
The problem is, that the result of the covariance matrix elements are always null.
The mistake was the 2nd parameter of cvCalcCovarMatrix(imageptr,count, cov, avg, COVAR_METHOD.CV_COVAR_NORMAL);
Correct is:
cvCalcCovarMatrix(imageptr, image_gray.Cols, cov, avg, COVAR_METHOD.CV_COVAR_NORMAL);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.