我的相机应用程序在显示帧之前使用OpenCV处理帧。虽然摄像头预览有效,但logcat被发送垃圾邮件时出现错误:
E / BufferQueue(22797):[unnamed-22797-0] dequeueBuffer:SurfaceTexture 已经被遗弃了! E / SecCameraHardware(2078):无法出列 gralloc缓冲! 05-03 13:29:12.716 E / ISecCameraHardware(2078):bool android :: ISecCameraHardware :: previewThread():: flushSurface()失败
以下是相关代码,改编自OpenCV的示例代码:
mCamera.setPreviewCallbackWithBuffer(new PreviewCallback() {
public void onPreviewFrame(byte[] data, Camera camera) {
synchronized (CameraView.this) {
System.arraycopy(data, 0, mFrame, 0, data.length);
CameraView.this.notify();
}
camera.addCallbackBuffer(mBuffer);
}
});
[...]
mBitmap = Bitmap.createBitmap(mFrameWidth, mFrameHeight,
Bitmap.Config.ARGB_8888);
try {
mCamera.setPreviewTexture(new SurfaceTexture(10));
} catch (IOException e) {};
mCamera.startPreview();
[...]
public void run() {
mThreadRun = true;
Log.i(TAG, "Starting processing thread");
while (mThreadRun) {
synchronized (this) {
try {
this.wait();
processFrame(mFrame);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Canvas canvas = mHolder.lockCanvas();
if (canvas != null) {
canvas.drawBitmap(mBitmap,
(canvas.getWidth() - mFrameWidth) / 2,
(canvas.getHeight() - mFrameHeight) / 2, null);
mHolder.unlockCanvasAndPost(canvas);
}
}
}
我注意到与此错误相关的existing question,但建议的解决方案 - 在设置预览纹理之前创建用于显示的位图 - 对我没有任何影响。