Ask Your Question
0

Get every element from a mat without any symbols

asked 2014-01-13 03:59:25 -0600

Hello,

i would like to get every elemt from a mat without any bracktets ( [,] or ,]

So I create a txt file and write there every element of my mat.

It looks like: [ 91, 28, 129, ...] But i want, that it looks like this example: 91 28 129

How I can do this?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-01-13 04:08:04 -0600

updated 2014-01-13 04:08:48 -0600

Just write the values of the pixels directly into the TXT, but you will need to save the size of the mat too (for example first two values)

Mat pic;
FILE *out;
out=open("ouput.txt","w");
printf("%d %d ",pic.cols,pic.rows);
unsigned char *ptr_data=pic.data;
for(int i=0;i<pic.cols*pic.rows;i++)  //for CV_8UC13 the condition is i<pic.cols*pic.rows*3
      printf("%d ",(int)*(ptr_data++); 
close(out);

I haven't compile that code, but the idea is clear.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-01-13 03:59:25 -0600

Seen: 247 times

Last updated: Jan 13 '14