Ask Your Question
0

how to convert char str_buffer[3072] into mat;

asked 2015-06-02 09:09:29 -0600

waheed gravatar image

how to convert cifar10 image char str_buffer[3072] into mat ;

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2015-06-02 13:37:14 -0600

LBerger gravatar image

updated 2015-06-02 13:40:56 -0600

May be you should read a book about C++

int main() {
    ifstream fs;
    const int tailleImage=3073;

    fs.open("F:\\Images\\cifar-10-batches-bin\\data_batch_1.bin",ios::binary);
    if (!fs.is_open())
        return 0;
   char *data=new char[tailleImage];
   for (int indexImage=25;indexImage<50;indexImage++)
    {
        fs.seekg(indexImage*tailleImage,ios::beg);
         fs.read(data,tailleImage);

        Mat im(32,32,CV_8UC3);
        for (int i=0;i<im.rows;i++)
            for (int j=0;j<im.rows;j++)
                im.at<Vec3b>(i,j)=Vec3b(data[j+i*32],data[j+i*32+32*32],data[j+i*32+32*32*2]);
        imshow("CIFAR",im);
            waitKey(100);
    }
   delete data;
    return 0;
    }

I don't check if it was BGR or RGB.

edit flag offensive delete link more

Comments

@LBerger, just curious, so cifar images come with separate planes for r,g,b channels ?

berak gravatar imageberak ( 2015-06-03 00:34:46 -0600 )edit
1

@berak yes I have found format in this page( Binary version)

LBerger gravatar imageLBerger ( 2015-06-03 00:45:18 -0600 )edit

ah, cool. thanks.

berak gravatar imageberak ( 2015-06-03 00:52:22 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-06-02 09:09:29 -0600

Seen: 192 times

Last updated: Jun 02 '15