opencv4nodejs icon indicating copy to clipboard operation
opencv4nodejs copied to clipboard

Draw mat at postion into different mat?

Open b-g opened this issue 4 years ago • 5 comments

Hi! I'm trying to draw a small image at position x/y into a big background image. I didn't find a way to do this with opencv4nodejs.

I'm aware of copyTo() ... but as both mats have to have the same size, it doesn't solve my problem.

const region = new cv.Rect(x, y, width, height)
small.copyTo(large.getRegion(region))

Any hints?

b-g avatar Oct 08 '19 14:10 b-g

me too

lighthx avatar Oct 18 '19 02:10 lighthx

Hi @justadudewhohacks, really no hint? :)

What would be the equivalent in your lib to e.g. this code?

// https://stackoverflow.com/a/10991840
Mat src( 5,  7, CV_8UC1, Scalar(1)); // 5x7
Mat dst(10, 10, CV_8UC1, Scalar(0)); // 10x10

src.copyTo(dst.rowRange(1, 6).colRange(3, 10));

b-g avatar Oct 22 '19 21:10 b-g

same question here

JCMais avatar Nov 03 '19 02:11 JCMais

Same question here

marcospgp avatar Jan 30 '20 22:01 marcospgp

I think this should work the way you're trying to do it. Just make sure that src and dest have the same size. If you're copying into a larger dest, you first need to get a region of the dest with the same size as src.

Equivalent of your example code:

const src = new cv.Mat(5, 7, cv.CV_8UC1, [0]); // 5x7
const dst = new cv.Mat(10, 10, cv.CV_8UC1, [255]); // 10x10

src.copyTo(dst.getRegion(new cv.Rect(3, 1, src.cols, src.rows)));

// print out the result
cv.imwrite('example.jpg', dst);

lost-valley avatar Oct 18 '22 11:10 lost-valley