According to the link of Operations on Arrays of OCV, I was not finding the way to have two different Mat and putting them into an only window which displays both of the images.
PS: It's not about merging images into a single one.
Any ideas?
According to the link of Operations on Arrays of OCV, I was not finding the way to have two different Mat and putting them into an only window which displays both of the images.
PS: It's not about merging images into a single one.
Any ideas?
I don't think it's possible to do it in pure opencv, as opencv is image processing library and support bare minimum of user interface, with a few functionality.
You can create a bigger Mat which contains your original two images. In order to be able to distinguish images from each other you can create a black line boundry, e.g:
// the 20 there is an example for border between images
Mat display = Mat::zeros ( MAX ( image1.rows, image2.rows ), image1.cols + 20 + image2.cols, image1.type() );
image1.copyTo ( Mat ( display, Rect ( 0, 0, image1.cols, image1.rows ) ) );
image2.copyTo ( Mat ( display, Rect ( image1.cols + 20, 0, image2.cols, image2.rows ) ) );
Use Qt and this function: how to convert an opencv cv::Mat to qimage
Highgui does not support several matrices per window yet.
I was thinking about this exact same thing and came across your question. Given the way Mat works, it is really just a smart pointer, i.e. has header information that defines how the data it points to is organized.
This means that you can't use the mat container, and everything display related right now only uses one mat object at a time. So a nice easy valid way is not easily achievable.
Warning, you now are responsible for handling the memory yourself
If you are extremely determined to do it (i know that feeling, and i did it this way since i couldn't find a better option). You could allocate a contiguous space in memory for your data buffer.
Now, you can partition that memory as you see fit for your multiple images. i.e. using pointer arithmetic. You need to make sure the images you want to display are next to each other.
At this point, you can create a Mat object that covers the whole memory space of your 2 objects using Mat(cv::Size size, int type, void *buffer)
.
Of course, using this method, they are permanently stuck together in a certain formation.
Obviously, this can also be done the other way around, i.e. create the mat object and let it allocate the space, and then take the data pointer from the Mat object using the uchar *data
member (remember to cast to your preferred type for your pointer arithmetic). And you can create 2 new Mat objects using that buffer.
Sadly, this method doesn't allow you do horizontal concatenation because of the way Mat objects are represented in memory.