Skip to content

Commit 48b5b63

Browse files
author
senst
committed
Revert "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"
This reverts commit 8ecfbdc
1 parent d88172a commit 48b5b63

File tree

1 file changed

+46
-46
lines changed

1 file changed

+46
-46
lines changed

modules/ximgproc/src/sparse_match_interpolators.cpp

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,16 @@ struct SparseMatch
5757

5858
bool operator<(const SparseMatch& lhs,const SparseMatch& rhs);
5959

60-
void weightedLeastSquaresAffineFit(int* labels, float* weights, int count, float lambda, SparseMatch* matches, Mat& dst);
61-
void generateHypothesis(int* labels, int count, RNG& rng, unsigned char* is_used, SparseMatch* matches, Mat& dst);
62-
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);
60+
void weightedLeastSquaresAffineFit(short* labels, float* weights, int count, float lambda, SparseMatch* matches, Mat& dst);
61+
void generateHypothesis(short* labels, int count, RNG& rng, unsigned char* is_used, SparseMatch* matches, Mat& dst);
62+
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);
6363

6464
struct node
6565
{
6666
float dist;
67-
int label;
67+
short label;
6868
node() {}
69-
node(int l,float d): dist(d), label(l) {}
69+
node(short l,float d): dist(d), label(l) {}
7070
};
7171

7272
class EdgeAwareInterpolatorImpl CV_FINAL : public EdgeAwareInterpolator
@@ -217,7 +217,7 @@ void EdgeAwareInterpolatorImpl::preprocessData(Mat& src, vector<SparseMatch>& ma
217217
y = min((int)(matches[i].reference_image_pos.y+0.5f),h-1);
218218

219219
distances.at<float>(y,x) = 0.0f;
220-
labels.at<int>(y,x) = (int)i;
220+
labels.at<short>(y,x) = (short)i;
221221
}
222222

