OpenCV/Android BufferQueue错误:表面纹理已被放弃



Android和OpenCV的新功能。一直在尝试实现新书《用实用计算机视觉项目掌握OpenCV》中的代码。该应用程序基本上使用OpenCV在相机预览上渲染卡通化图像。您可以触摸屏幕来保存卡通化的图像。

作者的源代码位于此处。

我对CartooniferApp.java文件做了一个小的修改(见下文),这样我就可以用OpenCV Manager应用程序静态加载卡通程序库(原始代码抛出了一个不满意的链接错误)。

我面临的问题是,当我将应用程序加载到我的Galaxy Nexus(Android 4.1.1)上时,我会得到一个空的黑屏。我的LogCat说:

E/BufferQueue(4744):〔unnamed-4744-0〕setBufferCount:表面纹理已被遗弃!E/卡通制作者::SurfaceView(4744):startPreview()失败

我认为这是内存问题。我知道cpp代码之所以有效,是因为它在我的计算机上运行良好——尽管在相对较新的笔记本电脑(华硕U46E)上渲染速度较慢。

我不知道怎么解决这个问题。我找到的唯一有用的建议是这里。如果我在CatoonifierVewBase.java 中替换我的setPreview方法

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

带有

mCamera.setPreviewDisplay(mHolder);

然后发生的事情是相机像正常工作一样,我可以通过触摸屏幕来保存卡通化的图像。请注意,这并不是我想要的结果,因为我想不断地卡通化相机上的图像预览。相机之所以能正常工作,是因为我没有按照表面视图写作(至少这是我的理解)。前面提到的网站上的答案有一些变通方法,但我不知道他在说什么。

顺便说一句,我已经尝试了所有的OpenCV4Android应用程序示例,它们运行得很好。此外,我使用的是OpenCV 2.4.3版本。API水平目标为15。

完整Logcat:

12-22 15:33:07.966:I/CartoonifierApp(5999):实例化的新类com.Cartoonifier.CartooniiferApp 12-22 15:33:07.966:I/CartoonifierApp(5999):调用Create 12-22 15:33:07.966:I/CartoonifierApp(5999):尝试加载OpenCV库12-2215:33:07.982:I/Cartoonifier::SurfaceView(5999):实例化的新class com.Cartoonifier.CartooniiferView 12-22 15:33:07.990:I/CartoonifierApp(5999):简历12-22 15:33:07.990:I/Cartoonifier::SurfaceView(5999):openCamera 12-22 15:33:07.990:I/Cartoonifier::SurfaceView(5999):发布照片12-22 15:33:08.099:D/OpenCVManager/Helper(5999):已创建服务连接12-2215:33:08.099:D/OpenCVManager/Helper(5999):正在尝试获取库路径12-22 15:33:08.138:D/OpenCVManager/Helper(5999):试图获得库列表12-22 15:33:08.169:D/OpenCVManager/Helper(5999):库列表:"12-22 15:33:08.169:D/OpenCVManager/Helper(5999):第一尝试加载libs 12-22 15:33:08.169:D/OpenCVManager/Helper(5999):尝试初始化OpenCV libs 12-22 15:33:08.169:D/OpenCVManager/Helper(5999):正在尝试加载库/data/data/org.opencv.engine/lib/libopencv_java.so 12-22 15:33:08.169:

D/dalvikvm(5999):正在尝试加载lib/data/data/org.opencv.engine/lib/libopencv_java.so 0x41936a40 12-22

15:33:08.193:D/dalvikvm(5999):添加了共享库/data/data/org.opencv.engine/lib/libopencv_java.so 0x41936a40 12-22

15:33:08.193:D/OpenCVManager/Helper(5999):OpenCV libs init还可以!

12-22 15:33:08.193:D/OpenCVManager/Helper(5999):首次尝试加载库正常12-22 15:33:08.193:D/OpenCVManager/Helper(5999):Init已完成,状态为0 12-22 15:33:08.193:D/OpenCVManager/Helper(5999):从服务取消绑定12-22 15:33:08.200:D/OpenCVManager/Helper(5999):使用回调进行调用12-2215:33:08200:I/CartoonifierApp(5999):OpenCV成功加载

12-22 15:33:08.200:D/dalvikvm(5999):正在尝试加载lib/data/data/com.Cartoonifier/lib/libkatonifier.so 0x41936a40 12-22

15:33:08.200:D/dalvikvm(5999):添加了共享库/data/data/com.Cartoonifier/lib/libkatonifier.so 0x41936a40 12-22

15:33:08200:D/dalvikvm(5999):在中找不到JNI_OnLoad/data/data/com.Cartoonifier/lib/libkatonifier.so 0x41936a40,正在跳过init 12-22 15:33:08.200:D/OpenCVManager/Helper(5999):创建的服务连接12-22 15:33:08.200:D/OpenCVManager/Helper(5999):试图获取库路径12-22

15:33:88.232:D/OpenCVManager/Helper(5999):正在尝试获取库列表12-22 15:33:08.271:D/OpenCVManager/Helper(5999):库列表:">

12-22 15:33:08.271:D/OpenCVManager/Helper(5999):首次尝试加载libs 12-22 15:33:08.271:D/OpenCVManager/Helper(5999):正在尝试

init OpenCV libs 12-22 15:33:08.271:D/OpenCVManager/Helper(5999):正在尝试加载库/data/data/org.opencv.engine/lib/libopencv_java.so 12-22 15:33:08.271:D/dalvikvm(5999):正在尝试加载lib/data/data/org.opencv.engine/lib/libopencv_java.so 0x41936a40 12-22

