Dewobble
Video motion stabilization with awareness of lens projection
filter_sync.hpp
1 #ifndef DEWOBBLE_FILTER_SYNC_HPP
2 #define DEWOBBLE_FILTER_SYNC_HPP
3 
4 #include "filter_base.hpp"
5 #include "filter_config.hpp"
6 
7 #include <CL/opencl.hpp>
8 #include <opencv2/core/ocl.hpp>
9 #include <opencv2/imgproc.hpp>
10 #include <queue>
11 
12 #include "camera.hpp"
13 #include "stabilizer.hpp"
14 
15 namespace dewobble
16 {
17 
25 class FilterSync : public FilterBase
26 {
27  // The filter configuration
28  FilterConfig m_config;
29 
30  // mapping from output pixel to x coordinate in input image
31  cv::UMat m_map_x;
32 
33  // mapping from output pixel to y coordinate in input image
34  cv::UMat m_map_y;
35 
36  // The input frame, converted to BGR
37  cv::UMat m_frame_bgr;
38 
39  // The output frame in BGR, ready to be copied to the NV12 output buffer
40  cv::UMat m_warped_frame;
41 
42  // OpenCL kernel to build mapping table between input/output pixels
43  cv::ocl::Kernel m_remap_kernel;
44 
45  // OpenCL kernel to convert BGR image to NV12
46  cv::ocl::Kernel m_cvt_color_bgr_to_nv12_kernel;
47 
48  // OpenCL kernel to convert NV12 image to BGR
49  cv::ocl::Kernel m_cvt_color_nv12_to_bgr_kernel;
50 
51  // The last input frame
52  bool m_input_ended = false;
53 
54  // Buffered frames ready for output
55  std::queue<StabilizedFrame> m_buffered_frames;
56 
57  void cvtColorBgrToNv12(cv::UMat input, cv::UMat output);
58  void cvtColorNv12oBgr(cv::UMat input, cv::UMat output);
59  void add_debug_info(cv::UMat output, StabilizedFrame frame);
60  void warp_frame(cv::UMat input, cv::UMat output, cv::Mat rotation);
61  void flush_frames();
62  void init_after_changed_opencl_context();
63 
64  public:
69 
70  void push_frame(cl_mem input_buffer, void *extra);
71 
72  void end_input();
73 
74  bool frame_ready();
75 
76  void pull_frame(cl_mem *output_buffer, cl_mem *input_buffer, void **extra);
77 
82 };
83 } // namespace dewobble
84 
85 #endif // DEWOBBLE_FILTER_SYNC_HPP
Definition: filter_base.hpp:19
Definition: filter_config.hpp:83
Definition: filter_sync.hpp:26
cl_mem get_output_frame_buffer()
FilterSync(FilterConfig config)
void pull_frame(cl_mem *output_buffer, cl_mem *input_buffer, void **extra)
void push_frame(cl_mem input_buffer, void *extra)