You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

546 lines
14 KiB

/*******************************************************************************
* vproc.h
*
* History:
* 2018/08/03 - [Hao Wang] created for CV22
*
* Copyright (c) 2018 Ambarella, Inc.
*
* This file and its contents ( "Software" ) are protected by intellectual
* property rights including, without limitation, U.S. and/or foreign
* copyrights. This Software is also the confidential and proprietary
* information of Ambarella, Inc. and its licensors. You may not use, reproduce,
* disclose, distribute, modify, or otherwise iproare derivative works of this
* Software or any portion thereof except pursuant to a signed license agreement
* or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates.
* In the absence of such an agreement, you agree to promptly notify and return
* this Software to Ambarella, Inc.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT,
* MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; COMPUTER FAILURE OR MALFUNCTION; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************/
#ifndef _VPROC_H_
#define _VPROC_H_
#ifdef __cplusplus
extern "C" {
#endif
#define IN
#define OUT
#define IN_OUT
struct vproc_version {
uint32_t major;
uint32_t minor;
uint32_t patch;
unsigned int mod_time;
char description[64];
};
typedef enum data_type_s {
DT_FX8 = 0,
DT_FX16 = 1,
DT_FP16 = 2,
} data_type_t;
typedef enum color_space_s {
/* General vector*/
CS_VECT = 0,
/* RGB list*/
CS_RGB = 1, // AMB RGB format, refering to plane-interleaved RGB data
CS_BGR = 2, // AMB BGR format, refering to plane-interleaved BGR data
CS_RGB_ITL = 3, // OpenCV RGB format, refering to element-interleaved RGB data
CS_BGR_ITL = 4, // OpenCV BGR format, refering to element-interleaved BGR data
CS_RGB_LAST,
CS_RGB_FIRST = CS_RGB,
/* YUV list*/
CS_NV12 = 10, // NV12 data
CS_Y = 11, // single channel, i.e. y data
CS_ITL = 12, // element-interleaved channel, i.e. uv data
CS_YUV_LAST,
CS_YUV_FIRST = CS_NV12,
} color_space_t;
typedef enum cvt_code_s {
FX8_2_FX8 = 0,
FX8_2_FX16 = 1,
FX8_2_FP16 = 2,
FX16_2_FX16 = 3,
FX16_2_FX8 = 4,
FX16_2_FP16 = 5,
FP16_2_FP16 = 6,
FP16_2_FX8 = 7,
FP16_2_FX16 = 8,
FP32_2_FX8 = 9,
FP32_2_FX16 = 10,
FP32_2_FP16 = 11,
FX8_2_FP32 = 12,
FX16_2_FP32 = 13,
FP16_2_FP32 = 14,
FP32_2_FP32 = 15,
} cvt_code_t;
typedef struct roi_area_s {
uint32_t xoffset; // start x postion
uint32_t yoffset; // start y position
uint32_t width; // width of ROI
uint32_t height; // height of ROI
} roi_area_t;
typedef struct vect_shape_s {
uint32_t p; // PLANE
uint32_t d; // DEPTH
uint32_t h; // HEIGHT
uint32_t w; // WIDTH
} vect_shape_t;
typedef struct data_format_s{
int8_t sign; // Sign bit: 0 for unsigned, 1 for sined
int8_t datasize; // 0 for 8bit, 1 for 16bit
int8_t exp_offset; // Q value for quantized data
int8_t exp_bits; // exp bits for floating point
} data_format_t;
typedef struct vect_desc_s {
uint32_t data_addr;
uint32_t pitch;
vect_shape_t shape;
data_format_t data_format;
color_space_t color_space;
roi_area_t roi;
} vect_desc_t;
typedef struct deformation_extra_s {
int32_t uv_offset;
} deformation_extra_t;
typedef struct polish_extra_s {
vect_desc_t *mean;
float scale;
} polish_extra_t;
/* Define yuv2rgb_mat as below
[R G B]T = [yc 0 rv; yc -gu -gv; yc bu 0] x [Y-yb U-128 V-128]T
Default values:
yc = 1
rv = 1.402
gu = 0.344136
gv = 0.714136
bu = 1.772
yb = 0
*/
typedef struct yuv2rgb_mat_s {
float yc;
float rv;
float gu;
float gv;
float bu;
float yb;
} yuv2rgb_mat_t;
typedef struct harris_cfg_s {
float threshold;
uint32_t nms_size;
} harris_cfg_t;
typedef struct optlk_cfg_s {
float resp_threshold; //resp = r1*r2 - k * (r1 + r2)^2
int32_t with_k; //one: k=0.04, zero: k=0
} optlk_cfg_t;
typedef struct bw_cfg_s {
int32_t with_abs; //zero: no-abs non-zero:with-abs
float bw_threshold;
uint32_t compare_method; //0:> 1:< 2:>= 3:<= 4:== 5:!=
uint8_t black_value;
uint8_t white_value;
} bw_cfg_t;
#ifndef AMBA_API
#define AMBA_API __attribute__((visibility("default")))
#endif
/* Get vproc libarary version
*/
AMBA_API int vproc_get_version(struct vproc_version *ver);
/* Init vproc libarary
@param bin_name Bin file to load.
@param size Avaiable size for bin loading.
*/
AMBA_API int vproc_init(IN const char *bin_name,
IN_OUT uint32_t *size);
/* Init vproc libarary
@param virt Virtual address that keeps vproc bin data.
@param size Avaiable size for bin loading.
*/
AMBA_API int vproc_init_from_mem(void *feed_virt,
IN_OUT uint32_t *size);
/* Load vproc libarary
@param fd_cavalry
@param virt_addr Virtual address to load bin.
@param phy_addr Start address to load bin.
@param size Malloced dram size.
*/
AMBA_API int vproc_load(IN int fd_cavalry,
IN uint8_t *virt_addr,
IN uint32_t phy_addr,
IN uint32_t size);
/* Exit vproc libarary
*/
AMBA_API int vproc_exit();
/* Run vproc_crop, cropping area is the ROI in input vector.
@param src Input vector.
@param dst Output vector.
*/
AMBA_API int vproc_crop(IN vect_desc_t *src,
OUT vect_desc_t *dst);
/* Run vproc_resize_vect_batch
@param src Input vector.
@param dst Output vector.
@param batch_num Number of loop.
*/
AMBA_API int vproc_resize_vect_batch(vect_desc_t *src_vect,
vect_desc_t *dst_vect, int count);
/* Run vproc_resize
@param src Input vector.
@param dst Output vector.
*/
AMBA_API int vproc_resize(IN vect_desc_t *src,
OUT vect_desc_t *dst);
/* Run vproc_resize_single_channel. Support one channel data which could be
Y-Channel, R-Channel, G-Channel, B-Channel and so on.
@param src Input vector.
@param dst Output vector.
*/
AMBA_API int vproc_resize_single_channel(IN vect_desc_t *src,
OUT vect_desc_t *dst);
/* Run vproc_resize_interleave_channel. Support 2-channel interleaved whick
looks like:
UVUVUVUVUVUV
UVUVUVUVUVUV
UVUVUVUVUVUV
@param src Input vector.
@param dst Output vector.
*/
AMBA_API int vproc_resize_interleave_channel(IN vect_desc_t *src,
OUT vect_desc_t *dst);
/* Run vproc_yuv2rgb_420
@param y Y-Channel data.
@param uv UV-Channle data.
@param rgb RGB-Channel data.
@param yuv2rgb_mat YUV to RGB conversion matrix.
*/
AMBA_API int vproc_yuv2rgb_420(IN vect_desc_t *y,
IN vect_desc_t *uv,
OUT vect_desc_t *rgb,
IN yuv2rgb_mat_t *yuv2rgb_mat);
/* Run vproc_submean
@param src Input vector.
@param mean Mean data.
@param dst Ouput data.
*/
AMBA_API int vproc_submean(IN vect_desc_t *src,
IN vect_desc_t *mean,
OUT vect_desc_t *dst);
/* Run vproc_scale_ext
@param src Input data.
@param dst Ouput data.
@param scl scale factor.
*/
AMBA_API int vproc_scale_ext(IN vect_desc_t *src,
OUT vect_desc_t *dst,
IN float scl);
/* Run vproc_dtcvt
@param src Input data.
@param dst Ouput data.
*/
AMBA_API int vproc_dtcvt(IN vect_desc_t *src,
OUT vect_desc_t *dst);
/* Run vproc_rotate
@param src Input data.
@param dst Ouput data.
@param rotate_flip_bitmap Input rotate_flip_bitmap.
4: pflip; 3: dflip; 2: vflip; 1: hflip; 0: rotate. E.g. vflip+rotate: 0x05 (00101)
*/
AMBA_API int vproc_rotate(IN vect_desc_t *src,
OUT vect_desc_t *dst, IN uint32_t src_rotate_flip_bitmap);
/* Run vproc_imcvt
@param src Input data.
@param dst Ouput data.
*/
AMBA_API int vproc_imcvt(IN vect_desc_t *src,
OUT vect_desc_t *dst);
/* Run vproc_10bitpackedfx16_to_uint16
@param src Input data.
@param dst Ouput data.
*/
AMBA_API int vproc_10bitpacked_to_uint16(IN vect_desc_t *src,
OUT vect_desc_t *dst);
/* Run vproc_image_deformation
A high-level API handles image deformation operations, such as yuv2rgb,
resize which internally calls low-level APIs.
*/
AMBA_API int vproc_image_deformation(IN vect_desc_t *src,
OUT vect_desc_t *dst, IN deformation_extra_t *dext);
/* Run vproc_data_polish
A high-level API handles data pre-processing operations, such as
mean subtraction, scale, data format conversion, which internally
calls low-level APIs.
*/
AMBA_API int vproc_data_polish(IN vect_desc_t *src,
OUT vect_desc_t *dst, IN polish_extra_t *pext);
/* Run vproc_harris
@param im_vect Input data.
@param threshold Harris Point select threshold.
@param det_bit_vect Ouput data.
@param resp_vect the harris reponse.
@param maxresp_vect the peak of the harris reponse.
*/
AMBA_API int vproc_harris(IN vect_desc_t *im_vect, IN float threshold,
OUT vect_desc_t *det_bit_vect, OUT vect_desc_t *resp_vect, OUT vect_desc_t *maxresp_vect);
/* Run vproc_harris
@param im_vect Input data.
@param harris_param, include threshold, nms window size.
@param det_bit_vect Ouput data.
@param resp_vect the harris reponse.
@param maxresp_vect the peak of the harris reponse.
*/
AMBA_API int vproc_harris_ext(IN vect_desc_t *im_vect, IN harris_cfg_t *harris_param,
OUT vect_desc_t *det_bit_vect, OUT vect_desc_t *resp_vect, OUT vect_desc_t *maxresp_vect);
/* Run vproc_cvfilter_init
@param None.
perfom to initilize the cvfilter module
*/
AMBA_API int vproc_cvfilter_init(void);
/* Run vproc_cvfilter_release
@param None.
perfom to release the resource from cvfilter module
*/
AMBA_API int vproc_cvfilter_release(void);
/* Run vproc_cvfilter
@param im_vect Input data.
@param ker_vect kernel vector.
@param out_vect Ouput data.
*/
AMBA_API int vproc_cvfilter(IN vect_desc_t *im_vect, IN float* ker_content,
IN uint32_t ker_h, IN uint32_t ker_w, OUT vect_desc_t *out_vect);
/* Run vproc_lpcvfilter
@param im_vect Input data.
@param ker_vect kernel vector.
@param out_vect Ouput data.
*/
AMBA_API int vproc_lpcvfilter(IN vect_desc_t *im_vect, IN float* ker_content,
IN uint32_t ker_h, IN uint32_t ker_w, OUT vect_desc_t *out_vect);
/* Run vproc_morph_init
@param None.
perfom to initilize the morph module
*/
AMBA_API int vproc_morph_init(void);
/* Run vproc_morph_release
@param None.
perfom to release the resource from morph module
*/
AMBA_API int vproc_morph_release(void);
/* Run vproc_morph
@param im_vect Input data.
@param out_vect Ouput data.
@param morph_h height of morph kernel.
@param morph_w width of morph kernel.
@param ker_data kernel data.
@param morph_method morph method selection.
*/
AMBA_API int vproc_morph(IN vect_desc_t *im_vect, OUT vect_desc_t *out_vect,
IN int morph_h, IN int morph_w, IN float* ker_data, IN int morph_method);
/* Run vproc_perspect_init
@param im_h input height.
@param im_w input width.
*/
AMBA_API void* vproc_perspect_init(IN int im_h, IN int im_w);
/* Run vproc_perspect_release
@param handler.
*/
AMBA_API int vproc_perspect_release(IN void* handler);
/* Run vproc_perspect_load_warp_mat
@param handler.
@param prj_mat_vect Perspective Matrix.
*/
AMBA_API int vproc_perspect_load_warp_mat(IN void* handler, IN vect_desc_t *prj_mat_vect);
/* Run vproc_perspect_warp
@param handler.
@param im_src input image.
@param warp_out warp out image.
*/
AMBA_API int vproc_perspect_warp(IN void* handler, IN vect_desc_t *im_src, OUT vect_desc_t *warp_out);
/* Run vproc_optlk_init
@param None.
perfom to initilize the optical LK module
*/
AMBA_API int vproc_optlk_init(void);
/* Run vproc_optlk_release
@param None.
perfom to release the resource from optical LK module
*/
AMBA_API int vproc_optlk_release(void);
/* Run vproc_optlk
@param im0_vect.
@param im1_vect.
@param optwin_coeff.
@param optwin_h
@param optwin_w
@param opt_param.
@param dxy_vect.
@param peak_vect.
*/
AMBA_API int vproc_optlk(IN vect_desc_t *im0_vect, IN vect_desc_t *im1_vect,
IN float* optwin_data, IN uint32_t optwin_h, IN uint32_t optwin_w, IN optlk_cfg_t *opt_param,
OUT vect_desc_t *dxy_vect, OUT vect_desc_t *peak_vect);
/* Run vproc_cdist_init
@param None.
perfom to initilize the cdist(cosine distance) module
*/
AMBA_API int vproc_cdist_init(void);
/* Run vproc_cdist_release
@param None.
perfom to release the resource from cdist(cosine distance) module
*/
AMBA_API int vproc_cdist_release(void);
/* Run vproc_cdist
@param in1_vect , intput vector 1
@param in2_vect, input vector 2
@param cdist_val, output cosine distance value
*/
AMBA_API int vproc_cdist(IN vect_desc_t *in1_vect, IN vect_desc_t *in2_vect, OUT float *cdist_val);
/* Run vproc_imhist
@param grayim_vect, input grayscale image data vector
@param histout_vect, output histogram bins vector
*/
AMBA_API int vproc_imhist(IN vect_desc_t *grayim_vect, OUT vect_desc_t *histout_vect);
/* Run vproc_bw
@param im_vect input 2D vector.
@param bw_vect output black-white map.
@param param config parameters.
*/
AMBA_API int vproc_bw(IN vect_desc_t *im_vect, OUT vect_desc_t *bw_vect, IN bw_cfg_t* param);
/* Run vproc_memcpy
@param dst_phy_addr Destination data physical address.
@param src_phy_addr Source data physical address.
@param size copy size.
*/
AMBA_API int vproc_memcpy(IN uint32_t dst_phy_addr, IN uint32_t src_phy_addr, IN uint32_t size);
/* Run dsi_split_query
@param input dsi_u16's width
@param input dsi_u16's height
@param required size
*/
AMBA_API void dsi_split_query(IN uint32_t dsi_w, IN uint32_t dsi_h, OUT uint32_t *size);
/* Run dsi_split_run
@param input dsi_u16 vector descriptor
@param physical address allocated for dsi_split
@param virtual address allocated for dsi_split
@param msb_stream info
@param lsb_stream info
*/
AMBA_API int dsi_split_run(IN vect_desc_t *dsi_u16, IN uint32_t dsi_split_mem,
IN void *dsi_split_virt, OUT vect_desc_t *msb_stream, OUT vect_desc_t *lsb_stream);
#ifdef __cplusplus
}
#endif
#endif