ZuzEL ZuzEL - 24 days ago 7
Java Question

OpenCV java. Multiple images side by side

Is there any example of how to combine two or more images side by side? In JAVA

I tried to adapt c++ code but without success.

Mat m = new Mat(imageA.cols(), imageA.rows() + imageB.rows(), imageA.type());

m.adjustROI(0, 0, imageA.cols(), imageA.rows());
imageA.copyTo(m);

m.adjustROI(0, imageA.rows(), imageB.cols(), imageB.rows());
imageB.copyTo(m);


This will always give
m
as
imageA
. Method
A.copyTo(B)
always result like
B == A


Almost every example in c++ contains
cvCopy(arg1, arg2);
it looks like java analog is A.copyTo(B)

But when I use A.copyTo(B), I always get image with width, height and content of A even if B was bigger.

Answer
private Mat addTo(Mat matA, Mat matB) {
    Mat m = new Mat(matA.rows(), matA.cols() +  matB.cols(), matA.type());
    int aCols = matA.cols();
    int aRows = matA.rows();
    m.rowRange(0, aRows-1).colRange(0, aCols-1) = matA;
    m.rowRange(0, aRows-1).colRange(aCols, (aCols*2)-1) = matB;
    return m;
}

I didn't try to run it, but I believe it will work. I assume matA and matB will have same size and same type. Even if it doesn't work, there must be some little syntax errors or etc. You shouldn't be putting pixels values by using 4 for loops!

Comments