Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

i have done mistake here. there must be a variable to keep image data. temp is only for keep information about single pixel. and also MNIST database has one channel images. i have define it as 3. here is the working code ans if someone has any thing about this, please comment here.

void create_image(CvSize size, int channels, unsigned char data[28][28], int imagenumber) {
string imgname; ostringstream imgstrm;string fullpath;
imgstrm << imagenumber;
imgname=imgstrm.str();
fullpath="D:\\MNIST\\"+imgname+".jpg";

IplImage *imghead=cvCreateImageHeader(size, IPL_DEPTH_8U, channels);
cvSetData(imghead, data, size.width);
cvSaveImage(fullpath.c_str(),imghead);  
}

and in the main function. it must be as follows.

    unsigned char arr[28][28];

    for(int i=0;i<1000;++i)
    {
        for(r=0;r<n_rows;++r)
        {
            for(c=0;c<n_cols;++c)
            {                 
                file.read((char*)&temp,sizeof(temp));
                arr[r][c]= temp;
            }           
        }
        size.height=r;size.width=c;
        create_image(size,1,arr, i);

    }