opencv4nodejs
opencv4nodejs copied to clipboard
Draw mat at postion into different mat?
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?
me too
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));
same question here
Same question here
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);