2012-12-22 19 views
6

AndroidおよびOpenCVの新機能です。新しい本からコードを実装しようとしていた実用的なコンピュータビジョンプロジェクトでOpenCVをマスタリングする。このアプリは基本的に、OpenCVを使用してカメラのプレビューに漫画化された画像をレンダリングします。画面に触れて、漫画化された画像を保存することができます。OpenCV/Android BufferQueueエラー:サーフェステクスチャが放棄されました

投稿者のソースコードは、hereにあります。

CartoonifierApp.javaファイルに小さな変更を加えました(アプリを使って、漫画化ライブラリを静的に読み込めるようにしました(元のコードはUnsatisfiedLinkErrorを投げました)。

私が直面している問題は、アプリをGalaxy Nexus(Android 4.1.1)に読み込むと、空の黒い画面が表示されることです。私のLogCatはこう言います:

E/BufferQueue(4744): [unnamed-4744-0] setBufferCount: SurfaceTexture has been abandoned! E/Cartoonifier::SurfaceView(4744): startPreview() failed

私はメモリ問題だと思います。比較的新しいノートパソコン(Asus U46E)ではレンダリングが遅いですが、コンピュータ上では正常に動作するため、cppコードが動作することはわかっています。

これを修正する方法はわかりません。私が見つけた唯一のアドバイスはhereでした。私はその後、

mCamera.setPreviewDisplay(mHolder); 

でCatoonifierVewBase.java

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) 
    mCamera.setPreviewTexture(new SurfaceTexture(10)); 
else 
    mCamera.setPreviewDisplay(null); 

で私setPreview方法を交換した場合どのようなカメラがあるが起こるかは、通常と同じように動作し、私は、画面をタッチすることでcartoonified画像を保存することができます。これは、カメラのプレビューでイメージを継続的に漫画化したいので、これが望ましい結果ではないことに注意してください。私は表面の見方に書いていないのでカメラは働いています(少なくとも私の理解です)。前に述べたsiteの答えにはいくつかの回避策がありますが、彼が何を話しているのかは分かりません。

私はすべてのサンプルOpenCV4Androidアプリを試してみましたが、うまく動作します。また、私はOpenCVバージョン2.4.3を使用しています。この問題は、いくつかの時間前にOpenCVのにworkaroundedた私の変形例を示すCartoonifierApp.javaから

12-22 15:33:07.966: I/CartoonifierApp(5999): Instantiated new class com.Cartoonifier.CartoonifierApp 12-22 15:33:07.966: I/CartoonifierApp(5999): called onCreate 12-22 15:33:07.966: I/CartoonifierApp(5999): Trying to load OpenCV library 12-22 15:33:07.982: I/Cartoonifier::SurfaceView(5999): Instantiated new class com.Cartoonifier.CartoonifierView 12-22 15:33:07.990: I/CartoonifierApp(5999): onResume 12-22 15:33:07.990: I/Cartoonifier::SurfaceView(5999): openCamera 12-22 15:33:07.990: I/Cartoonifier::SurfaceView(5999): releaseCamera 12-22 15:33:08.099: D/OpenCVManager/Helper(5999): Service connection created 12-22 15:33:08.099: D/OpenCVManager/Helper(5999): Trying to get library path 12-22 15:33:08.138: D/OpenCVManager/Helper(5999): Trying to get library list 12-22 15:33:08.169: D/OpenCVManager/Helper(5999): Library list: "" 12-22 15:33:08.169: D/OpenCVManager/Helper(5999): First attempt to load libs 12-22 15:33:08.169: D/OpenCVManager/Helper(5999): Trying to init OpenCV libs 12-22 15:33:08.169: D/OpenCVManager/Helper(5999): Trying to load library /data/data/org.opencv.engine/lib/libopencv_java.so 12-22 15:33:08.169:

D/dalvikvm(5999): Trying to load lib /data/data/org.opencv.engine/lib/libopencv_java.so 0x41936a40 12-22

15:33:08.193: D/dalvikvm(5999): Added shared lib /data/data/org.opencv.engine/lib/libopencv_java.so 0x41936a40 12-22

15:33:08.193: D/OpenCVManager/Helper(5999): OpenCV libs init was ok!

12-22 15:33:08.193: D/OpenCVManager/Helper(5999): First attempt to load libs is OK 12-22 15:33:08.193: D/OpenCVManager/Helper(5999): Init finished with status 0 12-22 15:33:08.193: D/OpenCVManager/Helper(5999): Unbind from service 12-22 15:33:08.200: D/OpenCVManager/Helper(5999): Calling using callback 12-22 15:33:08.200: I/CartoonifierApp(5999): OpenCV loaded successfully

12-22 15:33:08.200: D/dalvikvm(5999): Trying to load lib /data/data/com.Cartoonifier/lib/libcartoonifier.so 0x41936a40 12-22

