문제

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.

도움이 되었습니까?

해결책 2

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!

다른 팁

You can actually use hconcat/vconcat functions:

Mat dst = new Mat();
List<Mat> src = Arrays.asList(mat1, mat2);
Core.hconcat(src, dst);
//Core.vconcat(src, dst);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top