Skip to content

[GSoC 2017] Obstruction Free #1233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: 4.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/xphoto/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
set(the_description "Addon to basic photo module")
ocv_define_module(xphoto opencv_core opencv_imgproc WRAP python)
ocv_define_module(xphoto opencv_core opencv_imgproc opencv_highgui WRAP python)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need higui here? We are trying to reduce dependencies for each module.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for pointing it out. You are right. highgui was used originally for showing the processed images. I will remove this dependency to the sample file.

1 change: 1 addition & 0 deletions modules/xphoto/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ Additional photo processing algorithms
1. Color balance
2. Denoising
3. Inpainting
4. Obstruction-free photography (occlusion and reflection)

9 changes: 9 additions & 0 deletions modules/xphoto/doc/xphoto.bib
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,12 @@ @inproceedings{Cheng2015
pages={1000--1008},
year={2015}
}

@article{Xue2015ObstructionFree,
author = {Tianfan Xue and Michael Rubinstein and Ce Liu and William T. Freeman},
title = {A Computational Approach for Obstruction-Free Photography},
journal = {ACM Transactions on Graphics (Proc. SIGGRAPH)},
year = {2015},
volume = {34},
number = {4},
}
1 change: 1 addition & 0 deletions modules/xphoto/include/opencv2/xphoto.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@
#include "xphoto/white_balance.hpp"
#include "xphoto/dct_image_denoising.hpp"
#include "xphoto/bm3d_image_denoising.hpp"
#include "xphoto/obstruction_free.hpp"
#endif
77 changes: 77 additions & 0 deletions modules/xphoto/include/opencv2/xphoto/obstruction_free.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This long header should be replaced with a short one:

// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for pointing it out. I will modify the header part.

//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/

#ifndef __OPENCV_OBSTRUCTION_FREE_HPP__
#define __OPENCV_OBSTRUCTION_FREE_HPP__

/** @file
@date June 18, 2017
@author Binbin Xu
*/

#include <opencv2/core.hpp>

namespace cv
{
namespace xphoto
{

//! @addtogroup xphoto
//! @{


/** @brief The function implements a general obstruction free approach that can remove occlusions and reflections from input image sequences without manual masks.

See the original paper @cite Xue2015ObstructionFree for more details.

@param srcImgs source image sequences, involving translation motions.
@param dst Obstruction-removed destination image, corresponding to the reference image, with the same size and type. In general, the reference image is the center frame of the input image.
@param mask mask (CV_8UC1), where zero pixels indicate area to be estimated to be occlusions.
*/
CV_EXPORTS void obstructionFree(const std::vector <Mat> &srcImgs, Mat &dst, Mat &mask);

//! @}

}
}

#endif // __OPENCV_INPAINTING_HPP__
80 changes: 80 additions & 0 deletions modules/xphoto/src/obstruction_free.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same about the outdated long license header.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for pointing it out. I will modify the header part accordingly.

//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of Intel Corporation may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/

#ifndef __OPENCV_OBSTRUCTION_FREE_CPP__
#define __OPENCV_OBSTRUCTION_FREE_CPP__
#ifdef __cplusplus
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__cplusplus check is not useful anymore, so it's better to get rid of that.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for pointing it out. I will remove this line.


#include <vector>
#include <iostream>

#include <opencv2/xphoto.hpp>

#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>

namespace cv
{
namespace xphoto
{
void obstructionFree(const std::vector <Mat> &srcImgs, Mat &dst, Mat &mask){
size_t frameNumber = srcImgs.size();
size_t reference_number = (frameNumber-1)/2;;
dst.create( srcImgs[reference_number].size(), srcImgs[reference_number].type() );
mask = Mat::zeros(dst.rows,dst.cols,CV_8UC1);


/////////construct image pyramids//////
int pyramid_level=3;
std::vector<Mat> video_coarseLeve;
for (size_t frame_i=0; frame_i<frameNumber; frame_i++){
Mat temp, temp_gray;
temp=srcImgs[frame_i].clone();
cvtColor(temp, temp_gray, COLOR_RGB2GRAY);
for (int i=0; i<pyramid_level; i++){
pyrDown( temp_gray, temp_gray );
}
video_coarseLeve.push_back(temp_gray.clone());
}
}
}
}
#endif // __OPENCV_PCALIB_CPP__
#endif // cplusplus