1 | initial version |
don't save it as mat file, you can save it as dat file and then do this:
in matlab:
fid=fopen('test.dat','w+');
fprintf(fid,'%d\n',currFrame_Cropped_Gray);
fclose(fid);
This will save you the dat file as a 1 column.
now in java:
private Mat ReadDemoFromFile()
{
Mat tempmat = new Mat(new Size(701, 701), CvType.CV_8U);
InputStream in;
try {
in = new FileInputStream(Environment.getExternalStorageDirectory() + "/DCIM/Frames/test.dat");
InputStreamReader is = new InputStreamReader(in);
BufferedReader br = new BufferedReader(is);
String read;
for(int i = 0 ; i< 701; i++)
for(int j = 0 ; j < 701 ; j++)
{
try {
read = br.readLine();
tempmat.put(j, i, Integer.parseInt(read));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return tempmat;
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return tempmat;
}
Here I saved the data file in my device, if you want you can save the file in the RAW folder inside your project. This is an example of what I did, so change all the parameters and sizes as you wish.
2 | No.2 Revision |
don't save it as mat file, you can save it as dat file and then you can do this:
in matlab:
fid=fopen('test.dat','w+');
fprintf(fid,'%d\n',currFrame_Cropped_Gray);
fclose(fid);
This will save you the dat file as a 1 column.
now in java:
private Mat ReadDemoFromFile()
{
Mat tempmat = new Mat(new Size(701, 701), CvType.CV_8U);
InputStream in;
try {
in = new FileInputStream(Environment.getExternalStorageDirectory() + "/DCIM/Frames/test.dat");
InputStreamReader is = new InputStreamReader(in);
BufferedReader br = new BufferedReader(is);
String read;
for(int i = 0 ; i< 701; i++)
for(int j = 0 ; j < 701 ; j++)
{
try {
read = br.readLine();
tempmat.put(j, i, Integer.parseInt(read));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return tempmat;
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return tempmat;
}
Here I saved the data file in my device, if you want you can save the file in the RAW folder inside your project. This is an example of what I did, so change all the parameters and sizes as you wish.
3 | Improved style |
don't save it as mat file, you can save it the matrix as dat file you can do by doing this this:
in matlab:
in matlab:
fid=fopen('test.dat','w+');
fprintf(fid,'%d\n',currFrame_Cropped_Gray);
fclose(fid);
This will save your matrix as 1 column in a dat file, so after it you the dat file as a 1 column.can read in java line by line.
now in java:
private Mat ReadDemoFromFile()
{
Mat tempmat = new Mat(new Size(701, 701), CvType.CV_8U);
InputStream in;
try {
in = new FileInputStream(Environment.getExternalStorageDirectory() + "/DCIM/Frames/test.dat");
InputStreamReader is = new InputStreamReader(in);
BufferedReader br = new BufferedReader(is);
String read;
for(int i = 0 ; i< 701; i++)
for(int j = 0 ; j < 701 ; j++)
{
try {
read = br.readLine();
tempmat.put(j, i, Integer.parseInt(read));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return tempmat;
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return tempmat;
}
Here I saved the data file in my device, if you want you can save the file in the RAW folder inside your project. This is an example of what I did, so change all the parameters and sizes as you wish.