A
A
Alexey2020-02-05 12:52:44
OpenCV
Alexey, 2020-02-05 12:52:44

Insert picture in picture?

const cv = require('opencv4nodejs');
var largeImg= cv.imread('./large.jpg'); // 30720x30720
var smallBlock1= cv.imread('./block1.jpg');  // 2048x2048
var smallBlock2= cv.imread('./block2.jpg');  // 2048x2048
var smallBlock3= cv.imread('./block3.jpg');  // 2048x2048

How to insert blocks into a large image with offset? What method is used?
cv.addWeighted has no offset, just img.add without them too

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2020-02-05
@Azperin

Came to this solution, maybe it will be useful for someone

var largeImg = cv.imread('./largeImg.jpg'); // загружаем какое-то большое изображение
// либо можно сгенерировать new cv.Mat(new Array(15360).fill( new Array(15360).fill([0,0,0]) ), cv.CV_8UC3);
var blockSideSize = 2048; // размер стороны в пикселях, он же и оффсет, т.е. блоки у нас 2048х2048
for (let x = 0; x < 3; x++) {
  for (let y = 0; y < 3; y++) {
    // тупо попиксельно заменяем каждый цвет
    let block = cv.imread(`./blocks/block_${x}-${y}.jpg`);
    for (let y1 = 0; y1 < blockSideSize; y1++) {
      for (let x1 = 0; x1 < blockSideSize; x1++) {
        largeImg.set((y * blockSideSize + y1), (x * blockSideSize + x1), block.at(y1, x1));
      };
    };
  };
};
cv.imwrite('./ResultLargeImage.jpg', largeImg);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question