• 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
    
  • 相关阅读:
    Block详解二(底层分析)
    Block详解一(底层分析)
    Swift 属性与汇编分析inout本质
    Swift --闭包表达式与闭包(汇编分析)
    Swift--struct与class的区别(汇编角度底层分析)
    Swift 枚举-从汇编角度看枚举内存结构
    Swift -POP( 面向协议编程)与OOP(面向对象编程)
    从零开始的计算机网络基础(图文并茂,1.8w字,面试复习必备)
    浅谈js数据类型
    js数组冷知识
  • 原文地址:https://www.cnblogs.com/jukan/p/6673898.html
Copyright © 2020-2023  润新知