高通第三方算法(单帧数据)添加流程---hal1/hal3

这篇文档写了很久了,当时脑袋打结用的英文,懒得改成中文了,将就看下,如有错误请指正,谢谢

高通第三方算法(单帧数据)添加流程---hal1/hal3_第1张图片高通第三方算法(单帧数据)添加流程---hal1/hal3_第2张图片高通第三方算法(单帧数据)添加流程---hal1/hal3_第3张图片

上图是我总结的高通camera架构。下面介绍怎么添加单帧的算法,其实就是对单帧数据进行处理。

Add 3rd algorithm of singleframe:

 

As we known,camera consists ofthree parts:preview,capture and video。

If we want to Add 3rdalgorithm,we must find out the data callbacked to the HAL that processed by ISP。

 

callback file:hardware\qcom\camera\QCamera2\HAL\QCamera2HWICallbacks.cpp

 

Preview/Video callback:

voidQCamera2HardwareInterface::synchronous_stream_cb_routine(

       mm_camera_super_buf_t *super_frame,QCameraStream * stream,

       void *userdata)

 

Capture callback:

voidQCamera2HardwareInterface::zsl_channel_cb(mm_camera_super_buf_t*recvd_frame,

 void *userdata)

voidQCamera2HardwareInterface::postproc_channel_cb_routine(mm_camera_super_buf_t*recvd_frame, void *userdata)

 

The key is the structure mm_camera_super_buf_t,next show the struct of it。

 

typedef struct {

   uint32_t camera_handle;

    uint32_tch_id;

   uint32_t num_bufs;

   uint8_t bUnlockAEC;

   uint8_t bReadyForPrepareSnapshot;

    mm_camera_buf_def_t* bufs[MAX_STREAM_NUM_IN_BUNDLE];

} mm_camera_super_buf_t;

 

The buffer is inside in struct mm_camera_buf_def;

 

typedef struct mm_camera_buf_def {

   uint32_t stream_id;

   cam_stream_type_t stream_type;

   cam_stream_buf_type buf_type;

   uint32_t buf_idx;

   uint8_t is_uv_subsampled;

   struct timespec ts;

   uint32_t frame_idx;

   union {

       mm_camera_plane_buf_def_t planes_buf;

       mm_camera_user_buf_def_t user_buf;

   };

   int fd;

void *buffer;//this stored the data of frame,we shouldoperate it

   size_t frame_len;

   void *mem_info;

   uint32_t flags;

} mm_camera_buf_def_t;


(Samplecode)Add Face Detection Algorithm:

这里面的so文件就是我们的算法库,通过dlopen函数对其进行操作。

在最开始需要定义:typedef int (*CAC_FUNC)(unsigned char *data, int width, int height);这个与算法接口是对应的。

也需要加入头文件:#include “dlfcn.h"

高通第三方算法(单帧数据)添加流程---hal1/hal3_第4张图片


Position:Because realize FaceDetection just need to operate the buffer (one frame)that stored the data inthe forms of YUV420,so we can add Face Detection Algorithm everywhere in the function synchronous_stream_cb_routine。


Add algorithm step by step:

1:Realize FaceDetection。

高通第三方算法(单帧数据)添加流程---hal1/hal3_第5张图片

2:The Face Detection Algorithm depend on opencv lib。Compile it to be a so file (libmy.so) linked with libopencv_java3.so, then it will be private。

3:Push the related lib to the correct dir of your machine。
haarcascade_frontalface_alt2.xml---->system/vendor/lib/haarcascade_frontalface_alt2.xml
libopencv_java3.so            ---->/system/vendor/lib/libopencv_java3.so

libmy.so                     ---->/system/vendor/lib/libmy.so


以上是跑的hal1通道,如果跑的hal3通道的话,需要设置hal3 enable。(高通自带的相机就算打开hal3也是跑的hal1,应该是不支持hal3的,需另装apk)

设置命令是:adb shell setprop persist.camera.HAL3.enabled 1

 

Hal3的回调文件是:Qcamera3Channel.cpp

 

预览的回调是在:

voidQCamera3ProcessingChannel::streamCbRoutine(mm_camera_super_buf_t *super_frame,

       QCamera3Stream *stream)

拍照的回调是在:

voidQCamera3PicChannel::streamCbRoutine(mm_camera_super_buf_t *super_frame,

                           QCamera3Stream*stream)

高通第三方算法(单帧数据)添加流程---hal1/hal3_第6张图片

如上图所示就是在预览回调函数里面处理buffer,实现预览变灰的效果。


你可能感兴趣的:(camera,算法)