2017-10-07 23 views
0

私はonPreviewFrameで画像処理を行い、各フレームのY、U、V値を生成するアプリケーションを作成しています。私はこれらの値をArrayListに保存しました。ログ(Y、U、V)ArrayListからCSVを生成Android

10-08 05:06:10.941 20405-20405/redlight55.com.bpreader D/MyEntryData: [1590690, 2700692, 5731888] 
10-08 05:06:10.998 20405-20405/redlight55.com.bpreader D/MyEntryData: [1610252, 2699200, 5760320] 
10-08 05:06:11.014 20405-20405/redlight55.com.bpreader D/MyEntryData: [1612862, 2700420, 5763556] 
10-08 05:06:11.089 20405-20405/redlight55.com.bpreader D/MyEntryData: [1617378, 2699508, 5770000] 

から

例Iは、デバイスの内部ストレージに保存されるCSVファイルにこれらのデータを格納します。 彼らは、これは私がopencsvでそれをやろうとしてきた私は、ArrayListの

@Override 
public void onPreviewFrame(int ySum, int uSum, int vSum) { 
    img_Y_Avg = ySum; 
    img_U_Avg = uSum; 
    img_V_Avg = vSum; 

    //set value of Y on the text view 
    TextView valueOfY = (TextView)findViewById(R.id.valueY); 
    valueY = img_Y_Avg; 
    valueOfY.setText(Double.toString(img_Y_Avg)); 

    //set value of U on the text view 
    TextView valueOfU = (TextView)findViewById(R.id.valueU); 
    valueU = img_U_Avg; 
    valueOfU.setText(Double.toString(img_U_Avg)); 

    //set value of V on the text view 
    TextView valueOfV = (TextView)findViewById(R.id.valueV); 
    valueV = img_V_Avg; 
    valueOfV.setText(Double.toString(img_V_Avg)); 

    //store value to array list 
    ArrayList<Integer> yAverage = new ArrayList<Integer>(); 
    yAverage.add(img_Y_Avg); 
    //Log.d("MyEntryData", String.valueOf(yAverage)); 

    //store u values to array 
    ArrayList<Integer> uAverage = new ArrayList<Integer>(); 
    uAverage.add(img_U_Avg); 
    //Log.d("MyEntryData", String.valueOf(uAverage)); 

    //store u values to array 
    ArrayList<Integer> vAverage = new ArrayList<Integer>(); 
    vAverage.add(img_V_Avg); 
    //Log.d("MyEntryData", String.valueOf(vAverage)); 


    ArrayList<Integer> getValues = new ArrayList<Integer>(); 
    for(int i = 0; i < uAverage.size(); i++) { 
     getValues.add(yAverage.get(i)); 
     getValues.add(uAverage.get(i)); 
     getValues.add(vAverage.get(i)); 
    } 

    Log.d("MyEntryData", String.valueOf(getValues)); 


    handler = new Handler(); 
    final Runnable runnable = new Runnable() { 
     @Override 
     public void run() { 
      readingRemaining = readingRemaining -1; 

      if (readingRemaining > 0){ 
       plotGraph(img_Y_Avg); 
      } 
     } 
    }; 

    handler.postDelayed(runnable, 100); 

    //Log.d("MyEntryData", String.valueOf(img_Y_Avg +" "+ img_U_Avg+" "+img_V_Avg)); 
} 

のログを保存し、生成しています方法です。この

enter image description here

のようなものとして格納する必要がありますが、デバイスストレージに生成されるファイルはありません。これどうやってするの?

答えて

1

CSVはカンマ区切りの値ファイルなので、書き込んでください。

String filename = "csvfile.csv"; 
FileOutputStream outputStream; 

try { 
    outputStream = openFileOutput(filename, Context.MODE_PRIVATE); 
    for(int i = 0; i < uAverage.size(); i+=3) { 
     outputStream.write((getValues.get(i)+",").getBytes()); 
     outputStream.write((getValues.get(i+1)+",").getBytes()); 
     outputStream.write((getValues.get(i+2)+"\n").getBytes()); 
    } 
    outputStream.close(); 
} catch (Exception e) { 
    e.printStackTrace(); 
} 
+0

でも同じ問題があります。内部ストレージ内のファイルを見つけることができません。すべてのデータがプレビューフレームから生成されるとファイルが保存されるため、if文を追加してカメラがnullかどうかを確認します。まだ私は内部のストレージ内のタイルを取得しません。 – Mill3r

1
String filename = "csvfile.csv"; 

    File directoryDownload = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); 
    File logDir = new File (directoryDownload, "bpReader"); //Creates a new folder in DOWNLOAD directory 
    logDir.mkdirs(); 
    File file = new File(logDir, filename); 

    FileOutputStream outputStream = null; 
    try { 
      outputStream = new FileOutputStream(file, true); 
      //outputStream = openFileOutput(filename, Context.MODE_PRIVATE); 
      for (int i = 0; i < uAverage.size(); i += 3) { 
       outputStream.write((getValues.get(i) + ",").getBytes()); 
       outputStream.write((getValues.get(i + 1) + ",").getBytes()); 
       outputStream.write((getValues.get(i + 2) + "\n").getBytes()); 

      } 
      outputStream.close(); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 

これが正解であるように思えます。 Shmuelが投稿した回答は、ファイルを作成して列を分割するのに役立ちました。しかし、私は外部ストレージにファイルディレクトリを宣言する必要があります。

問題は、私は内蔵ストレージだけを持っている電話を持っていたということでした。だから、私はそれを内部ストレージに格納するために何かをする必要があると思った。私は間違っているかもしれませんが、電話機に内蔵ストレージしかない場合は、実際には外部ストレージとして機能します。

私はこれに完全に間違っているかもしれませんが、それは私のように思えました。

+1

マニフェストのWRITE_EXTERNAL_STORAGE権限を追加します。 Environment.getExternalStorageState()でフォルダを取得します。 – Shmuel

関連する問題