diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp index 42b271f1e..b273c8a7d 100644 --- a/modules/core/src/matrix.cpp +++ b/modules/core/src/matrix.cpp @@ -4816,7 +4816,8 @@ void SparseMat::copyTo( SparseMat& m ) const void SparseMat::copyTo( Mat& m ) const { CV_Assert( hdr ); - m.create( dims(), hdr->size, type() ); + int ndims = dims(); + m.create( ndims, hdr->size, type() ); m = Scalar(0); SparseMatConstIterator from = begin(); @@ -4825,7 +4826,7 @@ void SparseMat::copyTo( Mat& m ) const for( i = 0; i < N; i++, ++from ) { const Node* n = from.node(); - copyElem( from.ptr, m.ptr(n->idx), esz); + copyElem( from.ptr, (ndims > 1 ? m.ptr(n->idx) : m.ptr(n->idx[0])), esz); } }