changed fromCvMat implementation