differenceImage1
and differenceImage2
are grayscale images, hence with 1 channel, and you are allocating differenceImage3
with 3 channels (using flag CV_8UC3
). This causes the two copyTo
calls to allocate new buffers in leftone
and rightone
instead of using the pre-allocated buffer from differenceImage3
, which therefore is never filled.
This should work as expected if you replace:
Mat differenceImage3(sz1.height, sz1.width + sz2.width, CV_8UC3);
with
Mat differenceImage3(sz1.height, sz1.width + sz2.width, CV_8UC1);