15:33:08.271:D/dalvikvm(5999):共享库"/data/data.org/opencv.engine/lib/libopencv_java.so"已在中加载同一CL 0x41936a40 12-22 15:33:08.271:D/OpenCVManager/Helper(5999):OpenCV libs init还可以!12-22 15:33:08.271:D/OpenCVManager/Helper(5999):首次尝试加载库是可以的

12-22 15:33:08.271:D/OpenCVManager/Helper(5999):初始化已完成,状态为012-22 15:33:08.271:D/OpenCVManager/Helper(5999):取消绑定服务12-22 15:33:08.271:D/OpenCVManager/Helper(5999):使用回调进行调用12-22 15:33:08.271:I/CartoonifierApp(5999):OpenCV加载成功12-22 15:33:08.279:D/dalvikvm(5999):正在尝试加载lib/data/data/com.Cartoonifier/lib/libc漫画家.so 0x41936a4012-22 15:33:88.279:D/dalvikvm(5999):共享库'/data/data.com/Cartoonifier/lib/libcoanifier.so'已加载在同一CL 0x41936a40中12-22 15:33:08.302:I/Cartoonifier::表面视图(5999):表面已创建12-22 15:33:08.302:I/Cartoonifier::SurfaceView(5999):surfaceChanged()。窗口大小:1196x67012-22 15:33:08.302:I/Cartoonifier::SurfaceView(5999):setupCamera(1196x670)12-22 15:33:08.302:I/Cartoonifier::SurfaceView(5999):正在启动处理线程12-22 15:33:88.310:I/Cartoonifier::SurfaceView(5999):找到的相机分辨率1920x108012-22 15:33:88.310:I/Cartoonifier::SurfaceView(5999):发现相机分辨率1280x72012-22 15:33:88.310:I/Cartoonifier::SurfaceView(5999):发现相机分辨率960x72012-22 15:33:88.310:I/Cartoonifier::SurfaceView(5999):发现相机分辨率800x48012-22 15:33:88.310:I/Cartoonifier::SurfaceView(5999):发现相机分辨率720x57612-22 15:33:88.310:I/Cartoonifier::SurfaceView(5999):发现相机分辨率720x48012-22 15:33:88.310:I/Cartoonifier::SurfaceView(5999):发现相机分辨率768x57612-22 15:33:88.310:I/Cartoonifier::SurfaceView(5999):找到的相机分辨率为640x48012-22 15:33:88.310:I/Cartoonifier::SurfaceView(5999):找到的相机分辨率为320x24012-22 15:33:88.310:I/Cartoonifier::SurfaceView(5999):找到相机分辨率352x28812-22 15:33:88.310:I/Cartoonifier::SurfaceView(5999):发现相机分辨率240x16012-22 15:33:88.310:I/Cartoonifier::SurfaceView(5999):发现相机分辨率176x14412-22 15:33:88.310:I/Cartoonifier::SurfaceView(5999):发现相机分辨率128x9612-22 15:33:08.318:I/Cartoonifier::SurfaceView(5999):选择的相机预览尺寸:1280x72012-22 15:33:08.333:D/dalvikvm(5999):GC_FOR_ALLOC释放131K,2%释放10807K/11011K,暂停13ms,总计13ms

12-22 15:33:08.333:I/dalvikvm堆(5999):将堆(frag大小写)增加到11.902MB以进行1382416字节的分配

12-22 15:33:08.357:D/dalvikvm(5999):GC_CONCURRENT释放1K,3%释放12156K/12423K,暂停12ms+1ms,总计24ms

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

12-22 15:33:08.365:D/dalvikvm(5999):GC_FOR_ALLOC释放0K,3%释放12156K/12423K,暂停9ms,总计9ms

12-22 15:33:08.372:I/dalvikvm堆(5999):将堆(frag大小写)增加到13.219MB,用于1382416字节的分配

12-22 15:33:08.388:D/dalvikvm(5999):GC_CONCURRENT释放0K,3%释放13506K/13831K,暂停11ms+1ms,总计21ms

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

12-22 15:33:08.404:D/dalvikvm(5999):GC_FOR_ALLOC释放<1K,3%免费13506K/13831K,暂停9ms,总共10ms

12-22 15:33:08.411:I/dalvikvm堆(5999):将堆(frag大小写)增加到16.735MB以进行3686416字节的分配

12-22 15:33:08.427:D/dalvikvm(5999):释放GC_CONCURRENT<1K,3%空闲17106K/17479K,暂停12ms+1ms,总计22ms

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

12-22 15:33:08.443:D/dalvikvm(5999):GC_FOR_ALLOC释放<1K,3%免费17106K/17479K,暂停10ms,总共10ms

12-22 15:33:08.450:I/dalvikvm堆(5999):将堆(frag大小写)增长到20.250MB以进行3686416字节的分配

12-22 15:33:88.4466:D/dalvikvm(5999):GC_CONCURRENT释放0K,2%释放20706K/21127K,暂停12ms+2ms,总计22ms

12-22 15:33:08.4466:D/dalvikvm(5999):WAIT_FOR_CONCURRENT_GC阻止5ms

12-22 15:33:08.4466:I/Cartoonifier::SurfaceView(5999):开始预览

12-22 15:33:08.497:E/BufferQueue(5999):[未命名5999-0]setBufferCount:SurfaceTexture已被放弃!

12-22 15:33:08.505:E/卡通制作者::SurfaceView(5999):mCamera.startPreview()失败

CartoonifierApp.java中显示我修改的片段

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();
}
}

这个问题不久前在OpenCV中得到了解决。

不确定是应用程序错误还是操作系统错误。问题是对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);
}

(行的顺序发生了变化)

相关内容

  • 没有找到相关文章

最新更新