2013-12-13 11 views
7

Próbuję wyświetlić podgląd kamery na żywo w Google Glass.Wyświetlany obraz z szklanego aparatu jest zniekształcony.

Używam wszystkich domyślnych ustawień kamery (i próbowałem również użyć kilku różnych formatów obrazu, najlepiej mogę użyć jednego z formatów YUV), ale obraz wyświetlany na ekranie jest zniekształcony, to:

garbled preview image

układ jest prosty:

<?xml version="1.0" encoding="utf-8"?> 
<TextureView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/scan_preview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" /> 

Oto kod aktywny:

public class ScanActivity extends Activity { 
    private static final String kTag = ScanActivity.class.getSimpleName(); 
    private TextureView mVideoCaptureView = null; 
    private Camera mCamera = null; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_scan); 
     setTitle(R.string.title_scan); 

     mVideoCaptureView = (TextureView) findViewById(R.id.scan_preview); 
     mVideoCaptureView.setKeepScreenOn(true); 
     mVideoCaptureView.setSurfaceTextureListener(new VideoCaptureTextureListener()); 
    } 

    @Override 
    protected void onPause() { 
     super.onPause(); 
     stopVideo(); 
    } 

    @Override 
    protected void onResume() { 
     super.onResume(); 
     startVideo(); 
    } 

    private void startVideo() { 
     if (mCamera != null) { 
      mCamera.release(); 
     } 
     mCamera = Camera.open(); 
     if (null != mVideoCaptureView) { 
      try { 
       mCamera.setPreviewTexture(mVideoCaptureView.getSurfaceTexture()); 
      } catch (IOException e) { 
       Log.e(kTag, "Error setting preview texture", e); 
       return; 
      } 
     } 
     mCamera.startPreview(); 
    } 

    private void stopVideo() { 
     if (null == mCamera) 
      return; 
     try { 
      mCamera.stopPreview(); 
      mCamera.setPreviewDisplay(null); 
      mCamera.setPreviewTexture(null); 
      mCamera.release(); 
     } catch (IOException e) { 
      Log.w(kTag, e); 
     } 
     mCamera = null; 
    } 

    private final class VideoCaptureTextureListener implements TextureView.SurfaceTextureListener { 

     @Override 
     public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { 
      stopVideo(); 
      return true; 
     } 

     @Override 
     public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { 
      startVideo(); 
     } 

     @Override 
     public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { 
     } 

     @Override 
     public void onSurfaceTextureUpdated(SurfaceTexture surface) { 
     } 
    } 
} 

Czy masz pojęcie, dlaczego ten całkowicie niemanipulowany podgląd kamery nie wyświetla się poprawnie?

+2

możliwe duplikat [podglądu Google Glass obrazu jajecznica z nowym wydaniem XE10] (http://stackoverflow.com/questions/19235477/google-glass-preview-image-scrambled -with-new-xe10-release) –

Odpowiedz

10

Zostało tutaj odpowiedzi: https://stackoverflow.com/a/19257078/950427

Długoterminowa:

Camera.Parameters params = camera.getParameters(); 
params.setPreviewFpsRange(30000, 30000); 
camera.setParameters(params); 

Shorterm (testing):

Dla szybkiego testowania i użytkowania, wystarczy dodać do najbardziej oddalonych view:

android:layout_margin="1dp" 

Na przykład:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_margin="1dp" 
    android:layout_height="match_parent" > 

    <org.opencv.android.JavaCameraView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:id="@+id/tutorial2_activity_surface_view" /> 

</LinearLayout> 
+1

Podczas wysyłania zapytania do kamery, maksymalna previewFpsRange jest wymieniona jako 60000. Przypuszczam, że warto sprawdzić w następnym wydaniu. – squidpickles

+0

Nadal zepsute od XE12. – squidpickles

+0

@slugchewer Zdecydowanie nie, właśnie pracowałem nad aplikacją Camera wczoraj. Proszę spojrzeć na: https://github.com/jaredsburrows/OpenQuartz/tree/master/example-apps –

Powiązane problemy