15:33:08.200: D/dalvikvm(5999): Added shared lib /data/data/com.Cartoonifier/lib/libcartoonifier.so 0x41936a40 12-22

15:33:08.200: D/dalvikvm(5999): No JNI_OnLoad found in /data/data/com.Cartoonifier/lib/libcartoonifier.so 0x41936a40, skipping init 12-22 15:33:08.200: D/OpenCVManager/Helper(5999): Service connection created 12-22 15:33:08.200: D/OpenCVManager/Helper(5999): Trying to get library path 12-22

15:33:08.232: D/OpenCVManager/Helper(5999): Trying to get library list 12-22 15:33:08.271: D/OpenCVManager/Helper(5999): Library list: ""

12-22 15:33:08.271: D/OpenCVManager/Helper(5999): First attempt to load libs 12-22 15:33:08.271: D/OpenCVManager/Helper(5999): Trying to

init OpenCV libs 12-22 15:33:08.271: D/OpenCVManager/Helper(5999): Trying to load library /data/data/org.opencv.engine/lib/libopencv_java.so 12-22 15:33:08.271: D/dalvikvm(5999): Trying to load lib /data/data/org.opencv.engine/lib/libopencv_java.so 0x41936a40 12-22

15:33:08.271: D/dalvikvm(5999): Shared lib '/data/data/org.opencv.engine/lib/libopencv_java.so' already loaded in same CL 0x41936a40 12-22 15:33:08.271: D/OpenCVManager/Helper(5999): OpenCV libs init was ok! 12-22 15:33:08.271: D/OpenCVManager/Helper(5999): First attempt to load libs is OK

12-22 15:33:08.271: D/OpenCVManager/Helper(5999): Init finished with status 0 12-22 15:33:08.271: D/OpenCVManager/Helper(5999): Unbind from service 12-22 15:33:08.271: D/OpenCVManager/Helper(5999): Calling using callback 12-22 15:33:08.271: I/CartoonifierApp(5999): OpenCV loaded successfully 12-22 15:33:08.279: D/dalvikvm(5999): Trying to load lib /data/data/com.Cartoonifier/lib/libcartoonifier.so 0x41936a40 12-22 15:33:08.279: D/dalvikvm(5999): Shared lib '/data/data/com.Cartoonifier/lib/libcartoonifier.so' already loaded in same CL 0x41936a40 12-22 15:33:08.302: I/Cartoonifier::SurfaceView(5999): surfaceCreated 12-22 15:33:08.302: I/Cartoonifier::SurfaceView(5999): surfaceChanged(). Window size: 1196x670 12-22 15:33:08.302: I/Cartoonifier::SurfaceView(5999): setupCamera(1196x670) 12-22 15:33:08.302: I/Cartoonifier::SurfaceView(5999): Starting processing thread 12-22 15:33:08.310: I/Cartoonifier::SurfaceView(5999): Found Camera Resolution 1920x1080 12-22 15:33:08.310: I/Cartoonifier::SurfaceView(5999): Found Camera Resolution 1280x720 12-22 15:33:08.310: I/Cartoonifier::SurfaceView(5999): Found Camera Resolution 960x720 12-22 15:33:08.310: I/Cartoonifier::SurfaceView(5999): Found Camera Resolution 800x480 12-22 15:33:08.310: I/Cartoonifier::SurfaceView(5999): Found Camera Resolution 720x576 12-22 15:33:08.310: I/Cartoonifier::SurfaceView(5999): Found Camera Resolution 720x480 12-22 15:33:08.310: I/Cartoonifier::SurfaceView(5999): Found Camera Resolution 768x576 12-22 15:33:08.310: I/Cartoonifier::SurfaceView(5999): Found Camera Resolution 640x480 12-22 15:33:08.310: I/Cartoonifier::SurfaceView(5999): Found Camera Resolution 320x240 12-22 15:33:08.310: I/Cartoonifier::SurfaceView(5999): Found Camera Resolution 352x288 12-22 15:33:08.310: I/Cartoonifier::SurfaceView(5999): Found Camera Resolution 240x160 12-22 15:33:08.310: I/Cartoonifier::SurfaceView(5999): Found Camera Resolution 176x144 12-22 15:33:08.310: I/Cartoonifier::SurfaceView(5999): Found Camera Resolution 128x96 12-22 15:33:08.318: I/Cartoonifier::SurfaceView(5999): Chosen Camera Preview Size: 1280x720 12-22 15:33:08.333: D/dalvikvm(5999): GC_FOR_ALLOC freed 131K, 2% free 10807K/11011K, paused 13ms, total 13ms

12-22 15:33:08.333: I/dalvikvm-heap(5999): Grow heap (frag case) to 11.902MB for 1382416-byte allocation

12-22 15:33:08.357: D/dalvikvm(5999): GC_CONCURRENT freed 1K, 3% free 12156K/12423K, paused 12ms+1ms, total 24ms

12-22 15:33:08.357: D/dalvikvm(5999): WAIT_FOR_CONCURRENT_GC blocked 11ms

