Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cc/core/MatBindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<char *>(malloc(size));
memcpy(data, mat.data, size);
return "";
Expand Down
9 changes: 8 additions & 1 deletion test/tests/core/Mat/Mat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down