diff options
author | Junkai Wu <junkai.wu@intel.com> | 2017-10-27 12:06:46 +0800 |
---|---|---|
committer | windyuan <feng.yuan@intel.com> | 2017-10-27 17:44:24 +0800 |
commit | a07666d12bfd94b076db1b966d2d10846622309d (patch) | |
tree | a64f70a7d938a18d8ebb11f27a87ad8f5ed9294c /modules/ocl | |
parent | b0926c34382d0823424a5bb212b5ae6ecfdd7ae6 (diff) | |
download | libxcam-a07666d12bfd94b076db1b966d2d10846622309d.tar.gz |
Add bowl view mode in stitching.
Diffstat (limited to 'modules/ocl')
-rw-r--r-- | modules/ocl/cl_fisheye_handler.cpp | 111 | ||||
-rw-r--r-- | modules/ocl/cl_fisheye_handler.h | 39 | ||||
-rw-r--r-- | modules/ocl/cl_image_360_stitch.cpp | 131 | ||||
-rw-r--r-- | modules/ocl/cl_image_360_stitch.h | 9 | ||||
-rw-r--r-- | modules/ocl/cl_post_image_processor.cpp | 3 | ||||
-rw-r--r-- | modules/ocl/cl_post_image_processor.h | 1 | ||||
-rw-r--r-- | modules/ocl/cv_calibration_parser.cpp | 6 | ||||
-rw-r--r-- | modules/ocl/cv_surview_fisheye_dewarp.cpp | 59 | ||||
-rw-r--r-- | modules/ocl/cv_surview_fisheye_dewarp.h | 12 |
9 files changed, 249 insertions, 122 deletions
diff --git a/modules/ocl/cl_fisheye_handler.cpp b/modules/ocl/cl_fisheye_handler.cpp index c1ff0de..cce8a70 100644 --- a/modules/ocl/cl_fisheye_handler.cpp +++ b/modules/ocl/cl_fisheye_handler.cpp @@ -128,13 +128,14 @@ CLFisheye2GPSKernel::prepare_arguments (CLArgList &args, CLWorkSize &work_size) return XCAM_RETURN_NO_ERROR; } -CLFisheyeHandler::CLFisheyeHandler (const SmartPtr<CLContext> &context, bool use_map, bool need_lsc) +CLFisheyeHandler::CLFisheyeHandler (const SmartPtr<CLContext> &context, SurroundMode surround_mode, bool use_map, bool need_lsc) : CLImageHandler (context, "CLFisheyeHandler") , _output_width (0) , _output_height (0) , _range_longitude (180.0f) , _range_latitude (180.0f) , _map_factor (DEFAULT_FISHEYE_TABLE_SCALE) + , _surround_mode (surround_mode) , _use_map (use_map) , _need_lsc (need_lsc ? 1 : 0) , _lsc_array_size (0) @@ -374,44 +375,72 @@ CLFisheyeHandler::generate_fisheye_table ( ERROR, _geo_table.ptr () && _geo_table->is_valid (), XCAM_RETURN_ERROR_MEM, "[%s] check geo map buffer failed", get_name ()); - CLArgList args; - CLWorkSize work_size; - - FisheyeInfo fisheye_arg1 = fisheye_info; - fisheye_arg1.wide_angle = degree2radian (fisheye_info.wide_angle); - fisheye_arg1.rotate_angle = degree2radian (fisheye_info.rotate_angle); - args.push_back (new CLArgumentT<FisheyeInfo> (fisheye_arg1)); - - float fisheye_image_size[2]; - fisheye_image_size[0] = fisheye_width; - fisheye_image_size[1] = fisheye_height; - args.push_back (new CLArgumentTArray<float, 2> (fisheye_image_size)); - args.push_back (new CLMemArgument (_geo_table)); - - float radian_per_pixel[2]; - radian_per_pixel[0] = degree2radian (longitude / table_width); - radian_per_pixel[1] = degree2radian (latitude / table_height); - args.push_back (new CLArgumentTArray<float, 2> (radian_per_pixel)); - - float table_center[2]; - table_center[0] = table_width / 2.0f; - table_center[1] = table_height / 2.0f; - args.push_back (new CLArgumentTArray<float, 2> (table_center)); - - work_size.dim = 2; - work_size.local[0] = 8; - work_size.local[1] = 4; - work_size.global[0] = XCAM_ALIGN_UP (table_width, work_size.local[0]); - work_size.global[1] = XCAM_ALIGN_UP (table_height, work_size.local[1]); - - XCAM_FAIL_RETURN ( - ERROR, table_kernel->set_arguments (args, work_size) == XCAM_RETURN_NO_ERROR, - XCAM_RETURN_ERROR_CL, "kernel_fisheye_table set arguments failed"); - - XCAM_FAIL_RETURN ( - ERROR, table_kernel->execute (table_kernel, true) == XCAM_RETURN_NO_ERROR, - XCAM_RETURN_ERROR_CL, "[%s] execute kernel_fisheye_table failed", get_name ()); - + if(_surround_mode == BowlView) { + BowlDataConfig bowl_data_config = get_bowl_config(); + IntrinsicParameter intrinsic_param = get_intrinsic_param(); + ExtrinsicParameter extrinsic_param = get_extrinsic_param(); + + std::vector<float> map_table(table_width * table_height * 2); + CVPolyFisheyeDewarp fd; + fd.set_intrinsic_param(intrinsic_param); + fd.set_extrinsic_param(extrinsic_param); + + fd.fisheye_dewarp(map_table, table_width, table_height, output_width, output_height, bowl_data_config); + + float *map_ptr = NULL; + size_t origin[3] = {0, 0, 0}; + size_t region[3] = {table_width, table_height, 1}; + size_t row_pitch; + size_t slice_pitch; + XCamReturn ret = _geo_table->enqueue_map ((void *&)map_ptr, origin, region, &row_pitch, &slice_pitch, CL_MEM_READ_WRITE); + XCAM_ASSERT (ret == XCAM_RETURN_NO_ERROR); + + for (uint32_t row = 0; row < table_height; row++) { + for(uint32_t col = 0; col < table_width; col++) { + map_ptr[row * row_pitch / 4 + col * 4] = map_table[row * table_width * 2 + col * 2] / fisheye_width; + map_ptr[row * row_pitch / 4 + col * 4 + 1] = map_table[row * table_width * 2 + col * 2 + 1] / fisheye_height; + } + } + _geo_table->enqueue_unmap ((void *&)map_ptr); + } else { + CLArgList args; + CLWorkSize work_size; + + FisheyeInfo fisheye_arg1 = fisheye_info; + fisheye_arg1.wide_angle = degree2radian (fisheye_info.wide_angle); + fisheye_arg1.rotate_angle = degree2radian (fisheye_info.rotate_angle); + args.push_back (new CLArgumentT<FisheyeInfo> (fisheye_arg1)); + + float fisheye_image_size[2]; + fisheye_image_size[0] = fisheye_width; + fisheye_image_size[1] = fisheye_height; + args.push_back (new CLArgumentTArray<float, 2> (fisheye_image_size)); + args.push_back (new CLMemArgument (_geo_table)); + + float radian_per_pixel[2]; + radian_per_pixel[0] = degree2radian (longitude / table_width); + radian_per_pixel[1] = degree2radian (latitude / table_height); + args.push_back (new CLArgumentTArray<float, 2> (radian_per_pixel)); + + float table_center[2]; + table_center[0] = table_width / 2.0f; + table_center[1] = table_height / 2.0f; + args.push_back (new CLArgumentTArray<float, 2> (table_center)); + + work_size.dim = 2; + work_size.local[0] = 8; + work_size.local[1] = 4; + work_size.global[0] = XCAM_ALIGN_UP (table_width, work_size.local[0]); + work_size.global[1] = XCAM_ALIGN_UP (table_height, work_size.local[1]); + + XCAM_FAIL_RETURN ( + ERROR, table_kernel->set_arguments (args, work_size) == XCAM_RETURN_NO_ERROR, + XCAM_RETURN_ERROR_CL, "kernel_fisheye_table set arguments failed"); + + XCAM_FAIL_RETURN ( + ERROR, table_kernel->execute (table_kernel, true) == XCAM_RETURN_NO_ERROR, + XCAM_RETURN_ERROR_CL, "[%s] execute kernel_fisheye_table failed", get_name ()); + } //dump_geo_table (_geo_table); return XCAM_RETURN_NO_ERROR; @@ -556,12 +585,12 @@ create_fishey_gps_kernel (const SmartPtr<CLContext> &context, SmartPtr<CLFisheye } SmartPtr<CLImageHandler> -create_fisheye_handler (const SmartPtr<CLContext> &context, bool use_map, bool need_lsc) +create_fisheye_handler (const SmartPtr<CLContext> &context, SurroundMode surround_mode, bool use_map, bool need_lsc) { SmartPtr<CLFisheyeHandler> handler; SmartPtr<CLImageKernel> kernel; - handler = new CLFisheyeHandler (context, use_map, need_lsc); + handler = new CLFisheyeHandler (context, surround_mode, use_map, need_lsc); XCAM_ASSERT (handler.ptr ()); if (use_map) { diff --git a/modules/ocl/cl_fisheye_handler.h b/modules/ocl/cl_fisheye_handler.h index f53d87f..08c610b 100644 --- a/modules/ocl/cl_fisheye_handler.h +++ b/modules/ocl/cl_fisheye_handler.h @@ -26,6 +26,11 @@ #include "ocl/cl_image_handler.h" #include "ocl/cl_geo_map_handler.h" +#if HAVE_OPENCV +#include "ocl/cv_surview_fisheye_dewarp.h" +#include "ocl/cv_calibration_parser.h" +#endif + namespace XCam { class CLFisheyeHandler; @@ -48,7 +53,7 @@ class CLFisheyeHandler { friend class CLFisheye2GPSKernel; public: - explicit CLFisheyeHandler (const SmartPtr<CLContext> &context, bool use_map, bool need_lsc); + explicit CLFisheyeHandler (const SmartPtr<CLContext> &context, SurroundMode surround_mode, bool use_map, bool need_lsc); virtual ~CLFisheyeHandler(); void set_output_size (uint32_t width, uint32_t height); @@ -64,6 +69,28 @@ public: void set_lsc_table (float *table, uint32_t table_size); void set_lsc_gray_threshold (float min_threshold, float max_threshold); + void set_bowl_config(const BowlDataConfig bowl_data_config) { + _bowl_data_config = bowl_data_config; + } + const BowlDataConfig &get_bowl_config() { + return _bowl_data_config; + } + + void set_intrinsic_param(const IntrinsicParameter intrinsic_param) { + _intrinsic_param = intrinsic_param; + } + const IntrinsicParameter &get_intrinsic_param() { + return _intrinsic_param; + } + + void set_extrinsic_param(const ExtrinsicParameter extrinsic_param) { + _extrinsic_param = extrinsic_param; + } + const ExtrinsicParameter &get_extrinsic_param() { + return _extrinsic_param; + } + + protected: // derived from CLImageHandler virtual XCamReturn prepare_buffer_pool_video_info ( @@ -117,6 +144,14 @@ private: uint32_t _lsc_array_size; float _gray_threshold[2]; // [min_gray_threshold, max_gray_threshold] float *_lsc_array; + + BowlDataConfig _bowl_data_config; + + IntrinsicParameter _intrinsic_param; + ExtrinsicParameter _extrinsic_param; + + SurroundMode _surround_mode; + SmartPtr<CLImage> _geo_table; SmartPtr<CLImage> _lsc_table; SmartPtr<CLImage> _input[CLNV12PlaneMax]; @@ -124,7 +159,7 @@ private: }; SmartPtr<CLImageHandler> -create_fisheye_handler (const SmartPtr<CLContext> &context, bool use_map = false, bool need_lsc = false); +create_fisheye_handler (const SmartPtr<CLContext> &context, SurroundMode surround_mode = SphereView, bool use_map = false, bool need_lsc = false); } diff --git a/modules/ocl/cl_image_360_stitch.cpp b/modules/ocl/cl_image_360_stitch.cpp index f613fce..a69b420 100644 --- a/modules/ocl/cl_image_360_stitch.cpp +++ b/modules/ocl/cl_image_360_stitch.cpp @@ -180,25 +180,25 @@ get_default_stitch_info (StitchResMode res_mode) break; } case StitchRes1080P4: { - stitch_info.merge_width[0] = 96; - stitch_info.merge_width[1] = 96; - stitch_info.merge_width[2] = 96; - stitch_info.merge_width[3] = 96; + stitch_info.merge_width[0] = 224; + stitch_info.merge_width[1] = 128; + stitch_info.merge_width[2] = 128; + stitch_info.merge_width[3] = 64; - stitch_info.crop[0].left = 16; - stitch_info.crop[0].right = 16; + stitch_info.crop[0].left = 128; + stitch_info.crop[0].right = 48; stitch_info.crop[0].top = 0; stitch_info.crop[0].bottom = 0; - stitch_info.crop[1].left = 16; + stitch_info.crop[1].left = 160; stitch_info.crop[1].right = 16; stitch_info.crop[1].top = 0; stitch_info.crop[1].bottom = 0; - stitch_info.crop[2].left = 16; - stitch_info.crop[2].right = 16; + stitch_info.crop[2].left = 208; + stitch_info.crop[2].right = 496; stitch_info.crop[2].top = 0; stitch_info.crop[2].bottom = 0; - stitch_info.crop[3].left = 16; - stitch_info.crop[3].right = 16; + stitch_info.crop[3].left = 48; + stitch_info.crop[3].right = 136; stitch_info.crop[3].top = 0; stitch_info.crop[3].bottom = 0; @@ -259,13 +259,14 @@ get_default_stitch_info (StitchResMode res_mode) } CLImage360Stitch::CLImage360Stitch ( - const SmartPtr<CLContext> &context, CLBlenderScaleMode scale_mode, StitchResMode res_mode, - int fisheye_num, bool all_in_one_img) + const SmartPtr<CLContext> &context, CLBlenderScaleMode scale_mode, SurroundMode surround_mode, + StitchResMode res_mode, int fisheye_num, bool all_in_one_img) : CLMultiImageHandler (context, "CLImage360Stitch") , _context (context) , _output_width (0) , _output_height (0) , _scale_mode (scale_mode) + , _surround_mode (surround_mode) , _res_mode (res_mode) , _is_stitch_inited (false) , _fisheye_num (fisheye_num) @@ -329,6 +330,18 @@ CLImage360Stitch::set_blender (SmartPtr<CLBlender> blender, int idx) return add_image_handler (handler); } +void +CLImage360Stitch::set_fisheye_intrinsic (IntrinsicParameter intrinsic_param, int index) +{ + _fisheye[index].handler->set_intrinsic_param(intrinsic_param); +} + +void +CLImage360Stitch::set_fisheye_extrinsic (ExtrinsicParameter extrinsic_param, int index) +{ + _fisheye[index].handler->set_extrinsic_param(extrinsic_param); +} + bool CLImage360Stitch::set_image_overlap (const int idx, const Rect &overlap0, const Rect &overlap1) { @@ -370,30 +383,70 @@ CLImage360Stitch::calc_fisheye_initial_info (SmartPtr<VideoBuffer> &output) { const VideoBufferInfo &out_info = output->get_video_info (); - uint32_t fisheye_width_sum = out_info.width; - for (int i = 0; i < _fisheye_num; i++) { - fisheye_width_sum += _stitch_info.merge_width[i] + _stitch_info.crop[i].left + _stitch_info.crop[i].right; - } - _fisheye[0].width = fisheye_width_sum / _fisheye_num; - _fisheye[0].width = XCAM_ALIGN_UP (_fisheye[0].width, 16); - _fisheye[0].height = out_info.height + _stitch_info.crop[0].top + _stitch_info.crop[0].bottom; - XCAM_LOG_INFO ( - "fisheye correction output size width:%d height:%d", - _fisheye[0].width, _fisheye[0].height); - - for (int i = 1; i < _fisheye_num; i++) { - _fisheye[i].width = _fisheye[0].width; - _fisheye[i].height = _fisheye[0].height; - } + if(_surround_mode == SphereView) { + uint32_t fisheye_width_sum = out_info.width; + for (int i = 0; i < _fisheye_num; i++) { + fisheye_width_sum += _stitch_info.merge_width[i] + _stitch_info.crop[i].left + _stitch_info.crop[i].right; + } + _fisheye[0].width = fisheye_width_sum / _fisheye_num; + _fisheye[0].width = XCAM_ALIGN_UP (_fisheye[0].width, 16); + _fisheye[0].height = out_info.height + _stitch_info.crop[0].top + _stitch_info.crop[0].bottom; + XCAM_LOG_INFO ( + "fisheye correction output size width:%d height:%d", + _fisheye[0].width, _fisheye[0].height); + + for (int i = 1; i < _fisheye_num; i++) { + _fisheye[i].width = _fisheye[0].width; + _fisheye[i].height = _fisheye[0].height; + } - float max_dst_longitude, max_dst_latitude; - for (int i = 0; i < _fisheye_num; ++i) { - max_dst_latitude = (_stitch_info.fisheye_info[i].wide_angle > 180.0f) ? - 180.0f : _stitch_info.fisheye_info[i].wide_angle; - max_dst_longitude = max_dst_latitude * _fisheye[i].width / _fisheye[i].height; + float max_dst_longitude, max_dst_latitude; + for (int i = 0; i < _fisheye_num; ++i) { + max_dst_latitude = (_stitch_info.fisheye_info[i].wide_angle > 180.0f) ? + 180.0f : _stitch_info.fisheye_info[i].wide_angle; + max_dst_longitude = max_dst_latitude * _fisheye[i].width / _fisheye[i].height; - _fisheye[i].handler->set_dst_range (max_dst_longitude, max_dst_latitude); - _fisheye[i].handler->set_output_size (_fisheye[i].width, _fisheye[i].height); + _fisheye[i].handler->set_dst_range (max_dst_longitude, max_dst_latitude); + _fisheye[i].handler->set_output_size (_fisheye[i].width, _fisheye[i].height); + } + } else { + _fisheye[0].height = out_info.height + _stitch_info.crop[0].top + _stitch_info.crop[0].bottom; + + float view_angle[XCAM_STITCH_FISHEYE_MAX_NUM]; + float car_length = 4500.0f; + float max_z = 3000.0f; + + for(int i = 0; i < _fisheye_num; i++) { + view_angle[i] = 120.0f / 360.0f * 2 * PI; + _fisheye[i].width = view_angle[i] / (2 * PI) * out_info.width; + _fisheye[i].width = XCAM_ALIGN_UP (_fisheye[i].width, 16); + } + + XCAM_LOG_INFO ( + "fisheye correction output size width:%d height:%d", + _fisheye[0].width, _fisheye[0].height); + + BowlDataConfig bowl_data_config[XCAM_STITCH_FISHEYE_MAX_NUM]; + + float ground_length = bowl_data_config[0].a * sqrt(1 - (max_z / 2) * (max_z / 2) / (bowl_data_config[0].c * bowl_data_config[0].c)) - car_length / 2; + bowl_data_config[0].wall_image_height = (int)(max_z / (ground_length + max_z) * _fisheye[0].height); + bowl_data_config[0].ground_image_height = _fisheye[0].height - bowl_data_config[0].wall_image_height; + + bowl_data_config[0].angle_start = view_angle[0] / 2; + bowl_data_config[0].angle_end = -view_angle[0] / 2; + + for (int i = 1; i < _fisheye_num; i++) { + _fisheye[i].height = _fisheye[0].height; + bowl_data_config[i].wall_image_height = bowl_data_config[0].wall_image_height; + bowl_data_config[i].ground_image_height = bowl_data_config[0].ground_image_height; + bowl_data_config[i].angle_start = 2 * PI / _fisheye_num * (_fisheye_num - i) + view_angle[i] / 2; + bowl_data_config[i].angle_end = 2 * PI / _fisheye_num * (_fisheye_num - i) - view_angle[i] / 2; + } + + for(int i = 0; i < _fisheye_num; i++) { + _fisheye[i].handler->set_bowl_config(bowl_data_config[i]); + _fisheye[i].handler->set_output_size (_fisheye[i].width, _fisheye[i].height); + } } } @@ -781,19 +834,19 @@ create_blender_global_scale_kernel ( SmartPtr<CLImageHandler> create_image_360_stitch ( const SmartPtr<CLContext> &context, bool need_seam, - CLBlenderScaleMode scale_mode, bool fisheye_map, bool need_lsc, StitchResMode res_mode, - int fisheye_num, bool all_in_one_img) + CLBlenderScaleMode scale_mode, bool fisheye_map, bool need_lsc, SurroundMode surround_mode, + StitchResMode res_mode, int fisheye_num, bool all_in_one_img) { const int layer = 2; const bool need_uv = true; SmartPtr<CLFisheyeHandler> fisheye; SmartPtr<CLBlender> blender; SmartPtr<CLImage360Stitch> stitch = new CLImage360Stitch ( - context, scale_mode, res_mode, fisheye_num, all_in_one_img); + context, scale_mode, surround_mode, res_mode, fisheye_num, all_in_one_img); XCAM_ASSERT (stitch.ptr ()); for (int index = 0; index < fisheye_num; ++index) { - fisheye = create_fisheye_handler (context, fisheye_map, need_lsc).dynamic_cast_ptr<CLFisheyeHandler> (); + fisheye = create_fisheye_handler (context, surround_mode, fisheye_map, need_lsc).dynamic_cast_ptr<CLFisheyeHandler> (); XCAM_FAIL_RETURN (ERROR, fisheye.ptr (), NULL, "image_360_stitch create fisheye handler failed"); fisheye->disable_buf_pool (true); stitch->set_fisheye_handler (fisheye, index); diff --git a/modules/ocl/cl_image_360_stitch.h b/modules/ocl/cl_image_360_stitch.h index b54a56b..fd1a8b6 100644 --- a/modules/ocl/cl_image_360_stitch.h +++ b/modules/ocl/cl_image_360_stitch.h @@ -66,8 +66,8 @@ class CLImage360Stitch { public: explicit CLImage360Stitch ( - const SmartPtr<CLContext> &context, CLBlenderScaleMode scale_mode, StitchResMode res_mode, - int fisheye_num, bool all_in_one_img); + const SmartPtr<CLContext> &context, CLBlenderScaleMode scale_mode, SurroundMode surround_mode, + StitchResMode res_mode, int fisheye_num, bool all_in_one_img); bool set_stitch_info (StitchInfo stitch_info); StitchInfo get_stitch_info (); @@ -79,6 +79,9 @@ public: bool set_fisheye_handler (SmartPtr<CLFisheyeHandler> fisheye, int index); bool set_blender (SmartPtr<CLBlender> blender, int idx); + void set_fisheye_intrinsic (IntrinsicParameter intrinsic_param, int index); + void set_fisheye_extrinsic (ExtrinsicParameter extrinsic_param, int index); + bool set_image_overlap (const int idx, const Rect &overlap0, const Rect &overlap1); const Rect &get_image_overlap (int img_idx, int num) { XCAM_ASSERT (img_idx < _fisheye_num && num < 2); @@ -139,6 +142,7 @@ private: SmartPtr<VideoBuffer> _scale_global_input; SmartPtr<VideoBuffer> _scale_global_output; + SurroundMode _surround_mode; StitchResMode _res_mode; bool _is_stitch_inited; @@ -154,6 +158,7 @@ create_image_360_stitch ( CLBlenderScaleMode scale_mode = CLBlenderScaleLocal, bool fisheye_map = false, bool need_lsc = false, + SurroundMode surround_mode = SphereView, StitchResMode res_mode = StitchRes1080P, int fisheye_num = 2, bool all_in_one_img = true); diff --git a/modules/ocl/cl_post_image_processor.cpp b/modules/ocl/cl_post_image_processor.cpp index 60875a2..ebe9319 100644 --- a/modules/ocl/cl_post_image_processor.cpp +++ b/modules/ocl/cl_post_image_processor.cpp @@ -64,6 +64,7 @@ CLPostImageProcessor::CLPostImageProcessor () , _stitch_width (0) , _stitch_height (0) , _stitch_res_mode (0) + , _surround_mode (SphereView) { XCAM_LOG_DEBUG ("CLPostImageProcessor constructed"); } @@ -402,7 +403,7 @@ CLPostImageProcessor::create_handlers () /* image stitch */ image_handler = create_image_360_stitch (context, _stitch_enable_seam, _stitch_scale_mode, - _stitch_fisheye_map, _stitch_lsc, (StitchResMode) _stitch_res_mode); + _stitch_fisheye_map, _stitch_lsc, (SurroundMode) _surround_mode, (StitchResMode) _stitch_res_mode); _stitch = image_handler.dynamic_cast_ptr<CLImage360Stitch> (); XCAM_FAIL_RETURN ( WARNING, diff --git a/modules/ocl/cl_post_image_processor.h b/modules/ocl/cl_post_image_processor.h index 1b779ea..6c3b6ba 100644 --- a/modules/ocl/cl_post_image_processor.h +++ b/modules/ocl/cl_post_image_processor.h @@ -145,6 +145,7 @@ private: uint32_t _stitch_width; uint32_t _stitch_height; uint32_t _stitch_res_mode; + uint32_t _surround_mode; }; }; diff --git a/modules/ocl/cv_calibration_parser.cpp b/modules/ocl/cv_calibration_parser.cpp index e915dd3..18a994c 100644 --- a/modules/ocl/cv_calibration_parser.cpp +++ b/modules/ocl/cv_calibration_parser.cpp @@ -51,7 +51,7 @@ CalibrationParser::parse_intrinsic_param(char *file_body, IntrinsicParameter &in CHECK_NULL(line_str);
tok_str = strtok_r(line_str, str_tokens, &tok_endptr);
}
-
+
line_str = strtok_r(NULL, line_tokens, &line_endptr);
CHECK_NULL(line_str);
tok_str = strtok_r(line_str, str_tokens, &tok_endptr);
@@ -62,7 +62,7 @@ CalibrationParser::parse_intrinsic_param(char *file_body, IntrinsicParameter &in }
intrinsic_param.poly_length = strtol(tok_str, NULL, 10);
- for(int i = 0; i < intrinsic_param.poly_length; i++) {
+ for(uint32_t i = 0; i < intrinsic_param.poly_length; i++) {
tok_str = strtok_r(NULL, str_tokens, &tok_endptr);
CHECK_NULL(tok_str);
intrinsic_param.poly_coeff.push_back(strtof(tok_str, NULL));
@@ -174,7 +174,7 @@ CalibrationParser::parse_extrinsic_param(char *file_body, ExtrinsicParameter &ex tok_str = strtok_r(line_str, str_tokens, &tok_endptr);
}
extrinsic_param.yaw = strtof(tok_str, NULL);
- } while(0);
+ } while(0);
return XCAM_RETURN_NO_ERROR;
}
diff --git a/modules/ocl/cv_surview_fisheye_dewarp.cpp b/modules/ocl/cv_surview_fisheye_dewarp.cpp index be1c5fc..c99db17 100644 --- a/modules/ocl/cv_surview_fisheye_dewarp.cpp +++ b/modules/ocl/cv_surview_fisheye_dewarp.cpp @@ -24,8 +24,8 @@ namespace XCam { BowlDataConfig::BowlDataConfig()
{
- image_height = 480;
- image_heightZ0 = 320;
+ wall_image_height = 480;
+ ground_image_height = 320;
angle_start = PI / 2;
angle_end = 3 * PI / 2;
@@ -74,7 +74,7 @@ CVSurViewFisheyeDewarp::fisheye_dewarp(MapTable &map_table, uint32_t table_w, ui MapTable world_coord(3);
MapTable cam_coord(3);
MapTable cam_world_coord(3);
- MapTable image_coord(2);
+ MapTable image_coord(2);
uint32_t scale_factor_w = image_w / table_w;
uint32_t scale_factor_h = image_h / table_h;
@@ -90,9 +90,9 @@ CVSurViewFisheyeDewarp::fisheye_dewarp(MapTable &map_table, uint32_t table_w, ui cal_image_coord(cam_coord, image_coord);
map_table[row * table_w * 2 + col * 2] = image_coord[0];
- map_table[row * table_w * 2 + col * 2 + 1] = image_coord[1];
+ map_table[row * table_w * 2 + col * 2 + 1] = image_coord[1];
}
- }
+ }
}
void
@@ -105,14 +105,14 @@ CVSurViewFisheyeDewarp::cal_world_coord(uint32_t x, uint32_t y, MapTable &world_ float b = bowl_config.b;
float c = bowl_config.c;
- float z_step = 3000.0f / bowl_config.image_height;
+ float z_step = 3000.0f / bowl_config.wall_image_height;
float angle_step = fabs(bowl_config.angle_end - bowl_config.angle_start) / image_w;
- if(y < bowl_config.image_height) {
+ if(y < bowl_config.wall_image_height) {
world_z = 1500.0f - y * z_step;
- angle = bowl_config.angle_start - x * angle_step;
+ angle = bowl_config.angle_start - x * angle_step;
float r2 = 1 - world_z * world_z / (c * c);
-
+
if(angle == PI / 2) {
world_x = 0.0f;
world_y = sqrt(r2 * b * b);
@@ -131,11 +131,12 @@ CVSurViewFisheyeDewarp::cal_world_coord(uint32_t x, uint32_t y, MapTable &world_ a = a * sqrt(1 - world_z * world_z / (c * c));
b = b * sqrt(1 - world_z * world_z / (c * c));
- float step_a = (a - 920.0f) / bowl_config.image_heightZ0;
- float step_b = (b - 920.0f) / bowl_config.image_heightZ0;
+ float ratio_ab = b / a;
+
+ float step_a = (a - 920.0f) / bowl_config.ground_image_height;
- a = a - (y - bowl_config.image_height) * step_a;
- b = b - (y - bowl_config.image_height) * step_b;
+ a = a - (y - bowl_config.wall_image_height) * step_a;
+ b = a * ratio_ab;
angle = bowl_config.angle_start - x * angle_step;
@@ -154,7 +155,7 @@ CVSurViewFisheyeDewarp::cal_world_coord(uint32_t x, uint32_t y, MapTable &world_ }
}
- world_coord[0] = world_x - 2000.0f;
+ world_coord[0] = world_x - 2250.0f;
world_coord[1] = world_y;
world_coord[2] = world_z + 1500.0f;
}
@@ -162,9 +163,9 @@ CVSurViewFisheyeDewarp::cal_world_coord(uint32_t x, uint32_t y, MapTable &world_ void
CVSurViewFisheyeDewarp::cal_cam_world_coord(MapTable world_coord, MapTable &cam_world_coord)
{
- cv::Matx44f rotation_mat = generate_rotation_matrix(_extrinsic_param.roll * PI / 180,
- _extrinsic_param.pitch * PI / 180,
- _extrinsic_param.yaw * PI / 180);
+ cv::Matx44f rotation_mat = generate_rotation_matrix(_extrinsic_param.roll * PI / 180,
+ _extrinsic_param.pitch * PI / 180,
+ _extrinsic_param.yaw * PI / 180);
cv::Matx44f rotation_tran_mat(rotation_mat);
rotation_tran_mat(0, 3) = _extrinsic_param.trans_x;
rotation_tran_mat(1, 3) = _extrinsic_param.trans_y;
@@ -181,20 +182,20 @@ CVSurViewFisheyeDewarp::cal_cam_world_coord(MapTable world_coord, MapTable &cam_ cv::Matx44f
CVSurViewFisheyeDewarp::generate_rotation_matrix(float roll, float pitch, float yaw)
{
- cv::Matx44f matrix_x(1.0, 0.0, 0.0, 0.0,
- 0.0, cos(roll), -sin(roll), 0.0,
- 0.0, sin(roll), cos(roll), 0.0,
- 0.0, 0.0, 0.0, 1.0);
+ cv::Matx44f matrix_x(1.0, 0.0, 0.0, 0.0,
+ 0.0, cos(roll), -sin(roll), 0.0,
+ 0.0, sin(roll), cos(roll), 0.0,
+ 0.0, 0.0, 0.0, 1.0);
- cv::Matx44f matrix_y(cos(pitch), 0.0, sin(pitch), 0.0,
- 0.0, 1.0, 0.0, 0.0,
- -sin(pitch), 0.0, cos(pitch), 0.0,
- 0.0, 0.0, 0.0, 1.0);
+ cv::Matx44f matrix_y(cos(pitch), 0.0, sin(pitch), 0.0,
+ 0.0, 1.0, 0.0, 0.0,
+ -sin(pitch), 0.0, cos(pitch), 0.0,
+ 0.0, 0.0, 0.0, 1.0);
cv::Matx44f matrix_z(cos(yaw), -sin(yaw), 0.0, 0.0,
- sin(yaw), cos(yaw), 0.0, 0.0,
- 0.0, 0.0, 1.0, 0.0,
- 0.0, 0.0, 0.0, 1.0);
+ sin(yaw), cos(yaw), 0.0, 0.0,
+ 0.0, 0.0, 1.0, 0.0,
+ 0.0, 0.0, 0.0, 1.0);
return matrix_z * matrix_y * matrix_x;
}
@@ -210,6 +211,8 @@ CVSurViewFisheyeDewarp::world_coord2cam(MapTable cam_world_coord, MapTable &cam_ void
CVSurViewFisheyeDewarp::cal_image_coord(MapTable cam_coord, MapTable &image_coord)
{
+ image_coord[0] = cam_coord[0];
+ image_coord[1] = cam_coord[1];
}
void
diff --git a/modules/ocl/cv_surview_fisheye_dewarp.h b/modules/ocl/cv_surview_fisheye_dewarp.h index 3c098a8..b8e86b5 100644 --- a/modules/ocl/cv_surview_fisheye_dewarp.h +++ b/modules/ocl/cv_surview_fisheye_dewarp.h @@ -43,10 +43,10 @@ class BowlDataConfig {
public:
- explicit BowlDataConfig();
+ explicit BowlDataConfig();
- uint32_t image_height;
- uint32_t image_heightZ0;
+ uint32_t wall_image_height;
+ uint32_t ground_image_height;
float a, b, c;
float angle_start, angle_end;
@@ -68,10 +68,10 @@ public: IntrinsicParameter get_intrinsic_param();
ExtrinsicParameter get_extrinsic_param();
-
+
private:
XCAM_DEAD_COPY (CVSurViewFisheyeDewarp);
-
+
virtual void cal_image_coord(MapTable cam_coord, MapTable &image_coord);
void cal_world_coord(uint32_t x, uint32_t y, MapTable &world_coord, uint32_t image_w, const BowlDataConfig &bowl_config);
@@ -89,7 +89,7 @@ class CVPolyFisheyeDewarp : public CVSurViewFisheyeDewarp {
public:
- explicit CVPolyFisheyeDewarp ();
+ explicit CVPolyFisheyeDewarp ();
void cal_image_coord(MapTable cam_coord, MapTable &image_coord);
|