Commit 2c6f707b authored by Bellaktris's avatar Bellaktris

fixed some errors

parent f86e3156
...@@ -43,9 +43,15 @@ ...@@ -43,9 +43,15 @@
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
#include <cstdlib>
#include <limits> #include <limits>
template <typename Tp> static inline int min_idx(std::vector <Tp> vec)
namespace xphotoInternal
{
template <typename Tp> static int min_idx(std::vector <Tp> vec)
{ {
return int( std::min_element(vec.begin(), vec.end()) - vec.begin() ); return int( std::min_element(vec.begin(), vec.end()) - vec.begin() );
} }
...@@ -61,4 +67,6 @@ static inline int hamming_length(int x) ...@@ -61,4 +67,6 @@ static inline int hamming_length(int x)
return res; return res;
} }
}
#endif /* __ALGO_HPP__ */ #endif /* __ALGO_HPP__ */
...@@ -40,9 +40,12 @@ ...@@ -40,9 +40,12 @@
#ifndef __ANNF_HPP__ #ifndef __ANNF_HPP__
#define __ANNF_HPP__ #define __ANNF_HPP__
#include <vector>
#include "algo.hpp" #include "algo.hpp"
namespace xphotoInternal
{
static void plusToMinusUpdate(const cv::Mat &current, cv::Mat &next, const int dx, const int dy) static void plusToMinusUpdate(const cv::Mat &current, cv::Mat &next, const int dx, const int dy)
{ {
for (int i = 0; i < next.rows; ++i) for (int i = 0; i < next.rows; ++i)
...@@ -123,4 +126,6 @@ static void getWHSeries(const cv::Mat &src, cv::Mat &dst, const int nProjections ...@@ -123,4 +126,6 @@ static void getWHSeries(const cv::Mat &src, cv::Mat &dst, const int nProjections
cv::merge(projections, dst); cv::merge(projections, dst);
} }
}
#endif /* __ANNF_HPP__ */ #endif /* __ANNF_HPP__ */
...@@ -78,8 +78,8 @@ private: ...@@ -78,8 +78,8 @@ private:
TWeight weight; TWeight weight;
}; };
std::vector<Vtx> vtcs; ::std::vector<Vtx> vtcs;
std::vector<Edge> edges; ::std::vector<Edge> edges;
TWeight flow; TWeight flow;
}; };
...@@ -163,7 +163,7 @@ TWeight GCGraph<TWeight>::maxFlow() ...@@ -163,7 +163,7 @@ TWeight GCGraph<TWeight>::maxFlow()
Vtx *vtxPtr = &vtcs[0]; Vtx *vtxPtr = &vtcs[0];
Edge *edgePtr = &edges[0]; Edge *edgePtr = &edges[0];
std::vector<Vtx*> orphans; ::std::vector<Vtx*> orphans;
// initialize the active queue and the graph vertices // initialize the active queue and the graph vertices
for( int i = 0; i < (int)vtcs.size(); i++ ) for( int i = 0; i < (int)vtcs.size(); i++ )
......
...@@ -52,11 +52,10 @@ ...@@ -52,11 +52,10 @@
#include "opencv2/core/types.hpp" #include "opencv2/core/types.hpp"
#include "opencv2/core/types_c.h" #include "opencv2/core/types_c.h"
namespace xphotoInternal
{ #include "photomontage.hpp"
# include "photomontage.hpp" #include "annf.hpp"
# include "annf.hpp"
}
namespace cv namespace cv
{ {
...@@ -64,10 +63,10 @@ namespace cv ...@@ -64,10 +63,10 @@ namespace cv
static void shiftMapInpaint(const Mat &src, const Mat &mask, Mat &dst) static void shiftMapInpaint(const Mat &src, const Mat &mask, Mat &dst)
{ {
const int nTransform = 60; // number of dominant transforms for stitching const int nTransform = 60; // number of dominant transforms for stitching
//const int psize = 8; // single ANNF patch size const int psize = 8; // single ANNF patch size
/** ANNF computation **/ /** ANNF computation **/
srand( unsigned int(time(NULL)) ); srand( unsigned(time(NULL)) );
std::vector <Matx33f> transforms; // dominant transforms std::vector <Matx33f> transforms; // dominant transforms
for (int i = 0; i < nTransform; ++i) for (int i = 0; i < nTransform; ++i)
......
...@@ -50,6 +50,10 @@ ...@@ -50,6 +50,10 @@
#define GCInfinity 10*1000*1000*1000.0 #define GCInfinity 10*1000*1000*1000.0
namespace xphotoInternal
{
template <typename Tp> class Photomontage template <typename Tp> class Photomontage
{ {
private: private:
...@@ -109,10 +113,10 @@ setWeights(GCGraph <double> &graph, const cv::Point &pA, const cv::Point &pB, co ...@@ -109,10 +113,10 @@ setWeights(GCGraph <double> &graph, const cv::Point &pA, const cv::Point &pB, co
if (lA == lB) if (lA == lB)
{ {
/** Link from A to B **/ /** Link from A to B **/
double weightAB = dist( images[lA].at<typename Tp>(pA), double weightAB = dist( images[lA].at<Tp>(pA),
images[lA].at<typename Tp>(pB), images[lA].at<Tp>(pB),
images[lX].at<typename Tp>(pA), images[lX].at<Tp>(pA),
images[lX].at<typename Tp>(pB) ); images[lX].at<Tp>(pB) );
graph.addEdges( int(pA.y*width + pA.x), int(pB.y*width + pB.x), weightAB, weightAB); graph.addEdges( int(pA.y*width + pA.x), int(pB.y*width + pB.x), weightAB, weightAB);
} }
else else
...@@ -120,24 +124,24 @@ setWeights(GCGraph <double> &graph, const cv::Point &pA, const cv::Point &pB, co ...@@ -120,24 +124,24 @@ setWeights(GCGraph <double> &graph, const cv::Point &pA, const cv::Point &pB, co
int X = graph.addVtx(); int X = graph.addVtx();
/** Link from X to sink **/ /** Link from X to sink **/
double weightXS = dist( images[lA].at<typename Tp>(pA), double weightXS = dist( images[lA].at<Tp>(pA),
images[lA].at<typename Tp>(pB), images[lA].at<Tp>(pB),
images[lB].at<typename Tp>(pA), images[lB].at<Tp>(pA),
images[lB].at<typename Tp>(pB) ); images[lB].at<Tp>(pB) );
graph.addTermWeights(X, 0, weightXS); graph.addTermWeights(X, 0, weightXS);
/** Link from A to X **/ /** Link from A to X **/
double weightAX = dist( images[lA].at<typename Tp>(pA), double weightAX = dist( images[lA].at<Tp>(pA),
images[lA].at<typename Tp>(pB), images[lA].at<Tp>(pB),
images[lX].at<typename Tp>(pA), images[lX].at<Tp>(pA),
images[lX].at<typename Tp>(pB) ); images[lX].at<Tp>(pB) );
graph.addEdges( int(pA.y*width + pA.x), X, weightAX, weightAX); graph.addEdges( int(pA.y*width + pA.x), X, weightAX, weightAX);
/** Link from X to B **/ /** Link from X to B **/
double weightXB = dist( images[lX].at<typename Tp>(pA), double weightXB = dist( images[lX].at<Tp>(pA),
images[lX].at<typename Tp>(pB), images[lX].at<Tp>(pB),
images[lB].at<typename Tp>(pA), images[lB].at<Tp>(pA),
images[lB].at<typename Tp>(pB) ); images[lB].at<Tp>(pB) );
graph.addEdges(X, int(pB.y*width + pB.x), weightXB, weightXB); graph.addEdges(X, int(pB.y*width + pB.x), weightXB, weightXB);
} }
} }
...@@ -151,8 +155,8 @@ singleExpansion(const int alpha) ...@@ -151,8 +155,8 @@ singleExpansion(const int alpha)
/** Terminal links **/ /** Terminal links **/
for (int i = 0; i < height; ++i) for (int i = 0; i < height; ++i)
{ {
typename const uchar *maskAlphaRow = masks[alpha].ptr <uchar>(i); const uchar *maskAlphaRow = masks[alpha].ptr <uchar>(i);
typename const int *labelRow = (const int *) x_i.ptr <int>(i); const int *labelRow = (const int *) x_i.ptr <int>(i);
for (int j = 0; j < width; ++j) for (int j = 0; j < width; ++j)
graph.addTermWeights( graph.addVtx(), graph.addTermWeights( graph.addVtx(),
...@@ -163,8 +167,8 @@ singleExpansion(const int alpha) ...@@ -163,8 +167,8 @@ singleExpansion(const int alpha)
/** Neighbor links **/ /** Neighbor links **/
for (int i = 0; i < height - 1; ++i) for (int i = 0; i < height - 1; ++i)
{ {
typename const int *currentRow = (const int *) x_i.ptr <int>(i); const int *currentRow = (const int *) x_i.ptr <int>(i);
typename const int *nextRow = (const int *) x_i.ptr <int>(i + 1); const int *nextRow = (const int *) x_i.ptr <int>(i + 1);
for (int j = 0; j < width - 1; ++j) for (int j = 0; j < width - 1; ++j)
{ {
...@@ -188,8 +192,8 @@ singleExpansion(const int alpha) ...@@ -188,8 +192,8 @@ singleExpansion(const int alpha)
labelings[alpha].create( height, width, CV_32SC1 ); labelings[alpha].create( height, width, CV_32SC1 );
for (int i = 0; i < height; ++i) for (int i = 0; i < height; ++i)
{ {
typename const int *inRow = (const int *) x_i.ptr <int>(i); const int *inRow = (const int *) x_i.ptr <int>(i);
typename int *outRow = (int *) labelings[alpha].ptr <int>(i); int *outRow = (int *) labelings[alpha].ptr <int>(i);
for (int j = 0; j < width; ++j) for (int j = 0; j < width; ++j)
outRow[j] = graph.inSourceSegment(i*width + j) ? inRow[j] : alpha; outRow[j] = graph.inSourceSegment(i*width + j) ? inRow[j] : alpha;
...@@ -244,11 +248,12 @@ assignResImage(cv::Mat &img) ...@@ -244,11 +248,12 @@ assignResImage(cv::Mat &img)
template <typename Tp> Photomontage <Tp>:: template <typename Tp> Photomontage <Tp>::
Photomontage(const std::vector <cv::Mat> &_images, const std::vector <cv::Mat> &_masks) Photomontage(const std::vector <cv::Mat> &_images, const std::vector <cv::Mat> &_masks)
: :
images(_images), masks(_masks), height(int(images[0].rows)), width(int(images[0].cols)), images(_images), masks(_masks), labelings(images.size()), distances(images.size()),
type(images[0].type()), x_i(height, width, CV_32SC1), channels(images[0].channels()), height(int(images[0].rows)), width(int(images[0].cols)), type(images[0].type()),
lsize(int(images.size())), labelings(images.size()), distances(images.size()) channels(images[0].channels()), lsize(int(images.size())), x_i(height, width, CV_32SC1){
{
CV_Assert(images[0].depth() != CV_8U && masks[0].depth() == CV_8U); CV_Assert(images[0].depth() != CV_8U && masks[0].depth() == CV_8U);
} }
}
#endif /* __PHOTOMONTAGE_HPP__ */ #endif /* __PHOTOMONTAGE_HPP__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment