Android Opencv NativeCameraView error in 5.0 lollipop versions (Bug #4185)
Description
I am working on Android OpenCV based application. I am not able to run NativeCameraView on my MotoG after 5.0 lollipop update. The JavaCameraView is still working.
In my program I need to use VideoCapture (http://docs.opencv.org/java/2.4.2/index.html?org/opencv/highgui/VideoCapture.html) in my program. I dont know how do I switch to JavaCameraView Source in VideoCapture. [Only NativeCamera works fine for my Application. Using JavaCameraView is just a temporary workaround which I am looking for]
So my question is, Is this a bug on OpenCV to fix the Native Camera for 5.0 ? I did not find anybody raising such an issue. When will this be fixed ?
02-06 13:30:52.794: E/OpenCV::camera(31745): CameraWrapperConnector::connectToLib ERROR: cannot dlopen camera wrapper library 02-06 13:30:52.794: E/OpenCV::camera(31745): Native_camera returned opening error: 4
http://stackoverflow.com/questions/28361300/opencv-native-camera-view-on-android-5-0-not-working
History
Updated by Vadim Pisarevsky almost 10 years ago
- Category set to android
Updated by Bastien Bourineau almost 10 years ago
Most people use Android JavaCameraView but yes using full native camera on Android 5.0+ seems to not be supported yet :/
Please provide a libnative_camera_r5.0.0.so for Native developers like us.
Until now I didn't had to use any java code this is a bit frustrating to do not have this feature ^^
If someone have an environment to build Android already set and build the libnative_camera library...
- Target version set to 2.4.12
Updated by Bastien Bourineau almost 10 years ago
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
- % Done changed from 0 to 20
Updated by Maksim Shabunin almost 10 years ago
Please, note, that native camera support has been removed since OpenCV 3.0. This module depends on private Android headers which can be changed in any Android version and by any device vendor making reliable support almost impossible. Furthermore, it has been reported that Java version works quite well in current popular Android versions.
Updated by Bastien Bourineau over 9 years ago
Yes I saw that bad news :/
Is there in simple sample to control the camera and get data from ndk through jni java interface ?
Updated by Maksim Shabunin over 9 years ago
Do you mean something like this: https://github.com/Itseez/opencv/tree/master/samples/android/tutorial-2-mixedprocessing ?
The recommended way is to get frame via Android camera interface and then process it using your native library.
Updated by Bastien Bourineau over 9 years ago
Yes something like that :)
Thanks
Updated by Abhijat Biswas over 9 years ago
Is it enough to add this into the reference library? Do we need to update our OpenCV manager on the phone as well?
Updated by Maksim Shabunin over 9 years ago
Issue has been transferred to GitHub: https://github.com/Itseez/opencv/issues/4929