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

Commit a3b6601

Browse files
Merge pull request justadudewhohacks#485 from piercus/issue-480
Issue 480
2 parents b1f1228 + 42422ab commit a3b6601

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

cc/core/MatBindings.h

+8
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

+8-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,14 @@ describe('Mat', () => {
325325
expect(buf).instanceOf(Buffer).lengthOf(18);
326326
});
327327
});
328-
328+
329+
describe('getData after getRegion should throw an error', () => {
330+
it('should return buffer of with data of single channeled Mat', () => {
331+
const region = matC3.getRegion(new cv.Rect(0, 0, 2, 2));
332+
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")
333+
});
334+
});
335+
329336
describe('async', () => {
330337
it('should return buffer with data of single channeled Mat', (done) => {
331338
matC1.getDataAsync((err, buf) => {

0 commit comments

Comments
 (0)