Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.

Commit 42422ab

Browse files
committed
fix: justadudewhohacks#480 by adding an error when GetData is called and ROI is defined
1 parent 9f89f45 commit 42422ab

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

cc/core/MatBindings.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,16 @@ namespace MatBindings {
129129
size_t size;
130130
char *data;
131131

132+
cv::Size sizeTotal;
133+
cv::Point ofs;
134+
132135
std::string executeCatchCvExceptionWorker() {
133136
size = mat.rows * mat.cols * mat.elemSize();
137+
mat.locateROI(sizeTotal, ofs);
138+
139+
if(sizeTotal.width != mat.cols || sizeTotal.height != mat.rows){
140+
return "Cannot call GetData when Region of Interest is defined (i.e. after getRegion) use matrix.copyTo to copy ROI to a new matrix";
141+
}
134142
data = static_cast<char *>(malloc(size));
135143
memcpy(data, mat.data, size);
136144
return "";

test/tests/core/Mat/Mat.test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,12 +324,10 @@ describe('Mat', () => {
324324
});
325325
});
326326

327-
describe('getData after getRegion', () => {
327+
describe('getData after getRegion should throw an error', () => {
328328
it('should return buffer of with data of single channeled Mat', () => {
329329
const region = matC3.getRegion(new cv.Rect(0, 0, 2, 2));
330-
const buf = region.getData();
331-
expect(buf).instanceOf(Buffer).lengthOf(12);
332-
expect(new Uint8Array(buf)[6]).to.equal(region.getDataAsArray()[1][0][0])
330+
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")
333331
});
334332
});
335333

0 commit comments

Comments
 (0)