gpt4 book ai didi

android - 在 Android 上为 OpenCV 设置相机场景模式

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:44:05 27 4
gpt4 key购买 nike

我正在寻找一种从 C++ (Android NDK) 为网络摄像头设置场景模式值的方法。

OpenCV 在初始化时从网络摄像头获取值。在下面的日志中,日志显示 Supported Scene Modes: auto,action,portrait,landscape,beach,fireworks,night,night-portrait,snow,sports,steadyphoto,sunset,theatre,barcode

我想为相机设置其中一个值(例如海滩)。

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

示例代码(与我使用的代码不完全相同):

  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();

最佳答案

唯一的问题是 Android NDK 没有任何标准化的 API 来处理相机。有必要通过 Java,因为 NDK 访问将特定于特定硬件。

虽然在 OpenCV 的 C++ 接口(interface)中有一个 VideoCapture 类,如果您实现 Native Activity 方法,您可以使用它,但是由于 NDK 不提供从 native 代码访问相机的 API,所以 VideoCapture 使用未记录的接口(interface),这使得 VideoCapture 不通用。它不适用于某些旧设备或新设备。看看OpenCV原生相机的问题here .

我建议使用 setSceneMode(String value)在托管端,您还可以从 native 端发送请求以管理设置场景模式,从而在 SCENE_MODE_# 之间进行转换。在托管端和 native 端的相应枚举(您应该自己实现)。

顺便说一句,这里是 Android 相机的属性(VideoCaptureset() 方法):videoio.hpp #L263 - #L325


更新 #1:

您可以尝试扩展 OpenCV 的 camera_wrapper 的功能通过 CameraParameters设置场景模式(如焦点或白平衡),但某些 Android 版本之间可能存在差异。

另外请注意,您必须将 androidcamera 模块编译到所有 Android 版本才能开始使用它们。这就是为什么您在文件夹 OPENCV_ANDROID_PATH\sdk\native\libs\armeabi-v7a 下看到很多 libnative_camera_r#.#.#.so 的原因。

关于android - 在 Android 上为 OpenCV 设置相机场景模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28821988/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com