利用opencv读取多张图片

利用opencv中的imread读取图片十分方便,这里读取多张图片利用for循环的方法进行读取

代码如下

#include<opencv2\core\core.hpp>

#include<opencv2\highgui\highgui.hpp>
#include <opencv2/opencv.hpp>
#include<iostream>
using namespace std;
using namespace cv;
int main()
{
    system("color 5F");//自己设置的显示背景和数字的颜色
    for(int i=1;i<20;i++)//利用for循环读取多个图片
    {
        char buf[10];
    sprintf(buf,"%d.bmp",i);//把不同的第i个图片名称
    Mat image=imread(buf,0);//读入一张图
    if( !image.data )   //判读读取图片是否成功
        { printf("Oh,no,读取img图片文件错误~! \n");
        system("pause");//按键继续
        return -1; }
    for(int i=0;i<image.rows;i++)//读入图片的行
        for(int j=0;j<image.cols;j++)//读入图片的列
        {
            image.at<uchar>(i,j);//把图片的行和列存储起来
        }
    cout<<"shuzu"<<endl<<"the "<<i<<" image="<<endl<<image<<endl;//把读取到的二值化图片显示出来
    }
    waitKey(0);//等待多长时间关闭图片(0为一直显示此图片)
    return 0;
}
 
 

猜你喜欢

转载自blog.csdn.net/Goinggogogo/article/details/78231043
今日推荐