adjacent images in single window
Hi!I am using C++ and opencv..I need to display 3 images adjacent to each other in a single window. Can someone help please
Thanks
Hi!I am using C++ and opencv..I need to display 3 images adjacent to each other in a single window. Can someone help please
Thanks
Ok, shouldnt be that hard. I assume that all have the same height (otherwise find the biggest height) The 3 input images are img1, img2, img3.
cv::Size s1 = img1.size();
cv::Size s2 = img2.size();
cv::Size s3 = img3.size();
cv::Mat output(s1.height, s1.width + s2.width + s3.width, CV_MAT_TYPE); // put in the type of your mat
cv::Mat help1(output, cv::Rect(0,0, s1.width, s1.height);
cv::Mat help2(output, cv::Rect(s1.width, 0, s2.width, s2.height);
cv::Mat help3(output, cv::Rect(s1.width + s2.width, 0, s3.width, s3.height);
img1.copyTo(help1);
img2.copyTo(help2);
img3.copyTo(help3);
cv::imshow("Output", output);
Here is how this works: You create an output image that has the total size of all 3 images. Then you create 3 Mats that only point to a part of your output image that equals their respective input image. This only works since Mat(output, Rect()) does not copy the output Mat to a new one, it only points to it. So by img.copyTo(help) you copy the input image to the respective part in output.
cv::Mat output(s1.height, s1.width + s2.width + s3.width, CV_MAT_TYPE) and cv::Mat help2(output, cv::Rect(s1.width, 0, s2.width, s2.height);..what are those parameters in general?what does s1.height,s1.width + s2.width + s3.width, CV_MAT_TYPE mean in general?hope iim being clear
CV_MAT_TYPE( just a placeholder) is the image type of your input images. They have to be the same. So you can basically just do: cv::Mat output(s1.height, s1.width + s2.width + s3.width, img1.type())
s1, s2, s3 are the sizes of your input images. That are also the first 3 statements in my answer. s1.height is obviously the height of one of your input images (make sure you take the biggest height there). Your output image needs to have this height. s1.width + s2.width + s3.width is the total width of your output image, since you want to put them all next to each other.
With cv::Rect(s1.width, 0, s2.width, s2.height) you determine the size a rectangle and also its position. This is for example the rectangle of your 2nd image (you could call it region of interest).
sorryy..maybe i wasnt clear enough :/ cv::Mat is a data structure used to hold images and other matrix data. For example cv::Mat ima(240,320,CV_8U,cv::Scalar(100)); "ima" is the name given to the image, CV_8U is the type of the image,that is, whether it is colored or black and white, 240 and 320 i dont know whether they are coordinates etc
Now in general : Mat "imageName"(int rows,int cols,type,etcccc)
I need to know exactly what the data inside the brackets mean in general, like for Rect(int x, int y, int width, int height)
thanks for the additional details
As the name says, Mat is just a Matrix that has rows and columns. Each entry of the mat has a value and is determined by the row and column. So if you take Mat as an image container, the rows correspond to the image height and columns correspond to the width. Every entry of the Mat is a pixel value. So you have width * height entries (1 channel image) The 240 and 320 in your example just determine the size of your matrix.
Asked: 2013-09-10 05:59:47 -0600
Seen: 1,686 times
Last updated: Sep 10 '13
Is stereoRectifyUncalibrated efficient?
face recognition (different image size)
Way to convert .wav file waveform into video .mjpeg file
how to make two images only different from the brightness become the same
How do I capture images from a modest video camera?
Some questions about training LBP classifier.