2014-02-21 46 views
2

我做了一個從CameraBridgeViewBase(OpenCV)擴展的活動。當調用mOpenCvCameraView.enableView();時,它應該顯示相機。但現在不是。 我的活動是遵循從CameraBridgeViewBase(OpenCV)擴展的活動不會使相機連接

public class MainActivity extends Activity implements CvCameraViewListener2 { 
    private static final String TAG     = "OCVApplication::MainActivity"; 
    public static final int  VIEW_MODE_RGBA  = 0; 



    private CameraBridgeViewBase mOpenCvCameraView; 

    public static int viewMode = VIEW_MODE_RGBA; 

    private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) { 
     @Override 
     public void onManagerConnected(int status) { 
      switch (status) { 
       case LoaderCallbackInterface.SUCCESS: 
       { 
        Log.i(TAG, "OpenCV loaded successfully"); 
        mOpenCvCameraView.enableView(); 
       } break; 
       default: 
       { 
        super.onManagerConnected(status); 
       } break; 
      } 
     } 
    }; 




    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     Log.i(TAG, "called onCreate"); 
     super.onCreate(savedInstanceState); 
     getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 

     setContentView(R.layout.activity_main); 

     mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.image_manipulations_activity_surface_view); 
     mOpenCvCameraView.setCvCameraViewListener(this); 
    } 

    @Override 
    public void onCameraViewStarted(int width, int height) { 
     // TODO Auto-generated method stub 

    } 

    @Override 
    public void onCameraViewStopped() { 
     // TODO Auto-generated method stub 

    } 

    @Override 
    public Mat onCameraFrame(CvCameraViewFrame inputFrame) { 
     // TODO Auto-generated method stub 
     return null; 
    } 

    @Override 
    public void onPause() 
    { 
     super.onPause(); 
     if (mOpenCvCameraView != null) 
      mOpenCvCameraView.disableView(); 
    } 

    @Override 
    public void onResume() 
    { 
     super.onResume(); 
     OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_8, this, mLoaderCallback); 
    } 

    public void onDestroy() { 
     super.onDestroy(); 
     if (mOpenCvCameraView != null) 
      mOpenCvCameraView.disableView(); 
    } 
} 

XML是

<org.opencv.android.JavaCameraView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_centerInParent="true" 
     android:layout_marginLeft="0dp" 
     android:layout_marginRight="0dp" 
     android:visibility="gone" 
     android:layout_marginBottom="10dp"   
     android:layout_above="@+id/ImageCaptureButton" 
     android:id="@+id/image_manipulations_activity_surface_view" 
     opencv:show_fps="true" 
     opencv:camera_id="any"/> 
+0

在logcat中所有消息你找到一些幫助找到問題的日誌? –

+1

LogCat消息沒問題。只需顯示那些與加載OpenCV庫相關的代碼即可。 – batuman

+1

我已經下載了* cameraPreview的opencv示例*代碼之間唯一相關的區別是這個函數:'public Mat onCameraFrame(CvCameraViewFrame inputFrame){ return inputFrame.rgba(); }' –

回答

3

你已經錯過了這一點:

public Mat onCameraFrame(CvCameraViewFrame inputFrame) { 
    return inputFrame.rgba(); 
} 

希望這有助於!

+1

非常感謝您的幫助。 – batuman