我一直试图进入OpenCV。下面的代码似乎在cvtColor上崩溃了。
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
mRgba = inputFrame.rgba();
mGray = inputFrame.gray();
Mat gray = new Mat();
Imgproc.cvtColor(mRgba, gray, Imgproc.COLOR_RGB2GRAY);
return gray;
}
我无法理解为什么它在视频运行10秒后仍然会崩溃Android应用程序,而没有cvtColor它运行得很好。
想知道这里会发生什么。
日志
ExynosCameraBufferManager: [CAM_ID(0)][ISP_BUF]-ERR(getBuffer[667]):increase the buffer failed, m_allocatedBufCount 8, bufferIndex -2
10-04 20:39:54.877 3105 22149 E ExynosCameraMCPipe: [CAM_ID(0)][PIPE_3AA]-ERR(m_putBuffer[1447]):Buffer manager getBuffer fail, manager(2), frameCount(686), ret(-22)
10-04 20:39:54.936 3105 22149 E ExynosCameraBufferManager: [CAM_ID(0)][ISP_BUF]-ERR(getBuffer[667]):increase the buffer failed, m_allocatedBufCount 8, bufferIndex -2
10-04 20:39:54.936 3105 22149 E ExynosCameraMCPipe: [CAM_ID(0)][PIPE_3AA]-ERR(m_putBuffer[1447]):Buffer manager getBuffer fail, manager(2), frameCount(687), ret(-22)
10-04 20:39:54.996 3105 22149 E ExynosCameraBufferManager: [CAM_ID(0)][ISP_BUF]-ERR(getBuffer[667]):increase the buffer failed, m_allocatedBufCount 8, bufferIndex -2
10-04 20:39:54.996 3105 22149 E ExynosCameraMCPipe: [CAM_ID(0)][PIPE_3AA]-ERR(m_putBuffer[1447]):Buffer manager getBuffer fail, manager(2), frameCount(688), ret(-22)
10-04 20:39:55.055 3105 22150 E ExynosCameraMCPipe: [CAM_ID(0)][PIPE_3AA]-ERR(m_getBuffer[1948]):frameCount(686) : captureNodeCount == 0 || checkRet(0) != NO_ERROR. so, setFrameState(FRAME_STATE_SKIPPED)
10-04 20:39:55.056 3105 22149 E ExynosCameraBufferManager: [CAM_ID(0)][ISP_BUF]-ERR(getBuffer[667]):increase the buffer failed, m_allocatedBufCount 8, bufferIndex -2
10-04 20:39:55.056 3105 22149 E ExynosCameraMCPipe: [CAM_ID(0)][PIPE_3AA]-ERR(m_putBuffer[1447]):Buffer manager getBuffer fail, manager(2), frameCount(689), ret(-22)
10-04 20:39:55.056 25883 25883 E CocktailBarContainerView: updateContainerVisibility: 0
10-04 20:39:55.115 3105 22150 E ExynosCameraMCPipe: [CAM_ID(0)][PIPE_3AA]-ERR(m_getBuffer[1948]):frameCount(687) : captureNodeCount == 0 || checkRet(0) != NO_ERROR. so, setFrameState(FRAME_STATE_SKIPPED)
10-04 20:39:55.116 3105 22149 E ExynosCameraBufferManager: [CAM_ID(0)][ISP_BUF]-ERR(getBuffer[667]):increase the buffer failed, m_allocatedBufCount 8, bufferIndex -2
10-04 20:39:55.116 3105 22149 E ExynosCameraMCPipe: [CAM_ID(0)][PIPE_3AA]-ERR(m_putBuffer[1447]):Buffer manager getBuffer fail, manager(2), frameCount(690), ret(-22)
10-04 20:39:55.131 25883 25883 E CocktailBarContainerView: updateContainerVisibility: 0
10-04 20:39:55.131 25883 25883 E CocktailBarPanelManager: updateCocktailDisplayPolicy: 128 ---> 128
10-04 20:39:55.131 25883 25883 E CocktailBarContainerView: updateContainerVisibility: 0
10-04 20:39:55.135 25883 25883 E CocktailBarContainerView: updateContainerVisibility: 0
10-04 20:39:55.158 26076 26076 E Zygote : v2
10-04 20:39:55.160 26076 26076 E Zygote : accessInfo : 0
10-04 20:39:55.176 3105 22150 E ExynosCameraMCPipe: [CAM_ID(0)][PIPE_3AA]-ERR(m_getBuffer[1948]):frameCount(688) : captureNodeCount == 0 || checkRet(0) != NO_ERROR. so, setFrameState(FRAME_STATE_SKIPPED)
10-04 20:39:55.176 3105 22149 E ExynosCameraBufferManager: [CAM_ID(0)][ISP_BUF]-ERR(getBuffer[667]):increase the buffer failed, m_allocatedBufCount 8, bufferIndex -2
10-04 20:39:55.176 3105 22149 E ExynosCameraMCPipe: [CAM_ID(0)][PIPE_3AA]-ERR(m_putBuffer[1447]):Buffer manager getBuffer fail, manager(2), frameCount(691), ret(-22)
10-04 20:39:55.183 25883 25883 E CocktailBarPanelManager: updateCocktailDisplayPolicy: 128 ---> 1
10-04 20:39:55.184 25883 25883 E CocktailBarContainerView: updateContainerVisibility: 0
10-04 20:39:55.186 26087 26087 E Zygote : v2
10-04 20:39:55.187 26087 26087 E Zygote : accessInfo : 0
10-04 20:39:55.205 3105 26008 E ExynosCameraMemoryAllocator: ERR(alloc):dequeue_buffer failed
10-04 20:39:55.210 3105 22157 E Surface : queueBuffer: error queuing buffer to SurfaceTexture, -32
10-04 20:39:55.210 3105 26008 E ExynosCameraMemoryAllocator: ERR(alloc):dequeue_buffer failed
10-04 20:39:55.210 3105 22157 E ExynosCameraMemoryAllocator: ERR(enqueueBuffer):enqueue_buffer failed
10-04 20:39:55.210 3105 26008 E ExynosCameraMemoryAllocator: ERR(alloc):dequeue_buffer failed
10-04 20:39:55.210 3105 22157 E ExynosCameraBufferManager: [CAM_ID(0)][SCP_BUF]-ERR(m_putBuffer[1866]):could not enqueue_buffer [bufIndex=1]
10-04 20:39:55.210 3105 26008 E ExynosCameraMemoryAllocator: ERR(alloc):dequeue_buffer failed
10-04 20:39:55.210 3105 26008 E ExynosCameraMemoryAllocator: ERR(alloc):dequeue_buffer failed
10-04 20:39:55.210 3105 26008 E ExynosCameraMemoryAllocator: @@@@ERR(alloc):*bufHandle == NULL failed
10-04 20:39:55.210 3105 26008 E ExynosCameraMemoryAllocator: ERR(dequeueBuffer):alloc failed
10-04 20:39:55.210 3105 26008 E ExynosCameraBufferManager: [CAM_ID(0)][SCP_BUF]-ERR(m_bufferCollectorThreadFunc[2294]):dequeueBuffer failed, dequeue(6), collected(4)
10-04 20:39:55.214 3105 26102 E ExynosCameraMemoryAllocator: ERR(alloc):dequeue_buffer failed
10-04 20:39:55.214 3105 26102 E ExynosCameraMemoryAllocator: ERR(alloc):dequeue_buffer failed
10-04 20:39:55.214 3105 26102 E ExynosCameraMemoryAllocator: ERR(alloc):dequeue_buffer failed
10-04 20:39:55.214 3105 26102 E ExynosCameraMemoryAllocator: ERR(alloc):dequeue_buffer failed
10-04 20:39:55.214 3105 26102 E ExynosCameraMemoryAllocator: ERR(alloc):dequeue_buffer failed
10-04 20:39:55.214 3105 26102 E ExynosCameraMemoryAllocator: @@@@ERR(alloc):*bufHandle == NULL failed
10-04 20:39:55.214 3105 26102 E ExynosCameraMemoryAllocator: ERR(dequeueBuffer):alloc failed
10-04 20:39:55.215 3105 26102 E ExynosCameraBufferManager: [CAM_ID(0)][SCP_BUF]-ERR(m_bufferCollectorThreadFunc[2294]):dequeueBuffer failed, dequeue(6), collected(3)
10-04 20:39:55.217 3105 22151 E ExynosCameraMCPipe: [CAM_ID(0)][PIPE_ISP]-ERR(m_putBuffer[1420]):Pipe is Busy, Skip frame, frameCount(679)
10-04 20:39:55.219 3105 26103 E ExynosCameraMemoryAllocator: ERR(alloc):dequeue_buffer failed
10-04 20:39:55.219 3105 26103 E ExynosCameraMemoryAllocator: ERR(alloc):dequeue_buffer failed
10-04 20:39:55.219 3105 26103 E ExynosCameraMemoryAllocator: ERR(alloc):dequeue_buffer failed
10-04 20:39:55.219 3105 26103 E ExynosCameraMemoryAllocator: ERR(alloc):dequeue_buffer failed
10-04 20:39:55.219 3105 26103 E ExynosCameraMemoryAllocator: ERR(alloc):dequeue_buffer failed
10-04 20:39:55.219 3105 26103 E ExynosCameraMemoryAllocator: @@@@ERR(alloc):*bufHandle == NULL failed
10-04 20:39:55.219 3105 26103 E ExynosCameraMemoryAllocator: ERR(dequeueBuffer):alloc failed
10-04 20:39:55.219 3105 26103 E ExynosCameraBufferManager: [CAM_ID(0)][SCP_BUF]-ERR(m_bufferCollectorThreadFunc[2294]):dequeueBuffer failed, dequeue(6), collected(2)
10-04 20:39:55.223 3105 26104 E ExynosCameraMemoryAllocator: ERR(alloc):dequeue_buffer failed
10-04 20:39:55.223 3105 22157 E Surface : queueBuffer: error queuing buffer to SurfaceTexture, -32
10-04 20:39:55.223 3105 22157 E ExynosCameraMemoryAllocator: ERR(enqueueBuffer):enqueue_buffer failed
10-04 20:39:55.224 3105 26104 E ExynosCameraMemoryAllocator: ERR(alloc):dequeue_buffer failed
10-04 20:39:55.224 3105 22157 E ExynosCameraBufferManager: [CAM_ID(0)][SCP_BUF]-ERR(m_putBuffer[1866]):could not enqueue_buffer [bufIndex=2]
10-04 20:39:55.224 3105 26104 E ExynosCameraMemoryAllocator: ERR(alloc):dequeue_buffer failed
10-04 20:39:55.224 3105 26104 E ExynosCameraMemoryAllocator: ERR(alloc):dequeue_buffer failed
10-04 20:39:55.224 3105 26104 E ExynosCameraMemoryAllocator: ERR(alloc):dequeue_buffer failed
10-04 20:39:55.224 3105 26104 E ExynosCameraMemoryAllocator: @@@@ERR(alloc):*bufHandle == NULL failed
10-04 20:39:55.224 3105 26104 E ExynosCameraMemoryAllocator: ERR(dequeueBuffer):alloc failed
10-04 20:39:55.224 3105 26104 E ExynosCameraBufferManager: [CAM_ID(0)][SCP_BUF]-ERR(m_bufferCollectorThreadFunc[2294]):dequeueBuffer failed, dequeue(6), collected(1)
10-04 20:39:55.225 3105 26105 E ExynosCameraMemoryAllocator: ERR(alloc):dequeue_buffer failed
10-04 20:39:55.225 3105 26105 E ExynosCameraMemoryAllocator: ERR(alloc):dequeue_buffer failed
10-04 20:39:55.225 3105 22151 E ExynosCameraBufferManager: [CAM_ID(0)][SCP_BUF]-ERR(m_getCollectedBuffer[2397]):Gralloc buffer collector has no Buffer
10-04 20:39:55.225 3105 26105 E ExynosCameraMemoryAllocator: ERR(alloc):dequeue_buffer failed
10-04 20:39:55.225 3105 22151 E ExynosCameraBufferManager: [CAM_ID(0)][SCP_BUF]-ERR(m_getCollectedBuffer[2421]):Failed to get available gralloc buffer from buffer collector, available count(0)
10-04 20:39:55.225 3105 26105 E ExynosCameraMemoryAllocator: ERR(alloc):dequeue_buffer failed
10-04 20:39:55.226 3105 22151 E ExynosCameraBufferManager: [CAM_ID(0)][SCP_BUF]-ERR(getBuffer[611]):m_getBuffer failed [bufferIndex=-2, position=2, permission=0]
10-04 20:39:55.226 3105 26105 E ExynosCameraMemoryAllocator: ERR(alloc):dequeue_buffer failed
10-04 20:39:55.226 3105 22151 E ExynosCameraMCPipe: [CAM_ID(0)][PIPE_ISP]-ERR(m_putBuffer[1447]):Buffer manager getBuffer fail, manager(5), frameCount(683), ret(-38)
10-04 20:39:55.226 3105 26105 E ExynosCameraMemoryAllocator: @@@@ERR(alloc):*bufHandle == NULL failed
10-04 20:39:55.226 3105 26105 E ExynosCameraMemoryAllocator: ERR(dequeueBuffer):alloc failed
10-04 20:39:55.226 3105 26105 E ExynosCameraBufferManager: [CAM_ID(0)][SCP_BUF]-ERR(m_bufferCollectorThreadFunc[2294]):dequeueBuffer failed, dequeue(6), collected(0)
10-04 20:39:55.226 3105 22151 E ExynosCameraBufferManager: [CAM_ID(0)][SCP_BUF]-ERR(m_getCollectedBuffer[2397]):Gralloc buffer collector has no Buffer
10-04 20:39:55.226 3105 22151 E ExynosCameraBufferManager: [CAM_ID(0)][SCP_BUF]-ERR(m_getCollectedBuffer[2421]):Failed to get available gralloc buffer from buffer collector, available count(0)
10-04 20:39:55.226 3105 22151 E ExynosCameraBufferManager: [CAM_ID(0)][SCP_BUF]-ERR(getBuffer[611]):m_getBuffer failed [bufferIndex=-2, position=2, permission=0]
10-04 20:39:55.226 3105 22151 E ExynosCameraMCPipe: [CAM_ID(0)][PIPE_ISP]-ERR(m_putBuffer[1447]):Buffer manager getBuffer fail, manager(5), frameCount(684), ret(-38)
10-04 20:39:55.226 3105 22151 E ExynosCameraBufferManager: [CAM_ID(0)][SCP_BUF]-ERR(m_getCollectedBuffer[2397]):Gralloc buffer collector has no Buffer
10-04 20:39:55.226 3105 26107 E ExynosCameraMemoryAllocator: ERR(alloc):dequeue_buffer failed
10-04 20:39:55.226 3105 22151 E ExynosCameraBufferManager: [CAM_ID(0)][SCP_BUF]-ERR(m_getCollectedBuffer[2421]):Failed to get available gralloc buffer from buffer collector, available count(0)
10-04 20:39:55.226 3105 22151 E ExynosCameraBufferManager: [CAM_ID(0)][SCP_BUF]-ERR(getBuffer[611]):m_getBuffer failed [bufferIndex=-2, position=2, permission=0]
10-04 20:39:55.226 3105 22151 E ExynosCameraMCPipe: [CAM_ID(0)][PIPE_ISP]-ERR(m_putBuffer[1447]):Buffer manager getBuffer fail, manager(5), frameCount(685), ret(-38)
10-04 20:39:55.226 3105 26107 E ExynosCameraMemoryAllocator: ERR(alloc):dequeue_buffer failed
10-04 20:39:55.226 3105 26107 E ExynosCameraMemoryAllocator: ERR(alloc):dequeue_buffer failed
10-04 20:39:55.226 3105 26107 E ExynosCameraMemoryAllocator: ERR(alloc):dequeue_buffer failed
10-04 20:39:55.226 3105 26107 E ExynosCameraMemoryAllocator: ERR(alloc):dequeue_buffer failed
10-04 20:39:55.226 3105 26107 E ExynosCameraMemoryAllocator: @@@@ERR(alloc):*bufHandle == NULL failed
10-04 20:39:55.226 3105 26107 E ExynosCameraMemoryAllocator: ERR(dequeueBuffer):alloc failed
10-04 20:39:55.227 3105 26107 E ExynosCameraBufferManager: [CAM_ID(0)][SCP_BUF]-ERR(m_bufferCollectorThreadFunc[2294]):dequeueBuffer failed, dequeue(6), collected(0)
10-04 20:39:55.227 3105 22151 E ExynosCameraMCPipe: [CAM_ID(0)][PIPE_ISP]-ERR(m_putBuffer[1410]):New frame is INVALID, frameCount(686)
10-04 20:39:55.227 3105 22151 E ExynosCameraMCPipe: [CAM_ID(0)][PIPE_ISP]-ERR(m_putBuffer[1410]):New frame is INVALID, frameCount(687)
10-04 20:39:55.227 3105 22151 E ExynosCameraMCPipe: [CAM_ID(0)][PIPE_ISP]-ERR(m_putBuffer[1410]):New frame is INVALID, frameCount(688)
10-04 20:39:55.236 3105 3382 E CameraService: notifyError(CAMERA_MSG_ERROR, CAMERA_ERROR_RELEASED)
10-04 20:39:55.236 3105 22150 E ExynosCameraMCPipe: [CAM_ID(0)][PIPE_3AA]-ERR(m_getBuffer[1948]):frameCount(689) : captureNodeCount == 0 || checkRet(0) != NO_ERROR. so, setFrameState(FRAME_STATE_SKIPPED)
10-04 20:39:55.236 3105 22151 E ExynosCameraMCPipe: [CAM_ID(0)][PIPE_ISP]-ERR(m_putBuffer[1410]):New frame is INVALID, frameCount(689)
10-04 20:39:55.243 3105 22157 E Surface : queueBuffer: error queuing buffer to SurfaceTexture, -32
10-04 20:39:55.243 3105 22157 E ExynosCameraMemoryAllocator: ERR(enqueueBuffer):enqueue_buffer failed
10-04 20:39:55.243 3105 22157 E ExynosCameraBufferManager: [CAM_ID(0)][SCP_BUF]-ERR(m_putBuffer[1866]):could not enqueue_buffer [bufIndex=3]
10-04 20:39:55.260 3105 22157 E Surface : queueBuffer: error queuing buffer to SurfaceTexture, -32
10-04 20:39:55.260 3105 22157 E ExynosCameraMemoryAllocator: ERR(enqueueBuffer):enqueue_buffer failed
10-04 20:39:55.260 3105 22157 E ExynosCameraBufferManager: [CAM_ID(0)][SCP_BUF]-ERR(m_putBuffer[1866]):could not enqueue_buffer [bufIndex=4]
10-04 20:39:55.288 3105 22157 E Surface : queueBuffer: error queuing buffer to SurfaceTexture, -32
10-04 20:39:55.288 3105 22157 E ExynosCameraMemoryAllocator: ERR(enqueueBuffer):enqueue_buffer failed
10-04 20:39:55.288 3105 22157 E ExynosCameraBufferManager: [CAM_ID(0)][SCP_BUF]-ERR(m_putBuffer[1866]):could not enqueue_buffer [bufIndex=5]
10-04 20:39:55.296 3105 22150 E ExynosCameraMCPipe: [CAM_ID(0)][PIPE_3AA]-ERR(m_getBuffer[1948]):frameCount(690) : captureNodeCount == 0 || checkRet(0) != NO_ERROR. so, setFrameState(FRAME_STATE_SKIPPED)
10-04 20:39:55.296 3105 22151 E ExynosCameraMCPipe: [CAM_ID(0)][PIPE_ISP]-ERR(m_putBuffer[1410]):New frame is INVALID, frameCount(690)
10-04 20:39:55.317 3105 22157 E Surface : queueBuffer: error queuing buffer to SurfaceTexture, -32
10-04 20:39:55.317 3105 22157 E ExynosCameraMemoryAllocator: ERR(enqueueBuffer):enqueue_buffer failed
10-04 20:39:55.317 3105 22157 E ExynosCameraBufferManager: [CAM_ID(0)][SCP_BUF]-ERR(m_putBuffer[1866]):could not enqueue_buffer [bufIndex=6]
10-04 20:39:55.343 3105 22152 E ExynosCameraMCPipe: [CAM_ID(0)][PIPE_ISP]-ERR(m_getBuffer[1948]):frameCount(683) : captureNodeCount == 0 || checkRet(0) != NO_ERROR. so, setFrameState(FRAME_STATE_SKIPPED)
10-04 20:39:55.356 3105 22150 E ExynosCameraMCPipe: [CAM_ID(0)][PIPE_3AA]-ERR(m_getBuffer[1948]):frameCount(691) : captureNodeCount == 0 || checkRet(0) != NO_ERROR. so, setFrameState(FRAME_STATE_SKIPPED)
10-04 20:39:55.419 3105 3382 E Surface : IGraphicBufferProducer::setBufferCount(0) returned Broken pipe
10-04 20:39:55.419 3105 3382 E ExynosCameraMemoryAllocator: ERR(setBufferCount):set_buffer_count failed [bufCount=0]
10-04 20:39:55.419 3105 3382 E ExynosCameraBufferManager: [CAM_ID(0)][SCP_BUF]-ERR(setBufferCount[2206]):m_allocator->setBufferCount(m_bufferCount(9)
- > 0)
看起来相机缓冲区在某个时刻消失了,想想那是从日志中发生的事情。
由于
答案 0 :(得分:1)
似乎问题在
Mat gray = new Mat();
一行,因为它会在每个新的相机框架上创建新的Mat
。尝试将gray
变量设为全局,并在onCameraViewStarted()
中创建一次,并使用Imgproc.cvtColor()
参数。这样的事情:
public class MainActivity extends AppCompatActivity implements CameraBridgeViewBase.CvCameraViewListener2 {
private Mat mRgba;
private Mat mGray;
...
@Override
public void onCameraViewStarted(int width, int height) {
mGray = new Mat(height, width, CvType.CV_8U);
}
...
@Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
mRgba = inputFrame.rgba();
Imgproc.cvtColor(mRgba, mGray, Imgproc.COLOR_RGB2GRAY);
return mGray;
}
...
}