From 02aa27da1dc1bbd767c7d8534345ed3f278be41b Mon Sep 17 00:00:00 2001 From: Anshul Jain Date: Fri, 20 Nov 2015 12:11:00 -0800 Subject: [PATCH] Return a new matrix after reshape operation to preserve the original matrix --- src/Matrix.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Matrix.cc b/src/Matrix.cc index 8c701de..e0026a7 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -2435,11 +2435,13 @@ NAN_METHOD(Matrix::Reshape) { JSTHROW("Invalid number of arguments"); } - cv::Mat res = self->mat.reshape(cn, rows); - ~self->mat; - self->mat = res; + Local img_to_return = + Nan::New(Matrix::constructor)->GetFunction()->NewInstance(); + Matrix *img = Nan::ObjectWrap::Unwrap(img_to_return); - return; + img->mat = self->mat.reshape(cn, rows); + + info.GetReturnValue().Set(img_to_return); } NAN_METHOD(Matrix::Release) {