From 0fd91f6d1403d6ad760f877dba80b9649543ee2f Mon Sep 17 00:00:00 2001 From: Rajkiran Natarajan Date: Thu, 25 Jul 2019 04:13:33 +0000 Subject: [PATCH 1/3] Correct the behaviour of inpainting mask usage --- modules/xphoto/src/inpainting.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/xphoto/src/inpainting.cpp b/modules/xphoto/src/inpainting.cpp index 6796254f071..ce4bc0654e5 100644 --- a/modules/xphoto/src/inpainting.cpp +++ b/modules/xphoto/src/inpainting.cpp @@ -83,7 +83,7 @@ namespace xphoto cv::resize(_src, src, _src.size()/ls, 0, 0, cv::INTER_AREA); src.convertTo( img, CV_32F ); - img.setTo(0, 255 - mask); + img.setTo(0, ~(mask > 0)); cv::erode( mask, dmask, cv::Mat(), cv::Point(-1,-1), 2); cv::erode(dmask, ddmask, cv::Mat(), cv::Point(-1,-1), 2); From 7f5546823524dd42910bde3c38d8a4fcbe9edb2e Mon Sep 17 00:00:00 2001 From: SSE4 Date: Fri, 26 Jul 2019 11:32:47 +0200 Subject: [PATCH 2/3] - fix find_package for glog & gflags Signed-off-by: SSE4 --- modules/sfm/cmake/FindGflags.cmake | 2 +- modules/sfm/cmake/FindGlog.cmake | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/sfm/cmake/FindGflags.cmake b/modules/sfm/cmake/FindGflags.cmake index d3b45dae572..2b15fc3627e 100644 --- a/modules/sfm/cmake/FindGflags.cmake +++ b/modules/sfm/cmake/FindGflags.cmake @@ -482,7 +482,7 @@ if (NOT GFLAGS_FOUND) endif (NOT GFLAGS_INCLUDE_DIR OR NOT EXISTS ${GFLAGS_INCLUDE_DIR}) - find_library(GFLAGS_LIBRARY NAMES gflags + find_library(GFLAGS_LIBRARY NAMES gflags gflags_debug gflags_nothreads gflags_nothreads_debug PATHS ${GFLAGS_LIBRARY_DIR_HINTS} ${GFLAGS_CHECK_LIBRARY_DIRS} PATH_SUFFIXES ${GFLAGS_CHECK_LIBRARY_SUFFIXES}) diff --git a/modules/sfm/cmake/FindGlog.cmake b/modules/sfm/cmake/FindGlog.cmake index 3057b312d23..ad447c27ce3 100644 --- a/modules/sfm/cmake/FindGlog.cmake +++ b/modules/sfm/cmake/FindGlog.cmake @@ -148,7 +148,7 @@ if (NOT GLOG_INCLUDE_DIR OR endif (NOT GLOG_INCLUDE_DIR OR NOT EXISTS ${GLOG_INCLUDE_DIR}) -find_library(GLOG_LIBRARY NAMES glog +find_library(GLOG_LIBRARY NAMES glog glogd PATHS ${GLOG_LIBRARY_DIR_HINTS} ${GLOG_CHECK_LIBRARY_DIRS} PATH_SUFFIXES ${GLOG_CHECK_LIBRARY_SUFFIXES}) From 4c2ef47680b80d977fd6eb9d5847f904451c211f Mon Sep 17 00:00:00 2001 From: Tobias Senst Date: Mon, 5 Aug 2019 17:41:38 +0200 Subject: [PATCH 3/3] Merge pull request #2209 from tsenst:update_EdgeAwareInterpolator Enhance EdgeAwareInterpolation no. matches limitation (#2209) * sparse_match_interpolators EdgeAwareInterpolation - enhance limitation of the maximal number of matches to be interpolated from SHORT_MAX to INT_MAX by substituting short by int types * sparse_match_interpolators EdgeAwareInterpolation - enhance limitation of the maximal number of matches to be interpolated from SHORT_MAX to INT_MAX by substituting short by int types * fix wrong allocation of labels mats CV16S to CV_32S --- .../src/sparse_match_interpolators.cpp | 99 +++++++++---------- 1 file changed, 49 insertions(+), 50 deletions(-) diff --git a/modules/ximgproc/src/sparse_match_interpolators.cpp b/modules/ximgproc/src/sparse_match_interpolators.cpp index d374555d576..8cb12f10a73 100644 --- a/modules/ximgproc/src/sparse_match_interpolators.cpp +++ b/modules/ximgproc/src/sparse_match_interpolators.cpp @@ -57,16 +57,16 @@ struct SparseMatch bool operator<(const SparseMatch& lhs,const SparseMatch& rhs); -void weightedLeastSquaresAffineFit(short* labels, float* weights, int count, float lambda, SparseMatch* matches, Mat& dst); -void generateHypothesis(short* labels, int count, RNG& rng, unsigned char* is_used, SparseMatch* matches, Mat& dst); -void verifyHypothesis(short* labels, float* weights, int count, SparseMatch* matches, float eps, float lambda, Mat& hypothesis_transform, Mat& old_transform, float& old_weighted_num_inliers); +void weightedLeastSquaresAffineFit(int* labels, float* weights, int count, float lambda, SparseMatch* matches, Mat& dst); +void generateHypothesis(int* labels, int count, RNG& rng, unsigned char* is_used, SparseMatch* matches, Mat& dst); +void verifyHypothesis(int* labels, float* weights, int count, SparseMatch* matches, float eps, float lambda, Mat& hypothesis_transform, Mat& old_transform, float& old_weighted_num_inliers); struct node { float dist; - short label; + int label; node() {} - node(short l,float d): dist(d), label(l) {} + node(int l,float d): dist(d), label(l) {} }; class EdgeAwareInterpolatorImpl CV_FINAL : public EdgeAwareInterpolator @@ -78,7 +78,6 @@ class EdgeAwareInterpolatorImpl CV_FINAL : public EdgeAwareInterpolator protected: int w,h; int match_num; - //internal buffers: vector* g; Mat labels; @@ -186,9 +185,9 @@ void EdgeAwareInterpolatorImpl::interpolate(InputArray from_image, InputArray fr CV_Assert(match_num& ma y = min((int)(matches[i].reference_image_pos.y+0.5f),h-1); distances.at(y,x) = 0.0f; - labels.at(y,x) = (short)i; + labels.at(y,x) = (int)i; } computeGradientMagnitude(src,cost_map); @@ -234,7 +233,7 @@ void EdgeAwareInterpolatorImpl::computeGradientMagnitude(Mat& src, Mat& dst) Mat dx,dy; Sobel(src, dx, CV_16S, 1, 0); Sobel(src, dy, CV_16S, 0, 1); - float norm_coef = src.channels()*4.0f*255.0f; + float norm_coef = src.channels()*4*255.0f; if(src.channels()==1) { @@ -272,8 +271,8 @@ void EdgeAwareInterpolatorImpl::geodesicDistanceTransform(Mat& distances, Mat& c int i,j; float *dist_row, *cost_row; float *dist_row_prev, *cost_row_prev; - short *label_row; - short *label_row_prev; + int *label_row; + int *label_row_prev; #define CHECK(cur_dist,cur_label,cur_cost,prev_dist,prev_label,prev_cost,coef)\ {\ @@ -287,7 +286,7 @@ void EdgeAwareInterpolatorImpl::geodesicDistanceTransform(Mat& distances, Mat& c { //first pass (left-to-right, top-to-bottom): dist_row = distances.ptr(0); - label_row = labels.ptr(0); + label_row = labels.ptr(0); cost_row = cost_map.ptr(0); for(j=1;j(i); dist_row_prev = distances.ptr(i-1); - label_row = labels.ptr(i); - label_row_prev = labels.ptr(i-1); + label_row = labels.ptr(i); + label_row_prev = labels.ptr(i-1); cost_row = cost_map.ptr(i); cost_row_prev = cost_map.ptr(i-1); @@ -321,7 +320,7 @@ void EdgeAwareInterpolatorImpl::geodesicDistanceTransform(Mat& distances, Mat& c //second pass (right-to-left, bottom-to-top): dist_row = distances.ptr(h-1); - label_row = labels.ptr(h-1); + label_row = labels.ptr(h-1); cost_row = cost_map.ptr(h-1); for(j=w-2;j>=0;j--) CHECK(dist_row[j],label_row[j],cost_row[j],dist_row[j+1],label_row[j+1],cost_row[j+1],c1); @@ -331,8 +330,8 @@ void EdgeAwareInterpolatorImpl::geodesicDistanceTransform(Mat& distances, Mat& c dist_row = distances.ptr(i); dist_row_prev = distances.ptr(i+1); - label_row = labels.ptr(i); - label_row_prev = labels.ptr(i+1); + label_row = labels.ptr(i); + label_row_prev = labels.ptr(i+1); cost_row = cost_map.ptr(i); cost_row_prev = cost_map.ptr(i+1); @@ -360,8 +359,8 @@ void EdgeAwareInterpolatorImpl::buildGraph(Mat& distances, Mat& cost_map) { float *dist_row, *cost_row; float *dist_row_prev, *cost_row_prev; - short *label_row; - short *label_row_prev; + int *label_row; + int *label_row_prev; int i,j; const float c1 = 1.0f/2.0f; const float c2 = sqrt(2.0f)/2.0f; @@ -387,7 +386,7 @@ void EdgeAwareInterpolatorImpl::buildGraph(Mat& distances, Mat& cost_map) } dist_row = distances.ptr(0); - label_row = labels.ptr(0); + label_row = labels.ptr(0); cost_row = cost_map.ptr(0); for(j=1;j(i); dist_row_prev = distances.ptr(i-1); - label_row = labels.ptr(i); - label_row_prev = labels.ptr(i-1); + label_row = labels.ptr(i); + label_row_prev = labels.ptr(i-1); cost_row = cost_map.ptr(i); cost_row_prev = cost_map.ptr(i-1); @@ -442,7 +441,7 @@ void EdgeAwareInterpolatorImpl::buildGraph(Mat& distances, Mat& cost_map) } if(!found) - g[neighbors[j].label].push_back(node((short)i,neighbors[j].dist)); + g[neighbors[j].label].push_back(node((int)i,neighbors[j].dist)); } } } @@ -453,18 +452,18 @@ struct nodeHeap // children: 2*i, 2*i+1 // parent: i>>1 node* heap; - short* heap_pos; + int* heap_pos; node tmp_node; - short size; - short num_labels; + int size; + int num_labels; - nodeHeap(short _num_labels) + nodeHeap(int _num_labels) { num_labels = _num_labels; heap = new node[num_labels+1]; heap[0] = node(-1,-1.0f); - heap_pos = new short[num_labels]; - memset(heap_pos,0,sizeof(short)*num_labels); + heap_pos = new int[num_labels]; + memset(heap_pos,0,sizeof(int)*num_labels); size=0; } @@ -477,7 +476,7 @@ struct nodeHeap void clear() { size=0; - memset(heap_pos,0,sizeof(short)*num_labels); + memset(heap_pos,0,sizeof(int)*num_labels); } inline bool empty() @@ -485,7 +484,7 @@ struct nodeHeap return (size==0); } - inline void nodeSwap(short idx1, short idx2) + inline void nodeSwap(int idx1, int idx2) { heap_pos[heap[idx1].label] = idx2; heap_pos[heap[idx2].label] = idx1; @@ -500,8 +499,8 @@ struct nodeHeap size++; heap[size] = n; heap_pos[n.label] = size; - short i = size; - short parent_i = i>>1; + int i = size; + int parent_i = i>>1; while(heap[i].dist>1; + int parent_i = i>>1; while(heap[i].dist>1; + int parent_i = i>>1; while(heap[i].distmatch_num); int end = std::min(range.end * stripe_sz, inst->match_num); - nodeHeap q((short)inst->match_num); + nodeHeap q((int)inst->match_num); int num_expanded_vertices; unsigned char* expanded_flag = new unsigned char[inst->match_num]; node* neighbors; @@ -600,8 +599,8 @@ void EdgeAwareInterpolatorImpl::GetKNNMatches_ParBody::operator() (const Range& num_expanded_vertices = 0; memset(expanded_flag,0,inst->match_num); q.clear(); - q.add(node((short)i,0.0f)); - short* NNlabels_row = inst->NNlabels.ptr(i); + q.add(node((int)i,0.0f)); + int* NNlabels_row = inst->NNlabels.ptr(i); float* NNdistances_row = inst->NNdistances.ptr(i); while(num_expanded_verticesk && !q.empty()) { @@ -625,7 +624,7 @@ void EdgeAwareInterpolatorImpl::GetKNNMatches_ParBody::operator() (const Range& delete[] expanded_flag; } -void weightedLeastSquaresAffineFit(short* labels, float* weights, int count, float lambda, SparseMatch* matches, Mat& dst) +void weightedLeastSquaresAffineFit(int* labels, float* weights, int count, float lambda, SparseMatch* matches, Mat& dst) { double sa[6][6]={{0.}}, sb[6]={0.}; Mat A (6, 6, CV_64F, &sa[0][0]), @@ -672,7 +671,7 @@ void weightedLeastSquaresAffineFit(short* labels, float* weights, int count, flo MM.reshape(2,3).convertTo(dst,CV_32F); } -void generateHypothesis(short* labels, int count, RNG& rng, unsigned char* is_used, SparseMatch* matches, Mat& dst) +void generateHypothesis(int* labels, int count, RNG& rng, unsigned char* is_used, SparseMatch* matches, Mat& dst) { int idx; Point2f src_points[3]; @@ -703,7 +702,7 @@ void generateHypothesis(short* labels, int count, RNG& rng, unsigned char* is_us getAffineTransform(src_points,dst_points).convertTo(dst,CV_32F); } -void verifyHypothesis(short* labels, float* weights, int count, SparseMatch* matches, float eps, float lambda, Mat& hypothesis_transform, Mat& old_transform, float& old_weighted_num_inliers) +void verifyHypothesis(int* labels, float* weights, int count, SparseMatch* matches, float eps, float lambda, Mat& hypothesis_transform, Mat& old_transform, float& old_weighted_num_inliers) { float* tr = hypothesis_transform.ptr(0); Point2f a,b; @@ -749,12 +748,12 @@ void EdgeAwareInterpolatorImpl::RansacInterpolation_ParBody::operator() (const R start = tmp-1; } - short* KNNlabels; + int* KNNlabels; float* KNNdistances; unsigned char* is_used = new unsigned char[inst->k]; Mat hypothesis_transform; - short* inlier_labels = new short[inst->k]; + int* inlier_labels = new int[inst->k]; float* inlier_distances = new float[inst->k]; float* tr; int num_inliers; @@ -765,7 +764,7 @@ void EdgeAwareInterpolatorImpl::RansacInterpolation_ParBody::operator() (const R if(inst->g[i].empty()) continue; - KNNlabels = inst->NNlabels.ptr(i); + KNNlabels = inst->NNlabels.ptr(i); KNNdistances = inst->NNdistances.ptr(i); if(inc>0) //forward pass { @@ -846,11 +845,11 @@ void EdgeAwareInterpolatorImpl::ransacInterpolation(vector& matches parallel_for_(Range(0,ransac_num_stripes),RansacInterpolation_ParBody(*this,transforms,weighted_inlier_nums,eps,&matches.front(),ransac_num_stripes,-1)); //construct the final piecewise-affine interpolation: - short* label_row; + int* label_row; float* tr; for(int i=0;i(i); + label_row = labels.ptr(i); Point2f* dst_row = dst_dense_flow.ptr(i); for(int j=0;j