diff --git a/cc/core/MatBindings.h b/cc/core/MatBindings.h index 4a267842b..a1d77c354 100644 --- a/cc/core/MatBindings.h +++ b/cc/core/MatBindings.h @@ -129,8 +129,16 @@ namespace MatBindings { size_t size; char *data; + cv::Size sizeTotal; + cv::Point ofs; + std::string executeCatchCvExceptionWorker() { size = mat.rows * mat.cols * mat.elemSize(); + mat.locateROI(sizeTotal, ofs); + + if(sizeTotal.width != mat.cols || sizeTotal.height != mat.rows){ + return "Cannot call GetData when Region of Interest is defined (i.e. after getRegion) use matrix.copyTo to copy ROI to a new matrix"; + } data = static_cast(malloc(size)); memcpy(data, mat.data, size); return ""; diff --git a/test/tests/core/Mat/Mat.test.js b/test/tests/core/Mat/Mat.test.js index 30fb3f3af..09d5f9b15 100644 --- a/test/tests/core/Mat/Mat.test.js +++ b/test/tests/core/Mat/Mat.test.js @@ -323,7 +323,14 @@ describe('Mat', () => { expect(buf).instanceOf(Buffer).lengthOf(18); }); }); - + + describe('getData after getRegion should throw an error', () => { + it('should return buffer of with data of single channeled Mat', () => { + const region = matC3.getRegion(new cv.Rect(0, 0, 2, 2)); + assertError(() => region.getData(), "Mat::GetData - Cannot call GetData when Region of Interest is defined (i.e. after getRegion) use matrix.copyTo to copy ROI to a new matrix") + }); + }); + describe('async', () => { it('should return buffer with data of single channeled Mat', (done) => { matC1.getDataAsync((err, buf) => {