Ask Your Question

Revision history [back]

you can simply test the code below and get the answer YES

#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"

using namespace cv;
using namespace std;

int showImages( vector< Mat > images )
{
    for( size_t i = 0; i < images.size(); i++ )
    {
        imshow(format("image - %d", i), images[i] );
    }

    waitKey();
}

int main( int argc, char** argv )
{
    vector< Mat > images;

    Mat img0 = Mat::zeros( 400, 400, CV_8UC1 );
    circle( img0, Point(250,250), 100, Scalar(255) );

    Mat img1 = Mat::zeros( 500, 500, CV_8UC3 );
    circle( img1, Point(250,250), 200, Scalar(0,0,255) );

    Mat img2 = Mat::ones( 300, 300, CV_32FC3 );

    images.push_back(img0);
    images.push_back(img1);
    images.push_back(img2);

    showImages(images);

    return 0;
}

"Is it possible to insert images of different format in vector<mat>?"

you can simply test the code below and get the answer YES

#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"

using namespace cv;
using namespace std;

int showImages( vector< Mat > images )
{
    for( size_t i = 0; i < images.size(); i++ )
    {
        imshow(format("image - %d", i), images[i] );
    }

    waitKey();
}

int main( int argc, char** argv )
{
    vector< Mat > images;

    Mat img0 = Mat::zeros( 400, 400, CV_8UC1 );
    circle( img0, Point(250,250), 100, Scalar(255) );

    Mat img1 = Mat::zeros( 500, 500, CV_8UC3 );
    circle( img1, Point(250,250), 200, Scalar(0,0,255) );

    Mat img2 = Mat::ones( 300, 300, CV_32FC3 );

    images.push_back(img0);
    images.push_back(img1);
    images.push_back(img2);

    showImages(images);

    return 0;
}

"Is it possible to insert images of different format in vector<mat>vector<Mat>?"

you can simply test the code below and get the answer YES

#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"

using namespace cv;
using namespace std;

int showImages( vector< Mat > images )
{
    for( size_t i = 0; i < images.size(); i++ )
    {
        imshow(format("image - %d", i), images[i] );
    }

    waitKey();
}

int main( int argc, char** argv )
{
    vector< Mat > images;

    Mat img0 = Mat::zeros( 400, 400, CV_8UC1 );
    circle( img0, Point(250,250), 100, Scalar(255) );

    Mat img1 = Mat::zeros( 500, 500, CV_8UC3 );
    circle( img1, Point(250,250), 200, Scalar(0,0,255) );

    Mat img2 = Mat::ones( 300, 300, CV_32FC3 );

    images.push_back(img0);
    images.push_back(img1);
    images.push_back(img2);

    showImages(images);

    return 0;
}