Set Camera Scene Mode for OpenCV on Android

I am looking for a way to set the scene mode value for a C ++ webcam (Android NDK).

OpenCV gets the values ​​from the webcam when it is initialized. In the magazine below, the magazine says Supported Scene Modes: auto,action,portrait,landscape,beach,fireworks,night,night-portrait,snow,sports,steadyphoto,sunset,theatre,barcode .

I would like to set one of the values ​​(e.g. beach) for the camera.

 D/OpenCV::camera﹕ CvCapture_Android::CvCapture_Android(1) D/OpenCV::camera﹕ Library name: libopencv_java.so D/OpenCV::camera﹕ Library base address: 0x69f3b000 D/OpenCV::camera﹕ Libraries folder found: /data/app-lib/gms.rewards.selfie-2/ D/OpenCV::camera﹕ CameraWrapperConnector::connectToLib: folderPath=/data/app-lib/gms.rewards.selfie-2/ E/OpenCV::camera﹕ ||libnative_camera_r4.1.1.so E/OpenCV::camera﹕ ||libnative_camera_r4.0.3.so E/OpenCV::camera﹕ ||libnative_camera_r2.3.3.so E/OpenCV::camera﹕ ||libnative_camera_r4.2.0.so E/OpenCV::camera﹕ ||libnative_camera_r2.2.0.so E/OpenCV::camera﹕ ||libnative_camera_r3.0.1.so E/OpenCV::camera﹕ ||libnative_camera_r4.3.0.so E/OpenCV::camera﹕ ||libnative_camera_r4.0.0.so E/OpenCV::camera﹕ ||libnative_camera_r4.4.0.so D/OpenCV::camera﹕ try to load library 'libnative_camera_r4.4.0.so' D/OpenCV::camera﹕ CameraWrapperConnector::connectToLib ERROR: cannot dlopen camera wrapper library /data/app-lib/gms.rewards.selfie-2/libnative_camera_r4.4.0.so, dlerror="Cannot load library: soinfo_relocate(linker.cpp:975): cannot locate symbol "_ZN7android17IConsumerListenerD2Ev" referenced by "libnative_camera_r4.4.0.so"..." D/OpenCV::camera﹕ try to load library 'libnative_camera_r4.3.0.so' D/OpenCV::camera﹕ CameraWrapperConnector::connectToLib ERROR: cannot dlopen camera wrapper library /data/app-lib/gms.rewards.selfie-2/libnative_camera_r4.3.0.so, dlerror="Cannot load library: soinfo_relocate(linker.cpp:975): cannot locate symbol "_ZN7android6Camera17setPreviewTextureERKNS_2spINS_22IGraphicBufferProducerEEE" referenced by "libnative_camera_r4.3.0.so"..." D/OpenCV::camera﹕ try to load library 'libnative_camera_r4.2.0.so' D/OpenCV::camera﹕ Loaded library '/data/app-lib/gms.rewards.selfie-2/libnative_camera_r4.2.0.so' D/OpenCV_NativeCamera﹕ CameraHandler::initCameraConnect(0x6a64eb6d, 1, 0x69359e18, 0x0) D/OpenCV_NativeCamera﹕ Connecting to CameraService v 2.3 D/OpenCV_NativeCamera﹕ Instantiated new CameraHandler (0x6a64eb6d, 0x69359e18) I/OpenCV_NativeCamera﹕ initCameraConnect: [antibanding=auto;antibanding-values=off,auto,50hz,60hz;auto-exposure-lock=false;auto-exposure-lock-supported=true;auto-exposure-lock-values=false,true;auto-whitebalance-lock=false;auto-whitebalance-lock-supported=true;auto-whitebalance-lock-values=false,true;effect=none;effect-values=mono,negative,none,posterize,sepia,aqua,solarize,nv-vivid,nv-emboss;exposure-compensation-step=0.1;flash-mode=off;flash-mode-values=off,on,auto,torch,red-eye;focal-length=1.000;focus-areas=(0,0,0,0,0);focus-distances=0.95,1.9,Infinity;focus-mode=fixed;focus-mode-values=fixed;horizontal-view-angle=60.000;jpeg-quality=95;jpeg-thumbnail-height=240;jpeg-thumbnail-quality=90;jpeg-thumbnail-size-values=0x0,320x240,240x320;jpeg-thumbnail-width=320;max-exposure-compensation=20;max-num-detected-faces-hw=10;max-num-focus-areas=0;max-num-metering-areas=4;max-zoom=28;metering-areas=(0,0,0,0,0);min-exposure-compensation=-20;picture-format=jpeg;picture-format-values=jpeg,jfif,exif,yuv420p,yuv420sp;picture-size=1280x960;pic D/OpenCV_NativeCamera﹕ Supported Cameras: (null) D/OpenCV_NativeCamera﹕ Supported Picture Sizes: 320x240,480x480,640x368,640x480,800x600,960x720,1024x768,1280x720,1280x752,1280x960,1440x1080,1600x1200,1836x1080,1920x1080,2048x1152,2048x1360,2048x1536,2592x1456,2592x1520,2592x1920,2592x1944 D/OpenCV_NativeCamera﹕ Supported Picture Formats: jpeg,jfif,exif,yuv420p,yuv420sp D/OpenCV_NativeCamera﹕ Supported Preview Sizes: 176x144,320x240,352x288,480x480,640x480,704x576,720x408,720x480,720x576,768x432,800x448,960x720,1280x720,1280x752,1280x960,1360x720,1440x1080,1920x1080,1920x1088,1920x1440 D/OpenCV_NativeCamera﹕ Supported Preview Formats: yuv420p,yuv420sp D/OpenCV_NativeCamera﹕ Supported Preview Frame Rates: 5,8,10,15,20,24,25,30 D/OpenCV_NativeCamera﹕ Supported Thumbnail Sizes: 0x0,320x240,240x320 D/OpenCV_NativeCamera﹕ Supported Whitebalance Modes: auto,incandescent,fluorescent,warm-fluorescent,daylight,cloudy-daylight,shade,twilight D/OpenCV_NativeCamera﹕ Supported Effects: mono,negative,none,posterize,sepia,aqua,solarize,nv-vivid,nv-emboss D/OpenCV_NativeCamera﹕ Supported Scene Modes: auto,action,portrait,landscape,beach,fireworks,night,night-portrait,snow,sports,steadyphoto,sunset,theatre,barcode D/OpenCV_NativeCamera﹕ Supported Focus Modes: fixed D/OpenCV_NativeCamera﹕ Supported Antibanding Options: off,auto,50hz,60hz D/OpenCV_NativeCamera﹕ Supported Flash Modes: off,on,auto,torch,red-eye D/OpenCV_NativeCamera﹕ initCameraConnect: preview format is set to yuv420sp D/OpenCV_NativeCamera﹕ Starting preview D/OpenCV_NativeCamera﹕ Preview started successfully 

Code Example (Not the same code I use):

  cv::Mat inframe = cv::Mat(); cv::VideoCapture mCamera; mCamera.open(1); mCamera.set(CV_CAP_PROP_FRAME_WIDTH, 400); mCamera.set(CV_CAP_PROP_FRAME_HEIGHT, 300); // mCamera.set("scene mode", "beach"); // <-- looking for a way while (mCamera.isOpened()) { bool grab = mCamera.grab(); if (grab) { mCamera.retrieve(inframe, CV_CAP_ANDROID_COLOR_FRAME_RGB); // To do something for the iframe } else { LOGE("--->Cannot grab a frame from camera."); } } mCamera.release(); 
+5
source share
2 answers

The only problem is that there is no standardized API for handling Android NDK cameras. It is necessary to go through Java, as access to the NDK will be specific to specific equipment.

Although the OpenCV C ++ interface has a VideoCapture class, you can use it if you implement the Native Activity approach, but since the NDK does not provide an API for accessing the camera from native code, therefore VideoCapture uses undocumented interfaces, which makes VideoCapture not universal. It does not work on some old or new devices. Just take a look at the problems with the native OpenCV camera here .

I suggest using setSceneMode(String value) on the managed side, you can also send a request from the native side to control the scene mode thus doing a conversion between SCENE_MODE_# on the managed side and the corresponding enumerations on the native side (you have to implement yourself).

By the way, these are properties for Android cameras ( VideoCapture set() method): videoio.hpp # L263 - # L325


Update # 1:

You can try to extend the OpenCV camera_wrapper CameraParameters functions to set the scene mode (for example, focus or white balance), but there may be differences between some versions of Android.

Also note that you need to compile the androidcamera module for all versions of Android in order to work with them. That's why you see a lot of libnative_camera_r#.#.#.so in the OPENCV_ANDROID_PATH\sdk\native\libs\armeabi-v7a .

+4
source

After many tests, I found that one of the answers is abandoning OpenCV. This means direct control of the V4L2.

https://github.com/openxc/android-webcam

http://www.linuxtv.org/downloads/legacy/video4linux/API/V4L2_API/spec-single/v4l2.html

0
source

Source: https://habr.com/ru/post/1214514/


All Articles