aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYinhang Liu <yinhangx.liu@intel.com>2019-01-11 11:06:21 +0800
committerZong Wei <wei.zong@intel.com>2019-01-15 15:51:14 +0800
commita68e050d0c151ee80921e80e3d0f6864ccddff0c (patch)
tree9539709ee79af64c9f4a47e7ba8536878bb365dd
parent90bee3fafa3fbeed69ad7c9664da7803fdb10a50 (diff)
downloadlibxcam-a68e050d0c151ee80921e80e3d0f6864ccddff0c.tar.gz
feature-match: simplify function interface
-rw-r--r--modules/ocl/cl_image_360_stitch.cpp30
-rw-r--r--modules/ocv/cv_capi_feature_match.cpp52
-rw-r--r--modules/ocv/cv_capi_feature_match.h34
-rw-r--r--modules/ocv/cv_feature_match.cpp130
-rw-r--r--modules/ocv/cv_feature_match.h43
-rw-r--r--modules/ocv/cv_feature_match_cluster.cpp99
-rw-r--r--modules/ocv/cv_feature_match_cluster.h31
-rw-r--r--modules/soft/soft_stitcher.cpp126
-rw-r--r--xcore/interface/feature_match.cpp51
-rw-r--r--xcore/interface/feature_match.h30
-rw-r--r--xcore/interface/stitcher.h1
11 files changed, 349 insertions, 278 deletions
diff --git a/modules/ocl/cl_image_360_stitch.cpp b/modules/ocl/cl_image_360_stitch.cpp
index d30ec33..4c3948c 100644
--- a/modules/ocl/cl_image_360_stitch.cpp
+++ b/modules/ocl/cl_image_360_stitch.cpp
@@ -725,10 +725,15 @@ CLImage360Stitch::init_feature_match ()
{
#if HAVE_OPENCV
bool is_sphere = (_surround_mode == SphereView);
- FMConfig config = is_sphere ? get_fm_sphere_config (_res_mode) : get_fm_bowl_config ();
+ const FMConfig &config = is_sphere ? get_fm_sphere_config (_res_mode) : get_fm_bowl_config ();
for (int i = 0; i < _fisheye_num; i++) {
- _feature_match[i] = is_sphere ? new CVFeatureMatch () : new CVFeatureMatchCluster ();
+ if (is_sphere) {
+ _feature_match[i] = new CVFeatureMatch ();
+ _feature_match[i]->enable_adjust_crop_area ();
+ } else {
+ _feature_match[i] = new CVFeatureMatchCluster ();
+ }
XCAM_ASSERT (_feature_match[i].ptr ());
_feature_match[i]->set_fm_index (i);
@@ -864,8 +869,8 @@ CLImage360Stitch::set_fm_buf_mem (
cl_mem mem_left = cl_buf_left->get_mem_id ();
cl_mem mem_right = cl_buf_right->get_mem_id ();
- fm->set_cl_buf_mem (mem_left, CVFeatureMatch::BufId0);
- fm->set_cl_buf_mem (mem_right, CVFeatureMatch::BufId1);
+ fm->set_cl_buf_mem (mem_left, CVFeatureMatch::BufIdLeft);
+ fm->set_cl_buf_mem (mem_right, CVFeatureMatch::BufIdRight);
#else
XCAM_LOG_ERROR ("non-OpenCV mode, failed to set feature match buffer memory");
#endif
@@ -873,7 +878,7 @@ CLImage360Stitch::set_fm_buf_mem (
#if HAVE_OPENCV
static void
-convert_to_stitch_rect (Rect xcam_rect, Rect &stitch_rect, SurroundMode surround_mode)
+convert_to_stitch_rect (const Rect &xcam_rect, Rect &stitch_rect, SurroundMode surround_mode)
{
stitch_rect.pos_x = xcam_rect.pos_x;
stitch_rect.width = xcam_rect.width;
@@ -887,7 +892,7 @@ convert_to_stitch_rect (Rect xcam_rect, Rect &stitch_rect, SurroundMode surround
}
static void
-convert_to_xcam_rect (Rect stitch_rect, Rect &xcam_rect)
+convert_to_xcam_rect (const Rect &stitch_rect, Rect &xcam_rect)
{
xcam_rect.pos_x = stitch_rect.pos_x;
xcam_rect.width = stitch_rect.width;
@@ -912,18 +917,17 @@ CLImage360Stitch::sub_handler_execute_done (SmartPtr<CLImageHandler> &handler)
convert_to_stitch_rect (_img_merge_info[i].right, crop_left, _surround_mode);
convert_to_stitch_rect (_img_merge_info[idx_next].left, crop_right, _surround_mode);
if (_surround_mode == SphereView) {
- _feature_match[i]->optical_flow_feature_match (
- _fisheye[i].buf, _fisheye[idx_next].buf, crop_left, crop_right, _fisheye[i].width);
+ _feature_match[i]->set_dst_width (_fisheye[i].width);
+ _feature_match[i]->set_crop_rect (crop_left, crop_right);
+ _feature_match[i]->feature_match (_fisheye[i].buf, _fisheye[idx_next].buf);
+ _feature_match[i]->get_crop_rect (crop_left, crop_right);
convert_to_xcam_rect (crop_left, _img_merge_info[i].right);
convert_to_xcam_rect (crop_right, _img_merge_info[idx_next].left);
} else {
- Rect tmp_crop_left = crop_left;
- Rect tmp_crop_right = crop_right;
-
_feature_match[i]->reset_offsets ();
- _feature_match[i]->optical_flow_feature_match (
- _fisheye[i].buf, _fisheye[idx_next].buf, tmp_crop_left, tmp_crop_right, _fisheye[i].width);
+ _feature_match[i]->set_crop_rect (crop_left, crop_right);
+ _feature_match[i]->feature_match (_fisheye[i].buf, _fisheye[idx_next].buf);
update_scale_factors (i, crop_left, crop_right);
}
diff --git a/modules/ocv/cv_capi_feature_match.cpp b/modules/ocv/cv_capi_feature_match.cpp
index ffed593..9f7d34c 100644
--- a/modules/ocv/cv_capi_feature_match.cpp
+++ b/modules/ocv/cv_capi_feature_match.cpp
@@ -27,7 +27,7 @@
namespace XCam {
CVCapiFeatureMatch::CVCapiFeatureMatch ()
- : FeatureMatch()
+ : FeatureMatch ()
{
}
@@ -54,8 +54,7 @@ CVCapiFeatureMatch::get_crop_image (
}
void
-CVCapiFeatureMatch::add_detected_data (
- CvArr* image, std::vector<CvPoint2D32f> &corners)
+CVCapiFeatureMatch::add_detected_data (CvArr* image, std::vector<CvPoint2D32f> &corners)
{
std::vector<CvPoint2D32f> keypoints;
@@ -118,10 +117,8 @@ CVCapiFeatureMatch::get_valid_offsets (
void
CVCapiFeatureMatch::calc_of_match (
- CvArr* image0, CvArr* image1,
- std::vector<CvPoint2D32f> &corner0, std::vector<CvPoint2D32f> &corner1,
- std::vector<char> &status, std::vector<float> &error,
- int &last_count, float &last_mean_offset, float &out_x_offset)
+ CvArr* image0, CvArr* image1, std::vector<CvPoint2D32f> &corner0, std::vector<CvPoint2D32f> &corner1,
+ std::vector<char> &status, std::vector<float> &error)
{
CvMat debug_image;
CvSize img0_size = cvSize(((CvMat*)image0)->width, ((CvMat*)image0)->height);
@@ -132,6 +129,7 @@ CVCapiFeatureMatch::calc_of_match (
float offset_sum = 0.0f;
int count = 0;
float mean_offset = 0.0f;
+ float last_mean_offset = _mean_offset;
offsets.reserve (corner0.size ());
#if XCAM_CV_CAPI_FM_DEBUG
@@ -156,20 +154,19 @@ CVCapiFeatureMatch::calc_of_match (
bool ret = get_mean_offset (offsets, offset_sum, count, mean_offset);
if (ret) {
if (fabs (mean_offset - last_mean_offset) < _config.delta_mean_offset) {
- out_x_offset = out_x_offset * _config.offset_factor + mean_offset * (1.0f - _config.offset_factor);
+ _x_offset = _x_offset * _config.offset_factor + mean_offset * (1.0f - _config.offset_factor);
- if (fabs (out_x_offset) > _config.max_adjusted_offset)
- out_x_offset = (out_x_offset > 0.0f) ? _config.max_adjusted_offset : (-_config.max_adjusted_offset);
+ if (fabs (_x_offset) > _config.max_adjusted_offset)
+ _x_offset = (_x_offset > 0.0f) ? _config.max_adjusted_offset : (-_config.max_adjusted_offset);
}
}
- last_count = count;
- last_mean_offset = mean_offset;
+ _valid_count = count;
+ _mean_offset = mean_offset;
}
void
-CVCapiFeatureMatch::detect_and_match (
- CvArr* img_left, CvArr* img_right, int &valid_count, float &mean_offset, float &x_offset)
+CVCapiFeatureMatch::detect_and_match (CvArr* img_left, CvArr* img_right)
{
std::vector<float> err;
std::vector<char> status;
@@ -201,28 +198,26 @@ CVCapiFeatureMatch::detect_and_match (
XCAM_LOG_INFO ("FeatureMatch(idx:%d): matched corners:%d", _fm_idx, count);
#endif
- calc_of_match (img_left, img_right, corner_left, corner_right,
- status, err, valid_count, mean_offset, x_offset);
+ calc_of_match (img_left, img_right, corner_left, corner_right, status, err);
#if XCAM_CV_CAPI_FM_DEBUG
- XCAM_LOG_INFO ("FeatureMatch(idx:%d): x_offset:%0.2f", _fm_idx, x_offset);
+ XCAM_LOG_INFO ("FeatureMatch(idx:%d): x_offset:%0.2f", _fm_idx, _x_offset);
#endif
}
void
-CVCapiFeatureMatch::optical_flow_feature_match (
- const SmartPtr<VideoBuffer> &left_buf, const SmartPtr<VideoBuffer> &right_buf,
- Rect &left_crop_rect, Rect &right_crop_rect, int dst_width)
+CVCapiFeatureMatch::feature_match (
+ const SmartPtr<VideoBuffer> &left_buf, const SmartPtr<VideoBuffer> &right_buf)
{
- CvMat left_img, right_img;
+ XCAM_ASSERT (_left_rect.width && _left_rect.height);
+ XCAM_ASSERT (_right_rect.width && _right_rect.height);
- if (!get_crop_image (left_buf, left_crop_rect, _left_crop_image, left_img)
- || !get_crop_image (right_buf, right_crop_rect, _right_crop_image, right_img))
+ CvMat left_img, right_img;
+ if (!get_crop_image (left_buf, _left_rect, _left_crop_image, left_img)
+ || !get_crop_image (right_buf, _right_rect, _right_crop_image, right_img))
return;
- detect_and_match ((CvArr*)(&left_img), (CvArr*)(&right_img), _valid_count, _mean_offset, _x_offset);
-
- XCAM_UNUSED (dst_width);
+ detect_and_match ((CvArr*)(&left_img), (CvArr*)(&right_img));
#if XCAM_CV_CAPI_FM_DEBUG
XCAM_ASSERT (_fm_idx >= 0);
@@ -234,9 +229,9 @@ CVCapiFeatureMatch::optical_flow_feature_match (
char img_name[256] = {'\0'};
std::snprintf (img_name, 256, "fm_in_stitch_area_%d_%d_0.jpg", _frame_num, _fm_idx);
- write_image (left_buf, left_crop_rect, img_name, frame_str, fm_idx_str);
+ write_image (left_buf, _left_rect, img_name, frame_str, fm_idx_str);
std::snprintf (img_name, 256, "fm_in_stitch_area_%d_%d_1.jpg", _frame_num, _fm_idx);
- write_image (right_buf, right_crop_rect, img_name, frame_str, fm_idx_str);
+ write_image (right_buf, _right_rect, img_name, frame_str, fm_idx_str);
XCAM_LOG_INFO ("FeatureMatch(idx:%d): frame number:%d done", _fm_idx, _frame_num);
@@ -244,5 +239,4 @@ CVCapiFeatureMatch::optical_flow_feature_match (
#endif
}
-
}
diff --git a/modules/ocv/cv_capi_feature_match.h b/modules/ocv/cv_capi_feature_match.h
index 3e45722..f1f8794 100644
--- a/modules/ocv/cv_capi_feature_match.h
+++ b/modules/ocv/cv_capi_feature_match.h
@@ -42,33 +42,31 @@ class CVCapiFeatureMatch
public:
explicit CVCapiFeatureMatch ();
- void optical_flow_feature_match (
- const SmartPtr<VideoBuffer> &left_buf, const SmartPtr<VideoBuffer> &right_buf,
- Rect &left_img_crop, Rect &right_img_crop, int dst_width = 0);
+ virtual void feature_match (
+ const SmartPtr<VideoBuffer> &left_buf, const SmartPtr<VideoBuffer> &right_buf);
-protected:
- bool get_crop_image (const SmartPtr<VideoBuffer> &buffer, const Rect &crop_rect,
- std::vector<char> &crop_image, CvMat &img);
+private:
+ bool get_crop_image (
+ const SmartPtr<VideoBuffer> &buffer, const Rect &crop_rect, std::vector<char> &crop_image, CvMat &img);
+ void detect_and_match (CvArr* img_left, CvArr* img_right);
void add_detected_data (CvArr* image, std::vector<CvPoint2D32f> &corners);
- void get_valid_offsets (std::vector<CvPoint2D32f> &corner0, std::vector<CvPoint2D32f> &corner1,
- std::vector<char> &status, std::vector<float> &error,
- std::vector<float> &offsets, float &sum, int &count,
- CvArr* out_image, CvSize &img0_size);
- void calc_of_match (CvArr* image0, CvArr* image1,
- std::vector<CvPoint2D32f> &corner0, std::vector<CvPoint2D32f> &corner1,
- std::vector<char> &status, std::vector<float> &error,
- int &last_count, float &last_mean_offset, float &out_x_offset);
+ void calc_of_match (
+ CvArr* image0, CvArr* image1, std::vector<CvPoint2D32f> &corner0, std::vector<CvPoint2D32f> &corner1,
+ std::vector<char> &status, std::vector<float> &error);
- void detect_and_match (CvArr* img_left, CvArr* img_right,
- int &valid_count, float &mean_offset, float &x_offset);
+ void get_valid_offsets (
+ std::vector<CvPoint2D32f> &corner0, std::vector<CvPoint2D32f> &corner1,
+ std::vector<char> &status, std::vector<float> &error,
+ std::vector<float> &offsets, float &sum, int &count,
+ CvArr* out_image, CvSize &img0_size);
private:
XCAM_DEAD_COPY (CVCapiFeatureMatch);
- std::vector<char> _left_crop_image;
- std::vector<char> _right_crop_image;
+ std::vector<char> _left_crop_image;
+ std::vector<char> _right_crop_image;
};
}
diff --git a/modules/ocv/cv_feature_match.cpp b/modules/ocv/cv_feature_match.cpp
index 5294804..1bf9d60 100644
--- a/modules/ocv/cv_feature_match.cpp
+++ b/modules/ocv/cv_feature_match.cpp
@@ -32,7 +32,10 @@
namespace XCam {
CVFeatureMatch::CVFeatureMatch ()
: FeatureMatch ()
+ , _dst_width (0)
+ , _need_adjust (false)
{
+ xcam_mem_clear (_cl_buf_mem);
}
CVFeatureMatch::~CVFeatureMatch ()
@@ -40,6 +43,19 @@ CVFeatureMatch::~CVFeatureMatch ()
xcam_mem_clear (_cl_buf_mem);
}
+
+void
+CVFeatureMatch::set_dst_width (int width)
+{
+ _dst_width = width;
+}
+
+void
+CVFeatureMatch::enable_adjust_crop_area ()
+{
+ _need_adjust = true;
+}
+
void
CVFeatureMatch::set_cl_buf_mem (void *mem, BufId id)
{
@@ -128,10 +144,8 @@ CVFeatureMatch::get_valid_offsets (
void
CVFeatureMatch::calc_of_match (
- cv::Mat image0, cv::Mat image1,
- std::vector<cv::Point2f> &corner0, std::vector<cv::Point2f> &corner1,
- std::vector<uchar> &status, std::vector<float> &error,
- int &last_count, float &last_mean_offset, float &out_x_offset)
+ cv::Mat image0, cv::Mat image1, std::vector<cv::Point2f> &corner0, std::vector<cv::Point2f> &corner1,
+ std::vector<uchar> &status, std::vector<float> &error)
{
cv::Mat debug_img;
cv::Size img0_size = image0.size ();
@@ -139,11 +153,15 @@ CVFeatureMatch::calc_of_match (
XCAM_ASSERT (img0_size.height == img1_size.height);
#if XCAM_CV_FM_DEBUG
+ cv::Mat mat;
cv::Size size (img0_size.width + img1_size.width, img0_size.height);
- debug_img.create (size, image0.type ());
- image0.copyTo (debug_img (cv::Rect(0, 0, img0_size.width, img0_size.height)));
- image1.copyTo (debug_img (cv::Rect(img0_size.width, 0, img1_size.width, img1_size.height)));
+ mat.create (size, image0.type ());
+ debug_img = cv::Mat (mat);
+
+ image0.copyTo (mat (cv::Rect(0, 0, img0_size.width, img0_size.height)));
+ image1.copyTo (mat (cv::Rect(img0_size.width, 0, img1_size.width, img1_size.height)));
+ mat.copyTo (debug_img);
cv::Size scale_size = size * XCAM_CV_OF_DRAW_SCALE;
cv::resize (debug_img, debug_img, scale_size, 0, 0);
@@ -153,6 +171,7 @@ CVFeatureMatch::calc_of_match (
float offset_sum = 0.0f;
int count = 0;
float mean_offset = 0.0f;
+ float last_mean_offset = _mean_offset;
offsets.reserve (corner0.size ());
get_valid_offsets (corner0, corner1, status, error,
offsets, offset_sum, count, debug_img, img0_size);
@@ -166,46 +185,48 @@ CVFeatureMatch::calc_of_match (
bool ret = get_mean_offset (offsets, offset_sum, count, mean_offset);
if (ret) {
if (fabs (mean_offset - last_mean_offset) < _config.delta_mean_offset) {
- out_x_offset = out_x_offset * _config.offset_factor + mean_offset * (1.0f - _config.offset_factor);
+ _x_offset = _x_offset * _config.offset_factor + mean_offset * (1.0f - _config.offset_factor);
- if (fabs (out_x_offset) > _config.max_adjusted_offset)
- out_x_offset = (out_x_offset > 0.0f) ? _config.max_adjusted_offset : (-_config.max_adjusted_offset);
+ if (fabs (_x_offset) > _config.max_adjusted_offset)
+ _x_offset = (_x_offset > 0.0f) ? _config.max_adjusted_offset : (-_config.max_adjusted_offset);
}
}
- last_count = count;
- last_mean_offset = mean_offset;
+ _valid_count = count;
+ _mean_offset = mean_offset;
}
void
-CVFeatureMatch::adjust_stitch_area (int dst_width, float &x_offset, Rect &stitch0, Rect &stitch1)
+CVFeatureMatch::adjust_crop_area ()
{
- if (fabs (x_offset) < 5.0f)
+ if (fabs (_x_offset) < 5.0f)
return;
- int last_overlap_width = stitch1.pos_x + stitch1.width + (dst_width - (stitch0.pos_x + stitch0.width));
- // int final_overlap_width = stitch1.pos_x + stitch1.width + (dst_width - (stitch0.pos_x - x_offset + stitch0.width));
- if ((stitch0.pos_x - x_offset + stitch0.width) > dst_width)
- x_offset = dst_width - (stitch0.pos_x + stitch0.width);
- int final_overlap_width = last_overlap_width + x_offset;
+ XCAM_ASSERT (_dst_width);
+
+ int last_overlap_width = _right_rect.pos_x + _right_rect.width +
+ (_dst_width - (_left_rect.pos_x + _left_rect.width));
+ // int final_overlap_width = _right_rect.pos_x + _right_rect.width +
+ // (dst_width - (_left_rect.pos_x - x_offset + _left_rect.width));
+ if ((_left_rect.pos_x - _x_offset + _left_rect.width) > _dst_width)
+ _x_offset = _dst_width - (_left_rect.pos_x + _left_rect.width);
+ int final_overlap_width = last_overlap_width + _x_offset;
final_overlap_width = XCAM_ALIGN_AROUND (final_overlap_width, 8);
XCAM_ASSERT (final_overlap_width >= _config.sitch_min_width);
int center = final_overlap_width / 2;
XCAM_ASSERT (center >= _config.sitch_min_width / 2);
- stitch1.pos_x = XCAM_ALIGN_AROUND (center - _config.sitch_min_width / 2, 8);
- stitch1.width = _config.sitch_min_width;
- stitch0.pos_x = dst_width - final_overlap_width + stitch1.pos_x;
- stitch0.width = _config.sitch_min_width;
+ _right_rect.pos_x = XCAM_ALIGN_AROUND (center - _config.sitch_min_width / 2, 8);
+ _right_rect.width = _config.sitch_min_width;
+ _left_rect.pos_x = _dst_width - final_overlap_width + _right_rect.pos_x;
+ _left_rect.width = _config.sitch_min_width;
float delta_offset = final_overlap_width - last_overlap_width;
- x_offset -= delta_offset;
+ _x_offset -= delta_offset;
}
void
-CVFeatureMatch::detect_and_match (
- cv::Mat img_left, cv::Mat img_right, Rect &crop_left, Rect &crop_right,
- int &valid_count, float &mean_offset, float &x_offset, int dst_width)
+CVFeatureMatch::detect_and_match (cv::Mat img_left, cv::Mat img_right)
{
std::vector<float> err;
std::vector<uchar> status;
@@ -224,43 +245,48 @@ CVFeatureMatch::detect_and_match (
img_left, img_right, corner_left, corner_right, status, err, win_size, 3,
cv::TermCriteria (cv::TermCriteria::COUNT + cv::TermCriteria::EPS, 10, 0.01f));
- calc_of_match (img_left, img_right, corner_left, corner_right,
- status, err, valid_count, mean_offset, x_offset);
+ calc_of_match (img_left, img_right, corner_left, corner_right, status, err);
- adjust_stitch_area (dst_width, x_offset, crop_left, crop_right);
+ if (_need_adjust)
+ adjust_crop_area ();
-#if XCAM_CV_FM_DEBUG
- XCAM_LOG_INFO (
- "FeatureMatch(idx:%d): stiching area: left_area(pos_x:%d, width:%d), right_area(pos_x:%d, width:%d)",
- _fm_idx, crop_left.pos_x, crop_left.width, crop_right.pos_x, crop_right.width);
+#if XCAM_CV_CAPI_FM_DEBUG
+ XCAM_LOG_INFO ("FeatureMatch(idx:%d): x_offset:%0.2f", _fm_idx, _x_offset);
+ if (_need_adjust) {
+ XCAM_LOG_INFO (
+ "FeatureMatch(idx:%d): stiching area: left_area(pos_x:%d, width:%d), right_area(pos_x:%d, width:%d)",
+ _fm_idx, _left_rect.pos_x, _left_rect.width, _right_rect.pos_x, _right_rect.width);
+ }
#endif
}
void
-CVFeatureMatch::optical_flow_feature_match (
- const SmartPtr<VideoBuffer> &left_buf, const SmartPtr<VideoBuffer> &right_buf,
- Rect &left_crop_rect, Rect &right_crop_rect, int dst_width)
+CVFeatureMatch::feature_match (
+ const SmartPtr<VideoBuffer> &left_buf, const SmartPtr<VideoBuffer> &right_buf)
{
-#if HAVE_LIBCL
- cv::UMat left_umat, right_umat;
- if (!get_crop_image_umat (left_buf, left_crop_rect, left_umat, BufId0)
- || !get_crop_image_umat (right_buf, right_crop_rect, right_umat, BufId1))
- return;
+ XCAM_ASSERT (_left_rect.width && _left_rect.height);
+ XCAM_ASSERT (_right_rect.width && _right_rect.height);
- cv::Mat left_img = left_umat.getMat (cv::ACCESS_READ);
- cv::Mat right_img = right_umat.getMat (cv::ACCESS_READ);
-#else
+ cv::UMat left_umat, right_umat;
cv::Mat left_img, right_img;
- if (!convert_range_to_mat (left_buf, left_crop_rect, left_img)
- || !convert_range_to_mat (right_buf, right_crop_rect, right_img))
- return;
-#endif
- detect_and_match (left_img, right_img, left_crop_rect, right_crop_rect,
- _valid_count, _mean_offset, _x_offset, dst_width);
+ if (_cl_buf_mem[BufIdLeft] && _cl_buf_mem[BufIdRight]) {
+ if (!get_crop_image_umat (left_buf, _left_rect, left_umat, BufIdLeft)
+ || !get_crop_image_umat (right_buf, _right_rect, right_umat, BufIdRight))
+ return;
+
+ left_img = left_umat.getMat (cv::ACCESS_READ);
+ right_img = right_umat.getMat (cv::ACCESS_READ);
+ } else {
+ if (!convert_range_to_mat (left_buf, _left_rect, left_img)
+ || !convert_range_to_mat (right_buf, _right_rect, right_img))
+ return;
+ }
+
+ detect_and_match (left_img, right_img);
#if XCAM_CV_FM_DEBUG
- debug_write_image (left_buf, right_buf, left_crop_rect, right_crop_rect, _frame_num, _fm_idx);
+ debug_write_image (left_buf, right_buf, _left_rect, _right_rect, _frame_num, _fm_idx);
_frame_num++;
#endif
}
diff --git a/modules/ocv/cv_feature_match.h b/modules/ocv/cv_feature_match.h
index 598cb74..5d2fbc7 100644
--- a/modules/ocv/cv_feature_match.h
+++ b/modules/ocv/cv_feature_match.h
@@ -33,8 +33,8 @@ class CVFeatureMatch
{
public:
enum BufId {
- BufId0 = 0,
- BufId1,
+ BufIdLeft = 0,
+ BufIdRight,
BufIdMax
};
@@ -42,9 +42,8 @@ public:
explicit CVFeatureMatch ();
virtual ~CVFeatureMatch ();
- virtual void optical_flow_feature_match (
- const SmartPtr<VideoBuffer> &left_buf, const SmartPtr<VideoBuffer> &right_buf,
- Rect &left_img_crop, Rect &right_img_crop, int dst_width = 0);
+ virtual void feature_match (
+ const SmartPtr<VideoBuffer> &left_buf, const SmartPtr<VideoBuffer> &right_buf);
void set_cl_buf_mem (void *mem, BufId id);
@@ -56,28 +55,32 @@ protected:
const SmartPtr<VideoBuffer> &left_buf, const SmartPtr<VideoBuffer> &right_buf,
const Rect &left_rect, const Rect &right_rect, uint32_t frame_num, int fm_idx);
- void get_valid_offsets (std::vector<cv::Point2f> &corner0, std::vector<cv::Point2f> &corner1,
- std::vector<uchar> &status, std::vector<float> &error,
- std::vector<float> &offsets, float &sum, int &count,
- cv::Mat debug_img, cv::Size &img0_size);
-
- void calc_of_match (cv::Mat image0, cv::Mat image1,
- std::vector<cv::Point2f> &corner0, std::vector<cv::Point2f> &corner1,
- std::vector<uchar> &status, std::vector<float> &error,
- int &last_count, float &last_mean_offset, float &out_x_offset);
+private:
+ virtual void detect_and_match (cv::Mat img_left, cv::Mat img_right);
+ virtual void calc_of_match (
+ cv::Mat image0, cv::Mat image1, std::vector<cv::Point2f> &corner0, std::vector<cv::Point2f> &corner1,
+ std::vector<uchar> &status, std::vector<float> &error);
- void detect_and_match (cv::Mat img_left, cv::Mat img_right, Rect &crop_left, Rect &crop_right,
- int &valid_count, float &mean_offset, float &x_offset, int dst_width);
+ void get_valid_offsets (
+ std::vector<cv::Point2f> &corner0, std::vector<cv::Point2f> &corner1,
+ std::vector<uchar> &status, std::vector<float> &error,
+ std::vector<float> &offsets, float &sum, int &count,
+ cv::Mat debug_img, cv::Size &img0_size);
- void adjust_stitch_area (int dst_width, float &x_offset, Rect &stitch0, Rect &stitch1);
+ void adjust_crop_area ();
- void debug_write_image ( const SmartPtr<VideoBuffer> &buf, const Rect &rect, char *img_name,
- char *frame_str, char *fm_idx_str);
+ virtual void set_dst_width (int width);
+ virtual void enable_adjust_crop_area ();
private:
XCAM_DEAD_COPY (CVFeatureMatch);
- void *_cl_buf_mem[BufIdMax];
+protected:
+ void *_cl_buf_mem[BufIdMax];
+
+private:
+ int _dst_width;
+ bool _need_adjust;
};
}
diff --git a/modules/ocv/cv_feature_match_cluster.cpp b/modules/ocv/cv_feature_match_cluster.cpp
index af5b1c2..92df89c 100644
--- a/modules/ocv/cv_feature_match_cluster.cpp
+++ b/modules/ocv/cv_feature_match_cluster.cpp
@@ -183,12 +183,9 @@ CVFeatureMatchCluster::calc_mean_offset (
}
void
-CVFeatureMatchCluster::calc_of_match_cluster (
- cv::Mat image0, cv::Mat image1,
- std::vector<cv::Point2f> &corner0, std::vector<cv::Point2f> &corner1,
- std::vector<uchar> &status, std::vector<float> &error,
- float &last_mean_offset_x, float &last_mean_offset_y,
- float &out_x_offset, float &out_y_offset)
+CVFeatureMatchCluster::calc_of_match (
+ cv::Mat image0, cv::Mat image1, std::vector<cv::Point2f> &corner0, std::vector<cv::Point2f> &corner1,
+ std::vector<uchar> &status, std::vector<float> &error)
{
cv::Mat debug_img;
cv::Size img0_size = image0.size ();
@@ -196,13 +193,18 @@ CVFeatureMatchCluster::calc_of_match_cluster (
XCAM_ASSERT (img0_size.height == img1_size.height);
#if XCAM_CV_FM_DEBUG
+ cv::Mat mat;
cv::Size size ((img0_size.width + img1_size.width) * 2, img0_size.height);
- debug_img.create (size, image0.type ());
- image0.copyTo (debug_img (cv::Rect(0, 0, img0_size.width, img0_size.height)));
- image1.copyTo (debug_img (cv::Rect(img0_size.width, 0, img1_size.width, img1_size.height)));
- image0.copyTo (debug_img (cv::Rect(img0_size.width + img1_size.width, 0, img0_size.width, img0_size.height)));
- image1.copyTo (debug_img (cv::Rect(2 * img0_size.width + img1_size.width, 0, img1_size.width, img1_size.height)));
+ mat.create (size, image0.type ());
+ debug_img = cv::Mat (mat);
+
+ image0.copyTo (mat (cv::Rect(0, 0, img0_size.width, img0_size.height)));
+ image1.copyTo (mat (cv::Rect(img0_size.width, 0, img1_size.width, img1_size.height)));
+ image0.copyTo (mat (cv::Rect(img0_size.width + img1_size.width, 0, img0_size.width, img0_size.height)));
+ image1.copyTo (mat (cv::Rect(2 * img0_size.width + img1_size.width, 0, img1_size.width, img1_size.height)));
+
+ mat.copyTo (debug_img);
cv::Size scale_size = size * XCAM_CV_OF_DRAW_SCALE;
cv::resize (debug_img, debug_img, scale_size, 0, 0);
@@ -210,7 +212,10 @@ CVFeatureMatchCluster::calc_of_match_cluster (
float mean_offset_x = 0.0f;
float mean_offset_y = 0.0f;
- bool ret = calc_mean_offset (corner0, corner1, status, error, mean_offset_x, mean_offset_y, debug_img, img0_size, img1_size);
+ float last_mean_offset_x = _mean_offset;
+ float last_mean_offset_y = _mean_offset_y;
+ bool ret = calc_mean_offset (corner0, corner1, status, error, mean_offset_x, mean_offset_y,
+ debug_img, img0_size, img1_size);
#if XCAM_CV_FM_DEBUG
char file_name[256];
@@ -220,28 +225,26 @@ CVFeatureMatchCluster::calc_of_match_cluster (
if (ret) {
if (fabs (mean_offset_x - last_mean_offset_x) < _config.delta_mean_offset) {
- out_x_offset = out_x_offset * _config.offset_factor + mean_offset_x * (1.0f - _config.offset_factor);
+ _x_offset = _x_offset * _config.offset_factor + mean_offset_x * (1.0f - _config.offset_factor);
- if (fabs (out_x_offset) > _config.max_adjusted_offset)
- out_x_offset = (out_x_offset > 0.0f) ? _config.max_adjusted_offset : (-_config.max_adjusted_offset);
+ if (fabs (_x_offset) > _config.max_adjusted_offset)
+ _x_offset = (_x_offset > 0.0f) ? _config.max_adjusted_offset : (-_config.max_adjusted_offset);
}
if (fabs (mean_offset_y - last_mean_offset_y) < _config.delta_mean_offset) {
- out_y_offset = out_y_offset * _config.offset_factor + mean_offset_y * (1.0f - _config.offset_factor);
+ _y_offset = _y_offset * _config.offset_factor + mean_offset_y * (1.0f - _config.offset_factor);
- if (fabs (out_y_offset) > _config.max_adjusted_offset)
- out_y_offset = (out_y_offset > 0.0f) ? _config.max_adjusted_offset : (-_config.max_adjusted_offset);
+ if (fabs (_y_offset) > _config.max_adjusted_offset)
+ _y_offset = (_y_offset > 0.0f) ? _config.max_adjusted_offset : (-_config.max_adjusted_offset);
}
}
- last_mean_offset_x = mean_offset_x;
- last_mean_offset_y = mean_offset_y;
+ _mean_offset = mean_offset_x;
+ _mean_offset_y = mean_offset_y;
}
void
-CVFeatureMatchCluster::detect_and_match_cluster (
- cv::Mat img_left, cv::Mat img_right, Rect &crop_left, Rect &crop_right,
- float &mean_offset_x, float &mean_offset_y, float &x_offset, float &y_offset)
+CVFeatureMatchCluster::detect_and_match (cv::Mat img_left, cv::Mat img_right)
{
std::vector<float> err;
std::vector<uchar> status;
@@ -260,49 +263,45 @@ CVFeatureMatchCluster::detect_and_match_cluster (
img_left, img_right, corner_left, corner_right, status, err, win_size, 3,
cv::TermCriteria (cv::TermCriteria::COUNT + cv::TermCriteria::EPS, 30, 0.01f));
- calc_of_match_cluster (img_left, img_right, corner_left, corner_right,
- status, err, mean_offset_x, mean_offset_y, x_offset, y_offset);
+ calc_of_match (img_left, img_right, corner_left, corner_right, status, err);
#if XCAM_CV_FM_DEBUG
- XCAM_LOG_INFO ("x_offset:%0.2f", x_offset);
+ XCAM_LOG_INFO ("x_offset:%0.2f", _x_offset);
XCAM_LOG_INFO (
"FeatureMatch(idx:%d): stiching area: left_area(pos_x:%d, width:%d), right_area(pos_x:%d, width:%d)",
- _fm_idx, crop_left.pos_x, crop_left.width, crop_right.pos_x, crop_right.width);
+ _fm_idx, _left_rect.pos_x, _left_rect.width, _right_rect.pos_x, _right_rect.width);
#endif
-
- XCAM_UNUSED (crop_left);
- XCAM_UNUSED (crop_right);
}
void
-CVFeatureMatchCluster::optical_flow_feature_match (
- const SmartPtr<VideoBuffer> &left_buf, const SmartPtr<VideoBuffer> &right_buf,
- Rect &left_crop_rect, Rect &right_crop_rect, int dst_width)
+CVFeatureMatchCluster::feature_match (
+ const SmartPtr<VideoBuffer> &left_buf, const SmartPtr<VideoBuffer> &right_buf)
{
-#if HAVE_LIBCL
- cv::UMat left_umat, right_umat;
- if (!get_crop_image_umat (left_buf, left_crop_rect, left_umat, BufId0)
- || !get_crop_image_umat (right_buf, right_crop_rect, right_umat, BufId1))
- return;
+ XCAM_ASSERT (_left_rect.width && _left_rect.height);
+ XCAM_ASSERT (_right_rect.width && _right_rect.height);
- cv::Mat left_img = left_umat.getMat (cv::ACCESS_READ);
- cv::Mat right_img = right_umat.getMat (cv::ACCESS_READ);
-#else
+ cv::UMat left_umat, right_umat;
cv::Mat left_img, right_img;
- if (!convert_range_to_mat (left_buf, left_crop_rect, left_img)
- || !convert_range_to_mat (right_buf, right_crop_rect, right_img))
- return;
-#endif
- detect_and_match_cluster (left_img, right_img, left_crop_rect, right_crop_rect,
- _mean_offset, _mean_offset_y, _x_offset, _y_offset);
+ if (_cl_buf_mem[BufIdLeft] && _cl_buf_mem[BufIdRight]) {
+ if (!get_crop_image_umat (left_buf, _left_rect, left_umat, BufIdLeft)
+ || !get_crop_image_umat (right_buf, _right_rect, right_umat, BufIdRight))
+ return;
+
+ left_img = left_umat.getMat (cv::ACCESS_READ);
+ right_img = right_umat.getMat (cv::ACCESS_READ);
+ } else {
+ if (!convert_range_to_mat (left_buf, _left_rect, left_img)
+ || !convert_range_to_mat (right_buf, _right_rect, right_img))
+ return;
+ }
+
+ detect_and_match (left_img, right_img);
#if XCAM_CV_FM_DEBUG
- debug_write_image (left_buf, right_buf, left_crop_rect, right_crop_rect, _frame_num, _fm_idx);
+ debug_write_image (left_buf, right_buf, _left_rect, _right_rect, _frame_num, _fm_idx);
_frame_num++;
#endif
-
- XCAM_UNUSED (dst_width);
}
}
diff --git a/modules/ocv/cv_feature_match_cluster.h b/modules/ocv/cv_feature_match_cluster.h
index 3e24bc7..1b1fcdb 100644
--- a/modules/ocv/cv_feature_match_cluster.h
+++ b/modules/ocv/cv_feature_match_cluster.h
@@ -31,26 +31,19 @@ class CVFeatureMatchCluster
public:
explicit CVFeatureMatchCluster ();
- void optical_flow_feature_match (
- const SmartPtr<VideoBuffer> &left_buf, const SmartPtr<VideoBuffer> &right_buf,
- Rect &left_img_crop, Rect &right_img_crop, int dst_width = 0);
-
-protected:
- bool calc_mean_offset (std::vector<cv::Point2f> &corner0, std::vector<cv::Point2f> &corner1,
- std::vector<uchar> &status, std::vector<float> &error,
- float &mean_offset_x, float &mean_offset_y,
- cv::Mat debug_img, cv::Size &img0_size, cv::Size &img1_size);
-
- void calc_of_match_cluster (cv::Mat image0, cv::Mat image1,
- std::vector<cv::Point2f> &corner0, std::vector<cv::Point2f> &corner1,
- std::vector<uchar> &status, std::vector<float> &error,
- float &last_mean_offset_x, float &last_mean_offset_y,
- float &out_x_offset, float &out_y_offset);
-
- void detect_and_match_cluster (cv::Mat img_left, cv::Mat img_right, Rect &crop_left, Rect &crop_right,
- float &mean_offset_x, float &mean_offset_y,
- float &x_offset, float &y_offset);
+ virtual void feature_match (
+ const SmartPtr<VideoBuffer> &left_buf, const SmartPtr<VideoBuffer> &right_buf);
+private:
+ virtual void detect_and_match (cv::Mat img_left, cv::Mat img_right);
+ virtual void calc_of_match (
+ cv::Mat image0, cv::Mat image1, std::vector<cv::Point2f> &corner0,
+ std::vector<cv::Point2f> &corner1, std::vector<uchar> &status, std::vector<float> &error);
+
+ bool calc_mean_offset (
+ std::vector<cv::Point2f> &corner0, std::vector<cv::Point2f> &corner1, std::vector<uchar> &status,
+ std::vector<float> &error, float &mean_offset_x, float &mean_offset_y,
+ cv::Mat debug_img, cv::Size &img0_size, cv::Size &img1_size);
private:
XCAM_DEAD_COPY (CVFeatureMatchCluster);
diff --git a/modules/soft/soft_stitcher.cpp b/modules/soft/soft_stitcher.cpp
index 74918c2..c962a92 100644
--- a/modules/soft/soft_stitcher.cpp
+++ b/modules/soft/soft_stitcher.cpp
@@ -181,10 +181,8 @@ public:
XCamReturn stop ();
XCamReturn fisheye_dewarp_to_table ();
- XCamReturn feature_match (
- const SmartPtr<VideoBuffer> &left_buf,
- const SmartPtr<VideoBuffer> &right_buf,
- const uint32_t idx);
+ XCamReturn start_feature_match (
+ const SmartPtr<VideoBuffer> &left_buf, const SmartPtr<VideoBuffer> &right_buf, const uint32_t idx);
bool get_and_reset_feature_match_factors (uint32_t idx, Factor &left, Factor &right);
@@ -199,6 +197,8 @@ private:
const uint32_t &idx, const Factor &last_left_factor, const Factor &last_right_factor,
Factor &cur_left, Factor &cur_right);
+ void init_feature_match (uint32_t idx);
+
private:
FisheyeDewarp _fisheye [XCAM_STITCH_MAX_CAMERAS];
Overlap _overlaps [XCAM_STITCH_MAX_CAMERAS];
@@ -385,6 +385,42 @@ StitcherImpl::create_copier (Stitcher::CopyArea area)
return XCAM_RETURN_NO_ERROR;
}
+void
+StitcherImpl::init_feature_match (uint32_t idx)
+{
+#if ENABLE_FEATURE_MATCH
+ _overlaps[idx].matcher = new CVCapiFeatureMatch;
+
+ FMConfig config;
+ config.sitch_min_width = 136;
+ config.min_corners = 4;
+ config.offset_factor = 0.8f;
+ config.delta_mean_offset = 120.0f;
+ config.recur_offset_error = 8.0f;
+ config.max_adjusted_offset = 24.0f;
+ config.max_valid_offset_y = 20.0f;
+#ifndef ANDROID
+ config.max_track_error = 28.0f;
+#else
+ config.max_track_error = 3600.0f;
+#endif
+ _overlaps[idx].matcher->set_config (config);
+ _overlaps[idx].matcher->set_fm_index (idx);
+
+ const Stitcher::ImageOverlapInfo &info = _stitcher->get_overlap (idx);
+ Rect left_ovlap = info.left;
+ Rect right_ovlap = info.right;
+ left_ovlap.pos_y = left_ovlap.height / 5;
+ left_ovlap.height = left_ovlap.height / 2;
+ right_ovlap.pos_y = right_ovlap.height / 5;
+ right_ovlap.height = right_ovlap.height / 2;
+ _overlaps[idx].matcher->set_crop_rect (left_ovlap, right_ovlap);
+#else
+ XCAM_LOG_ERROR ("FeatureMatch unsupported");
+ XCAM_ASSERT (false);
+#endif
+}
+
XCamReturn
StitcherImpl::init_config (uint32_t count)
{
@@ -398,23 +434,7 @@ StitcherImpl::init_config (uint32_t count)
"stitcher:%s init fisheye failed, idx:%d.", XCAM_STR (_stitcher->get_name ()), i);
#if ENABLE_FEATURE_MATCH
- _overlaps[i].matcher = new CVCapiFeatureMatch;
-
- FMConfig config;
- config.sitch_min_width = 136;
- config.min_corners = 4;
- config.offset_factor = 0.8f;
- config.delta_mean_offset = 120.0f;
- config.recur_offset_error = 8.0f;
- config.max_adjusted_offset = 24.0f;
- config.max_valid_offset_y = 20.0f;
-#ifndef ANDROID
- config.max_track_error = 28.0f;
-#else
- config.max_track_error = 3600.0f;
-#endif
- _overlaps[i].matcher->set_config (config);
- _overlaps[i].matcher->set_fm_index (i);
+ init_feature_match (i);
#endif
_overlaps[i].blender = create_soft_blender ().dynamic_cast_ptr<SoftBlender>();
@@ -549,24 +569,37 @@ Overlap::find_blender_param_in_map (
}
XCamReturn
-StitcherImpl::feature_match (
+StitcherImpl::start_single_blender (
+ const uint32_t idx,
+ const SmartPtr<BlenderParam> &param)
+{
+ SmartPtr<SoftBlender> blender = _overlaps[idx].blender;
+ const Stitcher::ImageOverlapInfo &overlap_info = _stitcher->get_overlap (idx);
+ uint32_t out_width, out_height;
+ _stitcher->get_output_size (out_width, out_height);
+
+ blender->set_output_size (out_width, out_height);
+ blender->set_merge_window (overlap_info.out_area);
+ blender->set_input_valid_area (overlap_info.left, 0);
+ blender->set_input_valid_area (overlap_info.right, 1);
+ blender->set_input_merge_area (overlap_info.left, 0);
+ blender->set_input_merge_area (overlap_info.right, 1);
+ return blender->execute_buffer (param, false);
+}
+
+XCamReturn
+StitcherImpl::start_feature_match (
const SmartPtr<VideoBuffer> &left_buf,
const SmartPtr<VideoBuffer> &right_buf,
const uint32_t idx)
{
- const Stitcher::ImageOverlapInfo overlap_info = _stitcher->get_overlap (idx);
- Rect left_ovlap = overlap_info.left;
- Rect right_ovlap = overlap_info.right;
- const VideoBufferInfo left_buf_info = left_buf->get_video_info ();
+#if ENABLE_FEATURE_MATCH
+ _overlaps[idx].matcher->reset_offsets ();
+ _overlaps[idx].matcher->feature_match (left_buf, right_buf);
- left_ovlap.pos_y = left_ovlap.height / 5;
- left_ovlap.height = left_ovlap.height / 2;
- right_ovlap.pos_y = right_ovlap.height / 5;
- right_ovlap.height = right_ovlap.height / 2;
+ Rect left_ovlap, right_ovlap;
+ _overlaps[idx].matcher->get_crop_rect (left_ovlap, right_ovlap);
- _overlaps[idx].matcher->reset_offsets ();
- _overlaps[idx].matcher->optical_flow_feature_match (
- left_buf, right_buf, left_ovlap, right_ovlap, left_buf_info.width);
float left_offsetx = _overlaps[idx].matcher->get_current_left_offset_x ();
Factor left_factor, right_factor;
@@ -595,25 +628,10 @@ StitcherImpl::feature_match (
}
return XCAM_RETURN_NO_ERROR;
-}
-
-XCamReturn
-StitcherImpl::start_single_blender (
- const uint32_t idx,
- const SmartPtr<BlenderParam> &param)
-{
- SmartPtr<SoftBlender> blender = _overlaps[idx].blender;
- const Stitcher::ImageOverlapInfo &overlap_info = _stitcher->get_overlap (idx);
- uint32_t out_width, out_height;
- _stitcher->get_output_size (out_width, out_height);
-
- blender->set_output_size (out_width, out_height);
- blender->set_merge_window (overlap_info.out_area);
- blender->set_input_valid_area (overlap_info.left, 0);
- blender->set_input_valid_area (overlap_info.right, 1);
- blender->set_input_merge_area (overlap_info.left, 0);
- blender->set_input_merge_area (overlap_info.right, 1);
- return blender->execute_buffer (param, false);
+#else
+ XCAM_LOG_ERROR ("FeatureMatch unsupported");
+ return XCAM_RETURN_ERROR_PARAM;
+#endif
}
XCamReturn
@@ -663,14 +681,14 @@ StitcherImpl::start_overlap_tasks (
#if ENABLE_FEATURE_MATCH
//start feature match
if (cur_param.ptr ()) {
- ret = feature_match (cur_param->in_buf, cur_param->in1_buf, idx);
+ ret = start_feature_match (cur_param->in_buf, cur_param->in1_buf, idx);
XCAM_FAIL_RETURN (
ERROR, xcam_ret_is_ok (ret), ret,
"soft-stitcher:%s feature-match overlap idx:%d failed", XCAM_STR (_stitcher->get_name ()), idx);
}
if (prev_param.ptr ()) {
- ret = feature_match (prev_param->in_buf, prev_param->in1_buf, pre_idx);
+ ret = start_feature_match (prev_param->in_buf, prev_param->in1_buf, pre_idx);
XCAM_FAIL_RETURN (
ERROR, xcam_ret_is_ok (ret), ret,
"soft-stitcher:%s feature-match overlap idx:%d failed", XCAM_STR (_stitcher->get_name ()), pre_idx);
diff --git a/xcore/interface/feature_match.cpp b/xcore/interface/feature_match.cpp
index 78b4fd3..1ed625f 100644
--- a/xcore/interface/feature_match.cpp
+++ b/xcore/interface/feature_match.cpp
@@ -37,21 +37,29 @@ FeatureMatch::FeatureMatch ()
}
void
-FeatureMatch::set_config (FMConfig &config)
+FeatureMatch::set_fm_index (int idx)
+{
+ _fm_idx = idx;
+}
+
+void
+FeatureMatch::set_config (const FMConfig &config)
{
_config = config;
}
-FMConfig
-FeatureMatch::get_config ()
+void
+FeatureMatch::set_crop_rect (const Rect &left_rect, const Rect &right_rect)
{
- return _config;
+ _left_rect = left_rect;
+ _right_rect = right_rect;
}
void
-FeatureMatch::set_fm_index (int idx)
+FeatureMatch::get_crop_rect (Rect &left_rect, Rect &right_rect)
{
- _fm_idx = idx;
+ left_rect = _left_rect;
+ right_rect = _right_rect;
}
void
@@ -63,8 +71,37 @@ FeatureMatch::reset_offsets ()
_mean_offset_y = 0.0f;
}
+float
+FeatureMatch::get_current_left_offset_x ()
+{
+ return _x_offset;
+}
+
+float
+FeatureMatch::get_current_left_offset_y ()
+{
+ return _y_offset;
+}
+
+void
+FeatureMatch::set_dst_width (int width)
+{
+ XCAM_UNUSED (width);
+
+ XCAM_LOG_ERROR ("dst width is not supported");
+ XCAM_ASSERT (false);
+}
+
+void
+FeatureMatch::enable_adjust_crop_area ()
+{
+ XCAM_LOG_ERROR ("adjust crop area is not supported");
+ XCAM_ASSERT (false);
+}
+
bool
-FeatureMatch::get_mean_offset (std::vector<float> &offsets, float sum, int &count, float &mean_offset)
+FeatureMatch::get_mean_offset (
+ const std::vector<float> &offsets, float sum, int &count, float &mean_offset)
{
if (count < _config.min_corners || count <= 0)
return false;
diff --git a/xcore/interface/feature_match.h b/xcore/interface/feature_match.h
index 51465b2..9d23ae3 100644
--- a/xcore/interface/feature_match.h
+++ b/xcore/interface/feature_match.h
@@ -56,27 +56,24 @@ public:
explicit FeatureMatch ();
virtual ~FeatureMatch () {};
- void set_config (FMConfig &config);
- FMConfig get_config ();
+ virtual void feature_match (
+ const SmartPtr<VideoBuffer> &left_buf, const SmartPtr<VideoBuffer> &right_buf) = 0;
void set_fm_index (int idx);
+ void set_config (const FMConfig &config);
- void reset_offsets ();
-
- virtual void optical_flow_feature_match (
- const SmartPtr<VideoBuffer> &left_buf, const SmartPtr<VideoBuffer> &right_buf,
- Rect &left_crop_rect, Rect &right_crop_rect, int dst_width = 0) = 0;
+ void set_crop_rect (const Rect &left_rect, const Rect &right_rect);
+ void get_crop_rect (Rect &left_rect, Rect &right_rect);
- float get_current_left_offset_x () const {
- return _x_offset;
- }
+ void reset_offsets ();
+ float get_current_left_offset_x ();
+ float get_current_left_offset_y ();
- float get_current_left_offset_y () const {
- return _y_offset;
- }
+ virtual void set_dst_width (int width);
+ virtual void enable_adjust_crop_area ();
protected:
- bool get_mean_offset (std::vector<float> &offsets, float sum, int &count, float &mean_offset);
+ bool get_mean_offset (const std::vector<float> &offsets, float sum, int &count, float &mean_offset);
private:
XCAM_DEAD_COPY (FeatureMatch);
@@ -89,9 +86,12 @@ protected:
int _valid_count;
FMConfig _config;
+ Rect _left_rect;
+ Rect _right_rect;
+
// debug parameters
int _fm_idx;
- uint _frame_num;
+ uint32_t _frame_num;
};
}
diff --git a/xcore/interface/stitcher.h b/xcore/interface/stitcher.h
index b05a326..081cdaf 100644
--- a/xcore/interface/stitcher.h
+++ b/xcore/interface/stitcher.h
@@ -157,7 +157,6 @@ public:
_output_width = width; //XCAM_ALIGN_UP (width, XCAM_BLENDER_ALIGNED_WIDTH);
_output_height = height;
}
-
void get_output_size (uint32_t &width, uint32_t &height) const {
width = _output_width;
height = _output_height;