1 #ifndef __PANORAMA_STITCHINGAPP_H__ 2 #define __PANORAMA_STITCHINGAPP_H__ 3 4 #include <stdint.h> 5 6 #ifdef __cplusplus 7 extern "C" { 8 #endif 9 10 11 #if defined _WIN32 || defined __CYGWIN__ 12 #ifdef BUILDING_DLL 13 #ifdef __GNUC__ 14 #define DLL_PUBLIC __attribute__ ((dllexport)) 15 #else 16 // Note: actually gcc seems to also supports this syntax. 17 #define DLL_PUBLIC __declspec(dllexport) 18 #endif 19 #else 20 #ifdef __GNUC__ 21 #define DLL_PUBLIC __attribute__ ((dllimport)) 22 #else 23 // Note: actually gcc seems to also supports this syntax. 24 #define DLL_PUBLIC 25 #endif 26 #define DLL_LOCAL 27 #endif 28 #else 29 #if __GNUC__ >= 4 30 #define DLL_PUBLIC __attribute__ ((visibility ("default"))) 31 #define DLL_LOCAL __attribute__ ((visibility ("hidden"))) 32 #else 33 #define DLL_PUBLIC 34 #define DLL_LOCAL 35 #endif 36 #endif 37 38 /* 39 * @enum RK_PS_RETURN_STATUS 40 * @brief the return status of function 41 */ 42 enum RK_PS_RETURN_STATUS 43 { 44 RK_PS_STATUS_EOF = -1, /**< error of function inside */ 45 RK_PS_STATUS_OK = 0, /**< run successfully */ 46 RK_PS_STATUS_FILE_READ_ERROR, /**< error: fail to read file */ 47 RK_PS_STATUS_FILE_WRITE_ERROR, /**< error: fail to write file */ 48 RK_PS_STATUS_INVALID_PARAM, /**< error: invalid parameter */ 49 RK_PS_STATUS_ALLOC_FAILED, /**< error: fail to alloc buffer */ 50 AVS_STATUS_BUTT /**< error: reserved fields */ 51 }; 52 53 /* 54 * @enum RK_PS_MESH_ALPHA_SAVE_OPTION 55 * @brief Specify the way of saving mesh and alpha data 56 */ 57 enum RK_PS_MESH_ALPHA_SAVE_OPTION 58 { 59 WRITE_MESH_ALPHA_BUFFER = 0, /**< write mesh and alpha in buffer */ 60 WRITE_MESH_ALPHA_BIN_FILE = 1, /**< write mesh and alpha as bin file */ 61 }; 62 63 /* 64 * @enum RK_PS_LOW_FREQUENCY_LAYER_FUSE_WIDTH 65 * @brief Specify the low frequency layer fuse width 66 */ 67 enum RK_PS_LOW_FREQUENCY_LAYER_FUSE_WIDTH 68 { 69 LOW_FREQUENCY_LAYER_FUSE_WIDTH_128 = 128, /**< fuse_width = 128 */ 70 LOW_FREQUENCY_LAYER_FUSE_WIDTH_256 = 256, /**< fuse_width = 256 */ 71 LOW_FREQUENCY_LAYER_FUSE_WIDTH_512 = 512, /**< fuse_width = 512 */ 72 }; 73 74 /* 75 * @enum RK_PS_IMAGE_FORMAT 76 * @brief Specify the input images format 77 */ 78 enum RK_PS_IMAGE_FORMAT 79 { 80 INPUT_FORMAT_TYPE_GRAY = 0, /**< input gray images */ 81 INPUT_FORMAT_TYPE_RGB = 1, /**< input rgb images */ 82 INPUT_FORMAT_TYPE_YUVNV12 = 2, /**< input yuv_nv12 images */ 83 }; 84 85 /* 86 * @enum RK_PS_SAVE_MESH_ALPHA_TYPE 87 * @brief Specify the save mesh and alpha data type 88 */ 89 enum RK_PS_SAVE_MESH_ALPHA_TYPE 90 { 91 SAVE_MESH_ALPHA_TYPE_GPU = 0, /**< output rk mesh alpha data for gpu(3588) */ 92 SAVE_MESH_ALPHA_TYPE_CMODEL = 1, /**< output rk mesh alpha data for cmodel */ 93 SAVE_MESH_ALPHA_TYPE_DEBUG = 2, /**< output rk mesh alpha data for debug */ 94 SAVE_MESH_ALPHA_TYPE_FEC = 3, /**< output rk mesh alpha data for FEC */ 95 }; 96 97 /* 98 * @enum RK_PS_CAMERA_TYPE 99 * @brief Specify the camera type 100 */ 101 enum RK_PS_CAMERA_TYPE 102 { 103 RK_PS_CAMERA_TYPE_PINHOLE, /**< camera pinhole type */ 104 RK_PS_CAMERA_TYPE_OMNI, /**< camera omnidirectional type */ 105 RK_PS_CAMERA_TYPE_FISH, /**< camera fisheye type */ 106 }; 107 108 /* 109 * @enum RK_PS_PROJECT_TYPE 110 * @brief Specify the project type 111 */ 112 enum RK_PS_PROJECT_TYPE 113 { 114 RK_PS_PROJECTION_EQUIRECTANGULAR = 0, /**< equirectangular */ 115 RK_PS_PROJECTION_RECTILINEAR = 1, /**< rectilinear */ 116 RK_PS_PROJECTION_CYLINDRICAL = 2, /**< cylindrical */ 117 RK_PS_PROJECTION_CUBE_MAP = 3, /**< cube_map: currently unsupported */ 118 }; 119 120 /* 121 * @enum RK_PS_SrcOverlapPosition 122 * @brief Clockwise rotation angle of overlapping area from src image to dst image 123 */ 124 enum RK_PS_SrcOverlapPosition 125 { 126 RK_PS_SrcOverlapPosition_0 = 0, /**< clockwise rotation 0 degrees */ 127 RK_PS_SrcOverlapPosition_90 = 1, /**< clockwise rotation 90 degrees */ 128 RK_PS_SrcOverlapPosition_180 = 2, /**< clockwise rotation 180 degrees */ 129 RK_PS_SrcOverlapPosition_270 = 3, /**< clockwise rotation 270 degrees */ 130 }; 131 132 /* 133 * @struct RK_PS_SrcOverlapMap 134 * @brief the overlap map data and position on src image 135 */ 136 struct RK_PS_SrcOverlapMap 137 { 138 char versionInfo[64]; 139 RK_PS_SrcOverlapPosition srcOverlapPositon[8]; 140 unsigned char overlapMap[15 * 15 * 8]; 141 }; 142 143 struct RK_PS_MeshParams 144 { 145 int nonoverlap_num; 146 int overlap_num; 147 int nonoverlap_dst_startx[2]; 148 int nonoverlap_dst_width[2]; 149 int nonoverlap_mesh_width[2]; 150 int nonoverlap_mesh_height[2]; 151 152 int overlap_band_num; 153 int overlap_dst_startx[2]; 154 int overlap_dst_width[2]; 155 int overlap_mesh_width[2]; 156 int overlap_mesh_height[2]; 157 int overlap_alpha_width[2]; 158 int overlap_alpha_height[2]; 159 }; 160 /* 161 * @struct RK_PS_MeshBuffer 162 * @brief output buffer for mesh 163 */ 164 struct RK_PS_MeshBuffer 165 { 166 int src_width; 167 int src_height; 168 int dst_width; 169 int dst_height; 170 int mesh_step_x; 171 int mesh_step_y; 172 int camera_num; 173 float* pmesh; 174 RK_PS_MeshParams mesh_params[8]; 175 }; 176 177 /* 178 * @struct RK_PS_AlphaBuffer 179 * @brief output buffer for alpha 180 */ 181 struct RK_PS_AlphaBuffer 182 { 183 void* place_holder; 184 }; 185 186 /* 187 * @struct RK_PS_Engine 188 * @brief the internal engine instance 189 */ 190 struct RK_PS_Engine 191 { 192 RK_PS_MeshBuffer* mesh; /**< input/output-mesh buffer */ 193 RK_PS_AlphaBuffer* alpha; /**< input/output-alpha buffer */ 194 void* p; 195 }; 196 197 /* 198 * @struct RK_PS_InitParams 199 * @brief params for initialize calibration data 200 */ 201 struct RK_PS_InitParams 202 { 203 RK_PS_MESH_ALPHA_SAVE_OPTION save_option; /**< input-specify save option */ 204 int camera_num; /**< input-camera numbers */ 205 const char* input_calib_data_path; /**< input-cameras calibration data path */ 206 const char* input_mask_data_path; /**< input-mask image path */ 207 const char* input_lut_path; /**< input-specify src LUT file path */ 208 const char* output_mesh_alpha_data_path; /**< output-mesh and alpha data path */ 209 const char* output_overlap_data_path; /**< output-overlap data path */ 210 int mesh_step_x; /**< input-mesh step in horizontal direction */ 211 int mesh_step_y; /**< input-mesh step in vertical direction */ 212 int fuse_width; /**< input-min width of fuse band: 128 or 256 or 512 */ 213 }; 214 215 /* 216 * @struct RK_PS_Rotation 217 * @brief rotation angle 218 */ 219 struct RK_PS_Rotation 220 { 221 int yaw100; /**< yaw data. yaw angle x 100 */ 222 int pitch100; /**< pitch data. pitch angle x 100 */ 223 int roll100; /**< roll data. roll angle x 100 */ 224 }; 225 226 /* 227 * @struct RK_PS_SetProjectParams 228 * @brief params for the specifications of the output image 229 */ 230 struct RK_PS_SetProjectParams 231 { 232 int project_type; /**< input-project type */ 233 int camera_num; /**< input-cameras number */ 234 int src_width; /**< input-input_images width */ 235 int src_height; /**< input-input_images height */ 236 int dst_width; /**< input-output stitch image width */ 237 int dst_height; /**< input-output stitch image height */ 238 int fov_x100; /**< input-output stitch image fov_x */ 239 int fov_y100; /**< input-output stitch image fov_y */ 240 int center_x; /**< input-output stitch image center_y */ 241 int center_y; /**< input-output stitch image center_y */ 242 float stitch_distance; /**< input-best stitch distance */ 243 int save_mesh_alpha_type; /**< input-output mesh and alpha type */ 244 RK_PS_Rotation ori_rotation; /**< input-output stitch image ori rotation */ 245 RK_PS_Rotation rotation; /**< input-output stitch image rotation */ 246 }; 247 248 /* 249 * @struct RK_PS_FineTuningParams 250 * @brief fine tuning params for every camera 251 */ 252 struct RK_PS_FineTuningParams 253 { 254 int camera_num; 255 int offset_h[8]; 256 int offset_w[8]; 257 int offset_z[8]; 258 RK_PS_Rotation rotation[8]; 259 }; 260 261 /* 262 * @struct RK_PS_Roi_Params 263 * @brief params for roi 264 */ 265 struct RK_PS_RoiParams 266 { 267 int src_project_type; /**< input-project type */ 268 int src_width; /**< input-input_image width */ 269 int src_height; /**< input-input_image height */ 270 int src_fov_x100; /**< input-input_image fov_x */ 271 int src_fov_y100; /**< input-input_image fov_y */ 272 int src_center_x; 273 int src_center_y; 274 275 int dst_width; /**< input-output stitch image width */ 276 int dst_height; /**< input-output stitch image height */ 277 int dst_fov_x100; /**< input-output stitch image fov_x */ 278 int dst_fov_y100; /**< input-output stitch image fov_y */ 279 int dst_center_x; /**< input-output stitch image center_y */ 280 int dst_center_y; /**< input-output stitch image center_y */ 281 }; 282 283 /* 284 * @struct RK_PS_InitBlendedImages 285 * @brief params for initialize blended images 286 */ 287 struct RK_PS_InitBlendedImages 288 { 289 int camera_num; /**< input-cameras number */ 290 int image_format; /**< input-images format */ 291 int use_gain; /**< input-use gain or not(0-not use,1-use) */ 292 int gain_stepx; /**< input-gian step_x */ 293 int gain_stepy; /**< input-gian step_y */ 294 int input_mesh_alpha_data_type; /**< input-input mesh and alpha data type */ 295 const char* input_mesh_alpha_data_path; /**< input-input mesh and alpha data path */ 296 unsigned char* output_blended_image; /**< output-output blended image */ 297 }; 298 299 /* 创建Engine的函数 */ 300 DLL_PUBLIC int RK_PS_setEngine(struct RK_PS_Engine* engine); 301 302 /* 生成mesh表和alpha表时的初始化标定参数的函数 */ 303 DLL_PUBLIC int RK_PS_initParams(struct RK_PS_Engine* engine, RK_PS_InitParams* params); 304 305 /* 生成mesh表和alpha表时设置输出图像规格的函数 */ 306 DLL_PUBLIC int RK_PS_setProjectParams(struct RK_PS_Engine* engine, struct RK_PS_SetProjectParams* params); 307 308 /* 生成mesh表和alpha表时设置每个相机姿态精调参数的函数 */ 309 DLL_PUBLIC int RK_PS_setFineTuningParams(struct RK_PS_Engine* engine, struct RK_PS_FineTuningParams* params); 310 311 //获取GPU所需查找表所需的最大buffer 312 DLL_PUBLIC int RK_PS_getMaxMeshBufferSize(struct RK_PS_Engine* engine, float* buffer_size); 313 314 /* 通过标定文件生成mesh表和alpha表的函数 */ 315 DLL_PUBLIC int RK_PS_mesh_alphaFromCalibration(struct RK_PS_Engine* engine); 316 317 /* 通过标定文件计算输入图像重叠区域mask信息 */ 318 DLL_PUBLIC int RK_PS_srcOverlapMaskFromCalibration(struct RK_PS_Engine* engine); 319 320 /* 通过中间LUT表生成mesh表和alpha表的函数 */ 321 DLL_PUBLIC int RK_PS_mesh_alphaFromProjection(struct RK_PS_Engine* engine); 322 323 /* 通过用户指定的ROI参数生成rectilinear校正的mesh表的函数 */ 324 DLL_PUBLIC int RK_PS_meshForRoiRectilinear(struct RK_PS_Engine* engine, RK_PS_RoiParams* roi_parmas, const char* save_mesh_path); 325 326 /* 拼接图像的初始化函数 */ 327 DLL_PUBLIC int RK_PS_initBlendedImages(struct RK_PS_Engine* engine, struct RK_PS_InitBlendedImages* params); 328 329 /* 拼接图像函数主函数 */ 330 DLL_PUBLIC int RK_PS_blendedImages(struct RK_PS_Engine* engine, unsigned char** pinput_image); 331 332 /* 析构函数 */ 333 DLL_PUBLIC int RK_PS_destroy(struct RK_PS_Engine* engine); 334 335 #ifdef __cplusplus 336 } /* extern "C" { */ 337 #endif 338 339 340 341 342 #endif // !__PANORAMA_STITCHINGAPP_H__ 343