Search
 
SCRIPT & CODE EXAMPLE
 

CPP

displaying m images m windows opencv c++

imshow("1",img1);
imshow("2",img2);
Comment

displaying m images one window opencv c++

/**
     * @brief makeCanvas Makes composite image from the given images
     * @param vecMat Vector of Images.
     * @param windowHeight The height of the new composite image to be formed.
     * @param nRows Number of rows of images. (Number of columns will be calculated
     *              depending on the value of total number of images).
     * @return new composite image.
     */
    cv::Mat makeCanvas(std::vector<cv::Mat>& vecMat, int windowHeight, int nRows) {
            int N = vecMat.size();
            nRows  = nRows > N ? N : nRows; 
            int edgeThickness = 10;
            int imagesPerRow = ceil(double(N) / nRows);
            int resizeHeight = floor(2.0 * ((floor(double(windowHeight - edgeThickness) / nRows)) / 2.0)) - edgeThickness;
            int maxRowLength = 0;

            std::vector<int> resizeWidth;
            for (int i = 0; i < N;) {
                    int thisRowLen = 0;
                    for (int k = 0; k < imagesPerRow; k++) {
                            double aspectRatio = double(vecMat[i].cols) / vecMat[i].rows;
                            int temp = int( ceil(resizeHeight * aspectRatio));
                            resizeWidth.push_back(temp);
                            thisRowLen += temp;
                            if (++i == N) break;
                    }
                    if ((thisRowLen + edgeThickness * (imagesPerRow + 1)) > maxRowLength) {
                            maxRowLength = thisRowLen + edgeThickness * (imagesPerRow + 1);
                    }
            }
            int windowWidth = maxRowLength;
            cv::Mat canvasImage(windowHeight, windowWidth, CV_8UC3, Scalar(0, 0, 0));

            for (int k = 0, i = 0; i < nRows; i++) {
                    int y = i * resizeHeight + (i + 1) * edgeThickness;
                    int x_end = edgeThickness;
                    for (int j = 0; j < imagesPerRow && k < N; k++, j++) {
                            int x = x_end;
                            cv::Rect roi(x, y, resizeWidth[k], resizeHeight);
                            cv::Size s = canvasImage(roi).size();
                            // change the number of channels to three
                            cv::Mat target_ROI(s, CV_8UC3);
                            if (vecMat[k].channels() != canvasImage.channels()) {
                                if (vecMat[k].channels() == 1) {
                                    cv::cvtColor(vecMat[k], target_ROI, CV_GRAY2BGR);
                                }
                            } else {             
                                vecMat[k].copyTo(target_ROI);
                            }
                            cv::resize(target_ROI, target_ROI, s);
                            if (target_ROI.type() != canvasImage.type()) {
                                target_ROI.convertTo(target_ROI, canvasImage.type());
                            }
                            target_ROI.copyTo(canvasImage(roi));
                            x_end += resizeWidth[k] + edgeThickness;
                    }
            }
            return canvasImage;
    }
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ format number thousands separator 
Cpp :: 2d stl array 
Cpp :: tempcoderunnerfile.cpp:1:1: error: does not name a type 
Cpp :: run c++ files on chrome book 
Cpp :: operator using 
Cpp :: namespace c++ 
Cpp :: c++ n in regex 
Cpp :: Structure of s void function 
Cpp :: Check if two stacks are the same using C++ 
Cpp :: how to make a goto area in c++ 
Cpp :: onactorbeginoverlap c++ 
Cpp :: are maps sorted c++ 
Cpp :: c++ login 
Cpp :: opencv read gif c++ 
Cpp :: c++ get last element in array 
Cpp :: c++ find in pair 
Cpp :: how to write hello world c++ 
Cpp :: size of set c++ 
Cpp :: qt how to make a file browser 
Cpp :: hello world program in c ++ using standard namespace 
Cpp :: how to implement binders and decorators on c++ lik python? 
C :: sleep in c programming 
C :: dynamic 2d arr in c 
C :: how to map one value to another in C 
C :: how to search in a file in c 
C :: sigaction in c 
C :: c 2d array dimensions 
C :: c convert integer to string 
C :: ROUNDING decimal number in C 
C :: c program for swapping of two numbers using temporary variable 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =