/* * cl_video_stabilizer.h - Digital Video Stabilization using IMU (Gyroscope, Accelerometer) * * Copyright (c) 2017 Intel Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * Author: Zong Wei */ #ifndef XCAM_CL_VIDEO_STABILIZER_H #define XCAM_CL_VIDEO_STABILIZER_H #include #include #include #include #include namespace XCam { class MotionFilter; class ImageProjector; class CLVideoStabilizer; class CLImageWarpKernel; class CLImageWarpHandler; class CLVideoStabilizerKernel : public CLImageWarpKernel { public: explicit CLVideoStabilizerKernel ( const SmartPtr &context, const char *name, uint32_t channel, SmartPtr &handler); private: XCAM_DEAD_COPY (CLVideoStabilizerKernel); SmartPtr _handler; }; class CLVideoStabilizer : public CLImageWarpHandler { typedef std::list> CLImageBufferList; public: explicit CLVideoStabilizer ( const SmartPtr &context, const char *name = "CLVideoStabilizer"); virtual ~CLVideoStabilizer () { _input_buf_list.clear (); } virtual SmartPtr get_warp_input_buf (); virtual bool is_ready (); void reset_counter (); XCamReturn set_sensor_calibration (CalibrationParams ¶ms); XCamReturn set_camera_intrinsics ( double focal_x, double focal_y, double offset_x, double offset_y, double skew); XCamReturn align_coordinate_system ( CoordinateSystemConv& world_to_device, CoordinateSystemConv& device_to_image); XCamReturn set_motion_filter (uint32_t radius, float stdev); uint32_t filter_radius () const { return _filter_radius; }; Mat3d analyze_motion ( int64_t frame0_ts, DevicePoseList pose0_list, int64_t frame1_ts, DevicePoseList pose1_list); Mat3d stabilize_motion (int32_t stab_frame_id, std::list &motions); protected: virtual XCamReturn prepare_parameters (SmartPtr &input, SmartPtr &output); virtual XCamReturn execute_done (SmartPtr &output); private: XCAM_DEAD_COPY (CLVideoStabilizer); private: Mat3d _intrinsics; CalibrationParams _calib_params; SmartPtr _projector; SmartPtr _motion_filter; CoordinateSystemConv _world_to_device; CoordinateSystemConv _device_to_image; int64_t _input_frame_id; int64_t _frame_ts[2]; int64_t _stabilized_frame_id; DevicePoseList _device_pose[2]; std::list _motions; //motions[i] calculated from frame i to i+1 uint32_t _filter_radius; CLImageBufferList _input_buf_list; }; SmartPtr create_cl_video_stab_handler (const SmartPtr &context); class MotionFilter { public: MotionFilter (uint32_t radius = 15, float stdev = 10); virtual ~MotionFilter (); void set_filters (uint32_t radius, float stdev); uint32_t radius () const { return _radius; }; float stdev () const { return _stdev; }; Mat3d stabilize (int32_t index, std::list &motions, int32_t max); protected: Mat3d cumulate_motion (uint32_t index, uint32_t from, std::list &motions); private: XCAM_DEAD_COPY (MotionFilter); private: int32_t _radius; float _stdev; std::vector _weight; }; } #endif