12-22 15:33:08.365: D/dalvikvm(5999): GC_FOR_ALLOC freed 0K, 3% free 12156K/12423K, paused 9ms, total 9ms

12-22 15:33:08.372: I/dalvikvm-heap(5999): Grow heap (frag case) to 13.219MB for 1382416-byte allocation

12-22 15:33:08.388: D/dalvikvm(5999): GC_CONCURRENT freed 0K, 3% free 13506K/13831K, paused 11ms+1ms, total 21ms

12-22 15:33:08.388: D/dalvikvm(5999): WAIT_FOR_CONCURRENT_GC blocked 7ms

12-22 15:33:08.404: D/dalvikvm(5999): GC_FOR_ALLOC freed <1K, 3% free 13506K/13831K, paused 9ms, total 10ms

12-22 15:33:08.411: I/dalvikvm-heap(5999): Grow heap (frag case) to 16.735MB for 3686416-byte allocation

12-22 15:33:08.427: D/dalvikvm(5999): GC_CONCURRENT freed <1K, 3% free 17106K/17479K, paused 12ms+1ms, total 22ms

12-22 15:33:08.427: D/dalvikvm(5999): WAIT_FOR_CONCURRENT_GC blocked 10ms

12-22 15:33:08.443: D/dalvikvm(5999): GC_FOR_ALLOC freed <1K, 3% free 17106K/17479K, paused 10ms, total 10ms

12-22 15:33:08.450: I/dalvikvm-heap(5999): Grow heap (frag case) to 20.250MB for 3686416-byte allocation

12-22 15:33:08.466: D/dalvikvm(5999): GC_CONCURRENT freed 0K, 2% free 20706K/21127K, paused 12ms+2ms, total 22ms

12-22 15:33:08.466: D/dalvikvm(5999): WAIT_FOR_CONCURRENT_GC blocked 5ms

12-22 15:33:08.466: I/Cartoonifier::SurfaceView(5999): start preview

12-22 15:33:08.497: E/BufferQueue(5999): [unnamed-5999-0] setBufferCount: SurfaceTexture has been abandoned!

12-22 15:33:08.505: E/Cartoonifier::SurfaceView(5999): mCamera.startPreview() failed

スニペット

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

       // Load native library after(!) OpenCV initialization 
       System.loadLibrary("cartoonifier"); 
      } break; 
      default: 
      { 
       super.onManagerConnected(status); 
      } break; 
     } 
    } 
}; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    Log.i(TAG, "called onCreate"); 
    super.onCreate(savedInstanceState); 

    Log.i(TAG, "Trying to load OpenCV library"); 
    if (!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, mLoaderCallback)) 
    { 
     Log.e(TAG, "Cannot connect to OpenCV Manager"); 
    } 

    requestWindowFeature(Window.FEATURE_NO_TITLE); 

    mView = new CartoonifierView(this); 
    setContentView(mView); 

    // Call our "onTouch()" callback function whenever the user touches the screen. 
    mView.setOnTouchListener(this); 
} 


@Override 
protected void onPause() { 
    Log.i(TAG, "onPause"); 
    super.onPause(); 
    mView.releaseCamera(); 
} 

@Override 
public void onResume() 
{ 
    super.onResume(); 
    Log.i(TAG, "onResume"); 
    if (!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, mLoaderCallback)) 
    { 
     Log.e(TAG, "Cannot connect to OpenCV Manager"); 
    } 

    if(!mView.openCamera()) { 
     AlertDialog ad = new AlertDialog.Builder(this).create(); 
     ad.setCancelable(false); // This blocks the 'BACK' button 
     ad.setMessage("Fatal error: can't open camera!"); 
     /*ad.setButton("OK", new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog, int which) { 
       dialog.dismiss();      
       finish(); 
      } 
     }); */ 
     ad.show(); 
    } 
} 

答えて

9

:APIレベルの目標は、15

全Logcatです。

アプリケーションかOSの不具合かどうかは不明です。問題は、Bitmap.createBitmapへの呼び出しが可視化のために使用されたSurfaceTextureオブジェクトを切り離すことです。

問題を回避するには、ベースViewクラスのsetupCamera方法を変更し、

try { 
    setPreview(); 
} catch (IOException e) { 
    Log.e(TAG, "mCamera.setPreviewDisplay/setPreviewTexture fails: " + e); 
} 

/* Notify that the preview is about to be started and deliver preview size */ 
onPreviewStarted(params.getPreviewSize().width, params.getPreviewSize().height); 

/* Notify that the preview is about to be started and deliver preview size */ 
onPreviewStarted(params.getPreviewSize().width, params.getPreviewSize().height); 

try { 
    setPreview(); 
} catch (IOException e) { 
    Log.e(TAG, "mCamera.setPreviewDisplay/setPreviewTexture fails: " + e); 
} 

は(行の順序が変更された)を変更することでした

関連する問題