223223
computeGradientMagnitude(src,cost_map);
@@ -271,8 +271,8 @@ void EdgeAwareInterpolatorImpl::geodesicDistanceTransform(Mat& distances, Mat& c
271271
int i,j;
272272
float *dist_row, *cost_row;
273273
float *dist_row_prev, *cost_row_prev;
274-
int *label_row;
275-
int *label_row_prev;
274+
short *label_row;
275+
short *label_row_prev;
276276

277277
#define CHECK(cur_dist,cur_label,cur_cost,prev_dist,prev_label,prev_cost,coef)\
278278
{\
@@ -286,7 +286,7 @@ void EdgeAwareInterpolatorImpl::geodesicDistanceTransform(Mat& distances, Mat& c
286286
{
287287
//first pass (left-to-right, top-to-bottom):
288288
dist_row = distances.ptr<float>(0);
289-
label_row = labels.ptr<int>(0);
289+
label_row = labels.ptr<short>(0);
290290
cost_row = cost_map.ptr<float>(0);
291291
for(j=1;j<w;j++)
292292
CHECK(dist_row[j],label_row[j],cost_row[j],dist_row[j-1],label_row[j-1],cost_row[j-1],c1);
@@ -296,8 +296,8 @@ void EdgeAwareInterpolatorImpl::geodesicDistanceTransform(Mat& distances, Mat& c
296296
dist_row = distances.ptr<float>(i);
297297
dist_row_prev = distances.ptr<float>(i-1);
298298

299-
label_row = labels.ptr<int>(i);
300-
label_row_prev = labels.ptr<int>(i-1);
299+
label_row = labels.ptr<short>(i);
300+
label_row_prev = labels.ptr<short>(i-1);
301301

302302
cost_row = cost_map.ptr<float>(i);
303303
cost_row_prev = cost_map.ptr<float>(i-1);
@@ -320,7 +320,7 @@ void EdgeAwareInterpolatorImpl::geodesicDistanceTransform(Mat& distances, Mat& c
320320

321321
//second pass (right-to-left, bottom-to-top):
322322
dist_row = distances.ptr<float>(h-1);
323-
label_row = labels.ptr<int>(h-1);
323+
label_row = labels.ptr<short>(h-1);
324324
cost_row = cost_map.ptr<float>(h-1);
325325
for(j=w-2;j>=0;j--)
326326
CHECK(dist_row[j],label_row[j],cost_row[j],dist_row[j+1],label_row[j+1],cost_row[j+1],c1);
@@ -330,8 +330,8 @@ void EdgeAwareInterpolatorImpl::geodesicDistanceTransform(Mat& distances, Mat& c
330330
dist_row = distances.ptr<float>(i);
331331
dist_row_prev = distances.ptr<float>(i+1);
332332

333-
label_row = labels.ptr<int>(i);
334-
label_row_prev = labels.ptr<int>(i+1);
333+
label_row = labels.ptr<short>(i);
334+
label_row_prev = labels.ptr<short>(i+1);
335335

336336
cost_row = cost_map.ptr<float>(i);
337337
cost_row_prev = cost_map.ptr<float>(i+1);
@@ -359,8 +359,8 @@ void EdgeAwareInterpolatorImpl::buildGraph(Mat& distances, Mat& cost_map)
359359
{
360360
float *dist_row, *cost_row;
361361
float *dist_row_prev, *cost_row_prev;
362-
int *label_row;
363-
int *label_row_prev;
362+
short *label_row;
363+
short *label_row_prev;
364364
int i,j;
365365
const float c1 = 1.0f/2.0f;
366366
const float c2 = sqrt(2.0f)/2.0f;
@@ -386,7 +386,7 @@ void EdgeAwareInterpolatorImpl::buildGraph(Mat& distances, Mat& cost_map)
386386
}
387387

388388
dist_row = distances.ptr<float>(0);
389-
label_row = labels.ptr<int>(0);
389+
label_row = labels.ptr<short>(0);
390390
cost_row = cost_map.ptr<float>(0);
391391
for(j=1;j<w;j++)
392392
CHECK(dist_row[j],label_row[j],cost_row[j],dist_row[j-1],label_row[j-1],cost_row[j-1],c1);
@@ -396,8 +396,8 @@ void EdgeAwareInterpolatorImpl::buildGraph(Mat& distances, Mat& cost_map)
396396
dist_row = distances.ptr<float>(i);
397397
dist_row_prev = distances.ptr<float>(i-1);
398398

399-
label_row = labels.ptr<int>(i);
400-
label_row_prev = labels.ptr<int>(i-1);
399+
label_row = labels.ptr<short>(i);
400+
label_row_prev = labels.ptr<short>(i-1);
401401

402402
cost_row = cost_map.ptr<float>(i);
403403
cost_row_prev = cost_map.ptr<float>(i-1);
@@ -441,7 +441,7 @@ void EdgeAwareInterpolatorImpl::buildGraph(Mat& distances, Mat& cost_map)
441441
}
442442

443443
if(!found)
444-
g[neighbors[j].label].push_back(node((int)i,neighbors[j].dist));
444+
g[neighbors[j].label].push_back(node((short)i,neighbors[j].dist));
445445
}
446446
}
447447
}
@@ -452,18 +452,18 @@ struct nodeHeap
452452
// children: 2*i, 2*i+1
453453
// parent: i>>1
454454
node* heap;
455-
int* heap_pos;
455+
short* heap_pos;
456456
node tmp_node;
457-
int size;
458-
int num_labels;
457+
short size;
458+
short num_labels;
459459

460-
nodeHeap(int _num_labels)
460+
nodeHeap(short _num_labels)
461461
{
462462
num_labels = _num_labels;
463463
heap = new node[num_labels+1];
464464
heap[0] = node(-1,-1.0f);
465-
heap_pos = new int[num_labels];
466-
memset(heap_pos,0,sizeof(int)*num_labels);
465+
heap_pos = new short[num_labels];
466+
memset(heap_pos,0,sizeof(short)*num_labels);
467467
size=0;
468468
}
469469

@@ -476,15 +476,15 @@ struct nodeHeap
476476
void clear()
477477
{
478478
size=0;
479-
memset(heap_pos,0,sizeof(int)*num_labels);
479+
memset(heap_pos,0,sizeof(short)*num_labels);
480480
}
481481

482482
inline bool empty()
483483
{
484484
return (size==0);
485485
}
486486

487-
inline void nodeSwap(int idx1, int idx2)
487+
inline void nodeSwap(short idx1, short idx2)
488488
{
489489
heap_pos[heap[idx1].label] = idx2;
490490
heap_pos[heap[idx2].label] = idx1;
@@ -499,8 +499,8 @@ struct nodeHeap
499499
size++;
500500
heap[size] = n;
501501
heap_pos[n.label] = size;
502-
int i = size;
503-
int parent_i = i>>1;
502+
short i = size;
503+
short parent_i = i>>1;
504504
while(heap[i].dist<heap[parent_i].dist)
505505
{
506506
nodeSwap(i,parent_i);
@@ -514,8 +514,8 @@ struct nodeHeap
514514
node res = heap[1];
515515
heap_pos[res.label] = 0;
516516

517-
int i=1;
518-
int left,right;
517+
short i=1;
518+
short left,right;
519519
while( (left=i<<1) < size )
520520
{
521521
right = left+1;
@@ -542,7 +542,7 @@ struct nodeHeap
542542
heap[i] = heap[size];
543543
heap_pos[heap[i].label] = i;
544544

545-
int parent_i = i>>1;
545+
short parent_i = i>>1;
546546
while(heap[i].dist<heap[parent_i].dist)
547547
{
548548
nodeSwap(i,parent_i);
@@ -561,9 +561,9 @@ struct nodeHeap
561561
{
562562
if(heap_pos[n.label])
563563
{
564-
int i = heap_pos[n.label];
564+
short i = heap_pos[n.label];
565565
heap[i].dist = min(heap[i].dist,n.dist);
566-
int parent_i = i>>1;
566+
short parent_i = i>>1;
567567
while(heap[i].dist<heap[parent_i].dist)
568568
{
569569
nodeSwap(i,parent_i);
@@ -586,7 +586,7 @@ void EdgeAwareInterpolatorImpl::GetKNNMatches_ParBody::operator() (const Range&
586586
{
587587
int start = std::min(range.start * stripe_sz, inst->match_num);
588588
int end = std::min(range.end * stripe_sz, inst->match_num);
589-
nodeHeap q((int)inst->match_num);
589+
nodeHeap q((short)inst->match_num);
590590
int num_expanded_vertices;
591591
unsigned char* expanded_flag = new unsigned char[inst->match_num];
592592
node* neighbors;
@@ -599,8 +599,8 @@ void EdgeAwareInterpolatorImpl::GetKNNMatches_ParBody::operator() (const Range&
599599
num_expanded_vertices = 0;
600600
memset(expanded_flag,0,inst->match_num);
601601
q.clear();
602-
q.add(node((int)i,0.0f));
603-
int* NNlabels_row = inst->NNlabels.ptr<int>(i);
602+
q.add(node((short)i,0.0f));
603+
short* NNlabels_row = inst->NNlabels.ptr<short>(i);
604604
float* NNdistances_row = inst->NNdistances.ptr<float>(i);
605605
while(num_expanded_vertices<inst->k && !q.empty())
606606
{
@@ -624,7 +624,7 @@ void EdgeAwareInterpolatorImpl::GetKNNMatches_ParBody::operator() (const Range&
624624
delete[] expanded_flag;
625625
}
626626

627-
void weightedLeastSquaresAffineFit(int* labels, float* weights, int count, float lambda, SparseMatch* matches, Mat& dst)
627+
void weightedLeastSquaresAffineFit(short* labels, float* weights, int count, float lambda, SparseMatch* matches, Mat& dst)
628628
{
629629
double sa[6][6]={{0.}}, sb[6]={0.};
630630
Mat A (6, 6, CV_64F, &sa[0][0]),
@@ -671,7 +671,7 @@ void weightedLeastSquaresAffineFit(int* labels, float* weights, int count, float
671671
MM.reshape(2,3).convertTo(dst,CV_32F);
672672
}
673673

674-
void generateHypothesis(int* labels, int count, RNG& rng, unsigned char* is_used, SparseMatch* matches, Mat& dst)
674+
void generateHypothesis(short* labels, int count, RNG& rng, unsigned char* is_used, SparseMatch* matches, Mat& dst)
675675
{
676676
int idx;
677677
Point2f src_points[3];
@@ -702,7 +702,7 @@ void generateHypothesis(int* labels, int count, RNG& rng, unsigned char* is_used
702702
getAffineTransform(src_points,dst_points).convertTo(dst,CV_32F);
703703
}
704704

705-
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)
705+
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)
706706
{
707707
float* tr = hypothesis_transform.ptr<float>(0);
708708
Point2f a,b;
@@ -748,12 +748,12 @@ void EdgeAwareInterpolatorImpl::RansacInterpolation_ParBody::operator() (const R
748748
start = tmp-1;
749749
}
750750

751-
int* KNNlabels;
751+
short* KNNlabels;
752752
float* KNNdistances;
753753
unsigned char* is_used = new unsigned char[inst->k];
754754
Mat hypothesis_transform;
755755

756-
int* inlier_labels = new int[inst->k];
756+
short* inlier_labels = new short[inst->k];
757757
float* inlier_distances = new float[inst->k];
758758
float* tr;
759759
int num_inliers;
@@ -764,7 +764,7 @@ void EdgeAwareInterpolatorImpl::RansacInterpolation_ParBody::operator() (const R
764764
if(inst->g[i].empty())
765765
continue;
766766

767-
KNNlabels = inst->NNlabels.ptr<int>(i);
767+
KNNlabels = inst->NNlabels.ptr<short>(i);
768768
KNNdistances = inst->NNdistances.ptr<float>(i);
769769
if(inc>0) //forward pass
770770
{
@@ -845,11 +845,11 @@ void EdgeAwareInterpolatorImpl::ransacInterpolation(vector<SparseMatch>& matches
845845
parallel_for_(Range(0,ransac_num_stripes),RansacInterpolation_ParBody(*this,transforms,weighted_inlier_nums,eps,&matches.front(),ransac_num_stripes,-1));
846846

847847
//construct the final piecewise-affine interpolation:
848-
int* label_row;
848+
short* label_row;
849849
float* tr;
850850
for(int i=0;i<h;i++)
851851
{
852-
label_row = labels.ptr<int>(i);
852+
label_row = labels.ptr<short>(i);
853853
Point2f* dst_row = dst_dense_flow.ptr<Point2f>(i);
854854
for(int j=0;j<w;j++)
855855
{

0 commit comments

Comments
 (0)