OpenCV - Array of Images, or Buffer of Mat

强颜欢笑 提交于 2019-12-13 01:15:05

问题


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.


回答1:


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);



回答2:


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



来源:https://stackoverflow.com/questions/16383672/opencv-array-of-images-or-buffer-of-mat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!