Search code examples
opencvtransformconventions

How to show 2 channel Image or chnage it into 3 or one channel in OpenCv


I am new to Open Cv, I want to transform the two images, here are my images,Left image and right image. enter image description here

enter image description here

here is my Code

cv::Mat transformMat = cv::estimateRigidTransform(leftImageMat, rightImageMat, true);
transform(leftImageMat, reconMat, transformMat);

but the problem is that reconMat is of 2 channel. so how can I show it in openCv or convert to 1 channel image as shown above right and left images.


Solution

  • You have a fundamental misunderstanding of what cv::transform() does. The documentation states:

    Performs the matrix transformation of every array element.

    This means that the numerical value of each element is transformed by the specified matrix.

    It looks like you want a geometric transformation. This can be achieved using cv::warpAffine():

    cv::Mat transformMat = cv::estimateRigidTransform(leftImageMat, rightImageMat, true);
    cv::Mat output;
    cv::Size dsize = leftImageMat.size();    //This specifies the output image size--change as needed
    cv::warpAffine(leftImageMat, output, transformMat, dsize);