zoukankan      html  css  js  c++  java
  • Android Opencv NativeCameraView error in 5.0 lollipop versions (Bug #4185)

    https://github.com/opencv/opencv/wiki

    http://code.opencv.org/issues/4185

    Hello,

    I finally get a ride of Android build from sources.
    This is built only for arm devices.

    you can found the libnative_camera_r5.0.0.so here : https://svn.scolring.org/trunk/dependencies/OpenCV/SDK/android/armeabi-v7a/sdk/native/libs/armeabi-v7a/libnative_camera_r5.0.0.so

    the modified camera wrapper :

     .../camera_wrapper/camera_wrapper.cpp              | 62 +++++++++++++++++++---
     1 file changed, 55 insertions(+), 7 deletions(-)
    
    diff --git a/modules/androidcamera/camera_wrapper/camera_wrapper.cpp b/modules/androidcamera/camera_wrapper/camera_wrapper.cpp
    index 202aa29..dafbe64 100644
    --- a/modules/androidcamera/camera_wrapper/camera_wrapper.cpp
    +++ b/modules/androidcamera/camera_wrapper/camera_wrapper.cpp
    @@ -1,6 +1,6 @@
     #if !defined(ANDROID_r2_2_0) && !defined(ANDROID_r2_3_3) && !defined(ANDROID_r3_0_1) && 
      !defined(ANDROID_r4_0_0) && !defined(ANDROID_r4_0_3) && !defined(ANDROID_r4_1_1) && 
    - !defined(ANDROID_r4_2_0) && !defined(ANDROID_r4_3_0) && !defined(ANDROID_r4_4_0)
    + !defined(ANDROID_r4_2_0) && !defined(ANDROID_r4_3_0) && !defined(ANDROID_r4_4_0) && !defined(ANDROID_r5_0_0)
     # error Building camera wrapper for your version of Android is not supported by OpenCV.
      You need to modify OpenCV sources in order to compile camera wrapper for your version of Android.
     #endif
    @@ -8,7 +8,7 @@
     #include <camera/Camera.h>
     #include <camera/CameraParameters.h>
    
    -#if defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3)
    +#if defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3) || defined(ANDROID_r5_0_0)
     # include <system/camera.h>
     #endif //defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3)
    
    @@ -22,7 +22,7 @@
     #elif defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0)
     # include <gui/ISurface.h>
     # include <gui/BufferQueue.h>
    -#elif defined(ANDROID_r4_3_0) || defined(ANDROID_r4_4_0)
    +#elif defined(ANDROID_r4_3_0) || defined(ANDROID_r4_4_0) || defined(ANDROID_r5_0_0)
     # include <gui/IGraphicBufferProducer.h>
     # include <gui/BufferQueue.h>
     # include <ui/GraphicBuffer.h>
    @@ -95,9 +95,25 @@ public:
         {
         }
     };
    +#elif defined(ANDROID_r5_0_0)
    +class ConsumerListenerStub: public android::BnConsumerListener
    +{
    +public:
    +    virtual void onFrameAvailable()
    +    {
    +    }
    +    virtual void onBuffersReleased()
    +    {
    +    }
    +    virtual void onSidebandStreamChanged()
    +    {
    +    }
    +    virtual ~ConsumerListenerStub()
    +    {
    +    }
    +};   
     #endif
    
    -
     std::string getProcessName()
     {
         std::string result;
    @@ -156,6 +172,9 @@ protected:
     #if defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) || defined(ANDROID_r4_3_0) || defined(ANDROID_r4_4_0)
         sp<BufferQueue> queue;
         sp<ConsumerListenerStub> listener;
    +#elif defined(ANDROID_r5_0_0)
    +    sp<IGraphicBufferProducer> queue;
    +    sp<ConsumerListenerStub> listener;
     #endif
         CameraParameters* params;
         CameraCallback cameraCallback;
    @@ -344,7 +363,7 @@ public:
    
         virtual void postData(int32_t msgType, const sp<IMemory>& dataPtr
     #if defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3) || defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) 
    - || defined(ANDROID_r4_3_0) || defined(ANDROID_r4_4_0)
    + || defined(ANDROID_r4_3_0) || defined(ANDROID_r4_4_0) || defined(ANDROID_r5_0_0)
                               ,camera_frame_metadata_t*
     #endif
                               )
    @@ -689,6 +708,21 @@ CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback,
         bufferStatus = handler->camera->setPreviewTarget(handler->queue);
         if (bufferStatus != 0)
             LOGE("applyProperties: failed setPreviewTexture call; camera might not work correctly");
    +# elif defined(ANDROID_r5_0_0)
    +    void* buffer_queue_obj = operator new(sizeof(BufferQueue) + MAGIC_TAIL);
    +
    +    sp<IGraphicBufferProducer> producer;
    +    sp<IGraphicBufferConsumer> consumer;
    +    BufferQueue::createBufferQueue(&producer, &consumer);
    +
    +    consumer->setConsumerUsageBits(GraphicBuffer::USAGE_HW_TEXTURE);
    +    void* consumer_listener_obj = operator new(sizeof(ConsumerListenerStub) + MAGIC_TAIL);
    +    handler->listener = new(consumer_listener_obj) ConsumerListenerStub();
    +    consumer->consumerConnect(handler->listener, true);
    +    handler->queue = producer;
    +    bufferStatus = handler->camera->setPreviewTarget(handler->queue);
    +    if (bufferStatus != 0)
    +        LOGE("applyProperties: failed setPreviewTexture call; camera might not work correctly");
     # endif
    
     #if (defined(ANDROID_r2_2_0) || defined(ANDROID_r2_3_3) || defined(ANDROID_r3_0_1))
    @@ -730,7 +764,7 @@ void CameraHandler::closeCameraConnect()
    
         camera->stopPreview();
     #if defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3) || defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) 
    - || defined(ANDROID_r4_3_0) || defined(ANDROID_r4_4_0)
    + || defined(ANDROID_r4_3_0) || defined(ANDROID_r4_4_0) || defined(ANDROID_r5_0_0)
         camera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_NOOP);
     #endif
         camera->disconnect();
    @@ -1055,7 +1089,7 @@ void CameraHandler::applyProperties(CameraHandler** ppcameraHandler)
             (*ppcameraHandler)->params->setPreviewSize((*ppcameraHandler)->width, (*ppcameraHandler)->height);
    
     #if defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3) || defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) 
    - || defined(ANDROID_r4_3_0) || defined(ANDROID_r4_4_0)
    + || defined(ANDROID_r4_3_0) || defined(ANDROID_r4_4_0) || defined(ANDROID_r5_0_0)
         CameraHandler* handler=*ppcameraHandler;
    
         handler->camera->stopPreview();
    @@ -1092,6 +1126,20 @@ void CameraHandler::applyProperties(CameraHandler** ppcameraHandler)
         bufferStatus = handler->camera->setPreviewTarget(handler->queue);
         if (bufferStatus != 0)
             LOGE("applyProperties: failed setPreviewTexture call; camera might not work correctly");
    +# elif defined(ANDROID_r5_0_0)
    +    void* buffer_queue_obj = operator new(sizeof(BufferQueue) + MAGIC_TAIL);
    +    sp<IGraphicBufferProducer> producer;
    +    sp<IGraphicBufferConsumer> consumer;
    +    BufferQueue::createBufferQueue(&producer, &consumer);
    +
    +    consumer->setConsumerUsageBits(GraphicBuffer::USAGE_HW_TEXTURE);
    +    void* consumer_listener_obj = operator new(sizeof(ConsumerListenerStub) + MAGIC_TAIL);
    +    handler->listener = new(consumer_listener_obj) ConsumerListenerStub();
    +    consumer->consumerConnect(handler->listener, true);
    +    handler->queue = producer;
    +    bufferStatus = handler->camera->setPreviewTarget(handler->queue);
    +    if (bufferStatus != 0)
    +        LOGE("applyProperties: failed setPreviewTexture call; camera might not work correctly");
     # endif
    
         handler->camera->setPreviewCallbackFlags( CAMERA_FRAME_CALLBACK_FLAG_ENABLE_MASK | CAMERA_FRAME_CALLBACK_FLAG_COPY_OUT_MASK);//with copy
    
  • 相关阅读:
    Zabbix Server 和 Zabbix Agentd 开机自动运行
    nginx+keepalive实现高可用负载均衡
    zabbix添加对web页面url的状态监控
    Zabbix当内存剩余不足10%的时候触发报警
    zabbix cpu监控介绍
    bash小结
    数据库知识入门
    MySQL简单管理
    python环境
    paramiko实现putty功能
  • 原文地址:https://www.cnblogs.com/jukan/p/6673898.html
Copyright © 2011-2022 走看看