How, can I have a buffer or array of images "Mat" with OpenCV?
I mean: having a set of images, want to pick up and put in an array like
How can I do this? It's like C++ normal array style?
Mat images[2];
images[0] = imread(...);
images[1] = imread(..);
Thanks in advance.
Just declare a array of cvMat object as-
Mat image_array[10]; // array of 10 images
Now read the images into it according to index of the array
image_array[0]=imread("/home/me/Pictures/img1.png",1);
image_array[1]=imread("/home/me/Pictures/img2.png",1);
......
......
image_array[9]=imread("/home/me/Pictures/img9.png",1);
I had to implement something similar and I didn't need to view the images all I wanted was to extract some data from them but I'm going to add the imread anyway. Here is the code:
Mat mat[10];enter code here
char c[n]; //n is the size of chars in the directory of images
for(int i=1;i<=10;i++)
{
sprintf(c,"/directory to images/%d.jpg",i);
mat[i] = imread(c);
imshow("mat",mat[i]);
waitKey(0);
}
this is going to display the first image in the array and you will have to press any key to go to the next one. Hope this helps