switched float with short in blending step (opencv_stitching)
This commit is contained in:
parent
5bf8109dbc
commit
f44632ee6f
@ -411,6 +411,8 @@ void cv::pyrDown( const InputArray& _src, OutputArray _dst, const Size& _dsz )
|
||||
PyrFunc func = 0;
|
||||
if( depth == CV_8U )
|
||||
func = pyrDown_<FixPtCast<uchar, 8>, PyrDownVec_32s8u>;
|
||||
else if( depth == CV_16S )
|
||||
func = pyrDown_<FixPtCast<short, 8>, NoVec<int, short> >;
|
||||
else if( depth == CV_16U )
|
||||
func = pyrDown_<FixPtCast<ushort, 8>, NoVec<int, ushort> >;
|
||||
else if( depth == CV_32F )
|
||||
@ -433,6 +435,8 @@ void cv::pyrUp( const InputArray& _src, OutputArray _dst, const Size& _dsz )
|
||||
PyrFunc func = 0;
|
||||
if( depth == CV_8U )
|
||||
func = pyrUp_<FixPtCast<uchar, 6>, NoVec<int, uchar> >;
|
||||
else if( depth == CV_16S )
|
||||
func = pyrUp_<FixPtCast<short, 6>, NoVec<int, short> >;
|
||||
else if( depth == CV_16U )
|
||||
func = pyrUp_<FixPtCast<ushort, 6>, NoVec<int, ushort> >;
|
||||
else if( depth == CV_32F )
|
||||
|
@ -96,7 +96,7 @@ double estimateFocal(const vector<ImageFeatures> &features, const vector<Matches
|
||||
}
|
||||
}
|
||||
|
||||
if (static_cast<int>(focals.size()) >= 2 * (num_images - 1))
|
||||
if (static_cast<int>(focals.size()) >= num_images * (num_images - 1) / 2)
|
||||
{
|
||||
nth_element(focals.begin(), focals.end(), focals.begin() + focals.size()/2);
|
||||
return focals[focals.size()/2];
|
||||
|
@ -68,7 +68,7 @@ void Blender::prepare(const vector<Point> &corners, const vector<Size> &sizes)
|
||||
|
||||
void Blender::prepare(Rect dst_roi)
|
||||
{
|
||||
dst_.create(dst_roi.size(), CV_32FC3);
|
||||
dst_.create(dst_roi.size(), CV_16SC3);
|
||||
dst_.setTo(Scalar::all(0));
|
||||
dst_mask_.create(dst_roi.size(), CV_8U);
|
||||
dst_mask_.setTo(Scalar::all(0));
|
||||
@ -78,7 +78,7 @@ void Blender::prepare(Rect dst_roi)
|
||||
|
||||
void Blender::feed(const Mat &img, const Mat &mask, Point tl)
|
||||
{
|
||||
CV_Assert(img.type() == CV_32FC3);
|
||||
CV_Assert(img.type() == CV_16SC3);
|
||||
CV_Assert(mask.type() == CV_8U);
|
||||
|
||||
int dx = tl.x - dst_roi_.x;
|
||||
@ -86,8 +86,8 @@ void Blender::feed(const Mat &img, const Mat &mask, Point tl)
|
||||
|
||||
for (int y = 0; y < img.rows; ++y)
|
||||
{
|
||||
const Point3f *src_row = img.ptr<Point3f>(y);
|
||||
Point3f *dst_row = dst_.ptr<Point3f>(dy + y);
|
||||
const Point3_<short> *src_row = img.ptr<Point3_<short> >(y);
|
||||
Point3_<short> *dst_row = dst_.ptr<Point3_<short> >(dy + y);
|
||||
|
||||
const uchar *mask_row = mask.ptr<uchar>(y);
|
||||
uchar *dst_mask_row = dst_mask_.ptr<uchar>(dy + y);
|
||||
@ -122,7 +122,7 @@ void FeatherBlender::prepare(Rect dst_roi)
|
||||
|
||||
void FeatherBlender::feed(const Mat &img, const Mat &mask, Point tl)
|
||||
{
|
||||
CV_Assert(img.type() == CV_32FC3);
|
||||
CV_Assert(img.type() == CV_16SC3);
|
||||
CV_Assert(mask.type() == CV_8U);
|
||||
|
||||
int dx = tl.x - dst_roi_.x;
|
||||
@ -132,15 +132,17 @@ void FeatherBlender::feed(const Mat &img, const Mat &mask, Point tl)
|
||||
|
||||
for (int y = 0; y < img.rows; ++y)
|
||||
{
|
||||
const Point3f* src_row = img.ptr<Point3f>(y);
|
||||
Point3f* dst_row = dst_.ptr<Point3f>(dy + y);
|
||||
const Point3_<short>* src_row = img.ptr<Point3_<short> >(y);
|
||||
Point3_<short>* dst_row = dst_.ptr<Point3_<short> >(dy + y);
|
||||
|
||||
const float* weight_row = weight_map_.ptr<float>(y);
|
||||
float* dst_weight_row = dst_weight_map_.ptr<float>(dy + y);
|
||||
|
||||
for (int x = 0; x < img.cols; ++x)
|
||||
{
|
||||
dst_row[dx + x] += src_row[x] * weight_row[x];
|
||||
dst_row[dx + x].x += static_cast<short>(src_row[x].x * weight_row[x]);
|
||||
dst_row[dx + x].y += static_cast<short>(src_row[x].y * weight_row[x]);
|
||||
dst_row[dx + x].z += static_cast<short>(src_row[x].z * weight_row[x]);
|
||||
dst_weight_row[dx + x] += weight_row[x];
|
||||
}
|
||||
}
|
||||
@ -169,7 +171,7 @@ void MultiBandBlender::prepare(Rect dst_roi)
|
||||
for (int i = 1; i <= num_bands_; ++i)
|
||||
{
|
||||
dst_pyr_laplace_[i].create((dst_pyr_laplace_[i - 1].rows + 1) / 2,
|
||||
(dst_pyr_laplace_[i - 1].cols + 1) / 2, CV_32FC3);
|
||||
(dst_pyr_laplace_[i - 1].cols + 1) / 2, CV_16SC3);
|
||||
dst_band_weights_[i].create((dst_band_weights_[i - 1].rows + 1) / 2,
|
||||
(dst_band_weights_[i - 1].cols + 1) / 2, CV_32F);
|
||||
dst_pyr_laplace_[i].setTo(Scalar::all(0));
|
||||
@ -180,7 +182,7 @@ void MultiBandBlender::prepare(Rect dst_roi)
|
||||
|
||||
void MultiBandBlender::feed(const Mat &img, const Mat &mask, Point tl)
|
||||
{
|
||||
CV_Assert(img.type() == CV_32FC3);
|
||||
CV_Assert(img.type() == CV_16SC3);
|
||||
CV_Assert(mask.type() == CV_8U);
|
||||
|
||||
int top = tl.y - dst_roi_.y;
|
||||
@ -212,13 +214,17 @@ void MultiBandBlender::feed(const Mat &img, const Mat &mask, Point tl)
|
||||
{
|
||||
for (int y = 0; y < dst_pyr_laplace_[i].rows; ++y)
|
||||
{
|
||||
const Point3f* src_row = src_pyr_laplace[i].ptr<Point3f>(y);
|
||||
Point3f* dst_row = dst_pyr_laplace_[i].ptr<Point3f>(y);
|
||||
const Point3_<short>* src_row = src_pyr_laplace[i].ptr<Point3_<short> >(y);
|
||||
Point3_<short>* dst_row = dst_pyr_laplace_[i].ptr<Point3_<short> >(y);
|
||||
|
||||
const float* weight_row = weight_pyr_gauss[i].ptr<float>(y);
|
||||
|
||||
for (int x = 0; x < dst_pyr_laplace_[i].cols; ++x)
|
||||
dst_row[x] += src_row[x] * weight_row[x];
|
||||
{
|
||||
dst_row[x].x += static_cast<short>(src_row[x].x * weight_row[x]);
|
||||
dst_row[x].y += static_cast<short>(src_row[x].y * weight_row[x]);
|
||||
dst_row[x].z += static_cast<short>(src_row[x].z * weight_row[x]);
|
||||
}
|
||||
}
|
||||
dst_band_weights_[i] += weight_pyr_gauss[i];
|
||||
}
|
||||
@ -265,14 +271,18 @@ Rect resultRoi(const vector<Point> &corners, const vector<Size> &sizes)
|
||||
void normalize(const Mat& weight, Mat& src)
|
||||
{
|
||||
CV_Assert(weight.type() == CV_32F);
|
||||
CV_Assert(src.type() == CV_32FC3);
|
||||
CV_Assert(src.type() == CV_16SC3);
|
||||
for (int y = 0; y < src.rows; ++y)
|
||||
{
|
||||
Point3f *row = src.ptr<Point3f>(y);
|
||||
Point3_<short> *row = src.ptr<Point3_<short> >(y);
|
||||
const float *weight_row = weight.ptr<float>(y);
|
||||
|
||||
for (int x = 0; x < src.cols; ++x)
|
||||
row[x] *= 1.f / (weight_row[x] + WEIGHT_EPS);
|
||||
{
|
||||
row[x].x = static_cast<short>(row[x].x / (weight_row[x] + WEIGHT_EPS));
|
||||
row[x].y = static_cast<short>(row[x].y / (weight_row[x] + WEIGHT_EPS));
|
||||
row[x].z = static_cast<short>(row[x].z / (weight_row[x] + WEIGHT_EPS));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -296,7 +306,7 @@ void createLaplacePyr(const vector<Mat> &pyr_gauss, vector<Mat> &pyr_laplace)
|
||||
for (size_t i = 0; i < pyr_laplace.size() - 1; ++i)
|
||||
{
|
||||
pyrUp(pyr_gauss[i + 1], tmp, pyr_gauss[i].size());
|
||||
pyr_laplace[i] = pyr_gauss[i] - tmp;
|
||||
subtract(pyr_gauss[i], tmp, pyr_laplace[i]);
|
||||
}
|
||||
pyr_laplace[pyr_laplace.size() - 1] = pyr_gauss[pyr_laplace.size() - 1].clone();
|
||||
}
|
||||
@ -311,6 +321,7 @@ void restoreImageFromLaplacePyr(vector<Mat> &pyr)
|
||||
for (size_t i = pyr.size() - 1; i > 0; --i)
|
||||
{
|
||||
pyrUp(pyr[i], tmp, pyr[i - 1].size());
|
||||
pyr[i - 1] += tmp;
|
||||
add(tmp, pyr[i - 1], pyr[i - 1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -401,7 +401,6 @@ int main(int argc, char* argv[])
|
||||
cameras[i].R, masks_warped[i], INTER_NEAREST, BORDER_CONSTANT);
|
||||
}
|
||||
|
||||
// Convert to float for blending
|
||||
vector<Mat> images_warped_f(num_images);
|
||||
for (int i = 0; i < num_images; ++i)
|
||||
images_warped[i].convertTo(images_warped_f[i], CV_32F);
|
||||
@ -426,7 +425,7 @@ int main(int argc, char* argv[])
|
||||
LOGLN("Compositing...");
|
||||
t = getTickCount();
|
||||
|
||||
Mat img_warped, img_warped_f;
|
||||
Mat img_warped, img_warped_s;
|
||||
Mat dilated_mask, seam_mask, mask, mask_warped;
|
||||
Ptr<Blender> blender;
|
||||
double compose_seam_aspect = 1;
|
||||
@ -461,7 +460,7 @@ int main(int argc, char* argv[])
|
||||
// Warp the current image
|
||||
warper->warp(img, static_cast<float>(cameras[img_idx].focal), cameras[img_idx].R,
|
||||
img_warped);
|
||||
img_warped.convertTo(img_warped_f, CV_32F);
|
||||
img_warped.convertTo(img_warped_s, CV_16S);
|
||||
img_warped.release();
|
||||
img.release();
|
||||
|
||||
@ -497,7 +496,7 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
|
||||
// Blend the current image
|
||||
blender->feed(img_warped_f, mask_warped, corners[img_idx]);
|
||||
blender->feed(img_warped_s, mask_warped, corners[img_idx]);
|
||||
}
|
||||
|
||||
Mat result, result_mask;
|
||||
|
Loading…
Reference in New Issue
Block a user