@@ -57,16 +57,16 @@ struct SparseMatch
57
57
58
58
bool operator <(const SparseMatch& lhs,const SparseMatch& rhs);
59
59
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);
63
63
64
64
struct node
65
65
{
66
66
float dist;
67
- int label;
67
+ short label;
68
68
node () {}
69
- node (int l,float d): dist(d), label(l) {}
69
+ node (short l,float d): dist(d), label(l) {}
70
70
};
71
71
72
72
class EdgeAwareInterpolatorImpl CV_FINAL : public EdgeAwareInterpolator
@@ -217,7 +217,7 @@ void EdgeAwareInterpolatorImpl::preprocessData(Mat& src, vector<SparseMatch>& ma
217
217
y = min ((int )(matches[i].reference_image_pos .y +0 .5f ),h-1 );
218
218
219
219
distances.at <float >(y,x) = 0 .0f ;
220
- labels.at <int >(y,x) = (int )i;
220
+ labels.at <short >(y,x) = (short )i;
221
221
}
222
222
223
223
computeGradientMagnitude (src,cost_map);
@@ -271,8 +271,8 @@ void EdgeAwareInterpolatorImpl::geodesicDistanceTransform(Mat& distances, Mat& c
271
271
int i,j;
272
272
float *dist_row, *cost_row;
273
273
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;
276
276
277
277
#define CHECK (cur_dist,cur_label,cur_cost,prev_dist,prev_label,prev_cost,coef )\
278
278
{\
@@ -286,7 +286,7 @@ void EdgeAwareInterpolatorImpl::geodesicDistanceTransform(Mat& distances, Mat& c
286
286
{
287
287
// first pass (left-to-right, top-to-bottom):
288
288
dist_row = distances.ptr <float >(0 );
289
- label_row = labels.ptr <int >(0 );
289
+ label_row = labels.ptr <short >(0 );
290
290
cost_row = cost_map.ptr <float >(0 );
291
291
for (j=1 ;j<w;j++)
292
292
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
296
296
dist_row = distances.ptr <float >(i);
297
297
dist_row_prev = distances.ptr <float >(i-1 );
298
298
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 );
301
301
302
302
cost_row = cost_map.ptr <float >(i);
303
303
cost_row_prev = cost_map.ptr <float >(i-1 );
@@ -320,7 +320,7 @@ void EdgeAwareInterpolatorImpl::geodesicDistanceTransform(Mat& distances, Mat& c
320
320
321
321
// second pass (right-to-left, bottom-to-top):
322
322
dist_row = distances.ptr <float >(h-1 );
323
- label_row = labels.ptr <int >(h-1 );
323
+ label_row = labels.ptr <short >(h-1 );
324
324
cost_row = cost_map.ptr <float >(h-1 );
325
325
for (j=w-2 ;j>=0 ;j--)
326
326
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
330
330
dist_row = distances.ptr <float >(i);
331
331
dist_row_prev = distances.ptr <float >(i+1 );
332
332
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 );
335
335
336
336
cost_row = cost_map.ptr <float >(i);
337
337
cost_row_prev = cost_map.ptr <float >(i+1 );
@@ -359,8 +359,8 @@ void EdgeAwareInterpolatorImpl::buildGraph(Mat& distances, Mat& cost_map)
359
359
{
360
360
float *dist_row, *cost_row;
361
361
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;
364
364
int i,j;
365
365
const float c1 = 1 .0f /2 .0f ;
366
366
const float c2 = sqrt (2 .0f )/2 .0f ;
@@ -386,7 +386,7 @@ void EdgeAwareInterpolatorImpl::buildGraph(Mat& distances, Mat& cost_map)
386
386
}
387
387
388
388
dist_row = distances.ptr <float >(0 );
389
- label_row = labels.ptr <int >(0 );
389
+ label_row = labels.ptr <short >(0 );
390
390
cost_row = cost_map.ptr <float >(0 );
391
391
for (j=1 ;j<w;j++)
392
392
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)
396
396
dist_row = distances.ptr <float >(i);
397
397
dist_row_prev = distances.ptr <float >(i-1 );
398
398
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 );
401
401
402
402
cost_row = cost_map.ptr <float >(i);
403
403
cost_row_prev = cost_map.ptr <float >(i-1 );
@@ -441,7 +441,7 @@ void EdgeAwareInterpolatorImpl::buildGraph(Mat& distances, Mat& cost_map)
441
441
}
442
442
443
443
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 ));
445
445
}
446
446
}
447
447
}
@@ -452,18 +452,18 @@ struct nodeHeap
452
452
// children: 2*i, 2*i+1
453
453
// parent: i>>1
454
454
node* heap;
455
- int * heap_pos;
455
+ short * heap_pos;
456
456
node tmp_node;
457
- int size;
458
- int num_labels;
457
+ short size;
458
+ short num_labels;
459
459
460
- nodeHeap (int _num_labels)
460
+ nodeHeap (short _num_labels)
461
461
{
462
462
num_labels = _num_labels;
463
463
heap = new node[num_labels+1 ];
464
464
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);
467
467
size=0 ;
468
468
}
469
469
@@ -476,15 +476,15 @@ struct nodeHeap
476
476
void clear ()
477
477
{
478
478
size=0 ;
479
- memset (heap_pos,0 ,sizeof (int )*num_labels);
479
+ memset (heap_pos,0 ,sizeof (short )*num_labels);
480
480
}
481
481
482
482
inline bool empty ()
483
483
{
484
484
return (size==0 );
485
485
}
486
486
487
- inline void nodeSwap (int idx1, int idx2)
487
+ inline void nodeSwap (short idx1, short idx2)
488
488
{
489
489
heap_pos[heap[idx1].label ] = idx2;
490
490
heap_pos[heap[idx2].label ] = idx1;
@@ -499,8 +499,8 @@ struct nodeHeap
499
499
size++;
500
500
heap[size] = n;
501
501
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 ;
504
504
while (heap[i].dist <heap[parent_i].dist )
505
505
{
506
506
nodeSwap (i,parent_i);
@@ -514,8 +514,8 @@ struct nodeHeap
514
514
node res = heap[1 ];
515
515
heap_pos[res.label ] = 0 ;
516
516
517
- int i=1 ;
518
- int left,right;
517
+ short i=1 ;
518
+ short left,right;
519
519
while ( (left=i<<1 ) < size )
520
520
{
521
521
right = left+1 ;
@@ -542,7 +542,7 @@ struct nodeHeap
542
542
heap[i] = heap[size];
543
543
heap_pos[heap[i].label ] = i;
544
544
545
- int parent_i = i>>1 ;
545
+ short parent_i = i>>1 ;
546
546
while (heap[i].dist <heap[parent_i].dist )
547
547
{
548
548
nodeSwap (i,parent_i);
@@ -561,9 +561,9 @@ struct nodeHeap
561
561
{
562
562
if (heap_pos[n.label ])
563
563
{
564
- int i = heap_pos[n.label ];
564
+ short i = heap_pos[n.label ];
565
565
heap[i].dist = min (heap[i].dist ,n.dist );
566
- int parent_i = i>>1 ;
566
+ short parent_i = i>>1 ;
567
567
while (heap[i].dist <heap[parent_i].dist )
568
568
{
569
569
nodeSwap (i,parent_i);
@@ -586,7 +586,7 @@ void EdgeAwareInterpolatorImpl::GetKNNMatches_ParBody::operator() (const Range&
586
586
{
587
587
int start = std::min (range.start * stripe_sz, inst->match_num );
588
588
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 );
590
590
int num_expanded_vertices;
591
591
unsigned char * expanded_flag = new unsigned char [inst->match_num ];
592
592
node* neighbors;
@@ -599,8 +599,8 @@ void EdgeAwareInterpolatorImpl::GetKNNMatches_ParBody::operator() (const Range&
599
599
num_expanded_vertices = 0 ;
600
600
memset (expanded_flag,0 ,inst->match_num );
601
601
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);
604
604
float * NNdistances_row = inst->NNdistances .ptr <float >(i);
605
605
while (num_expanded_vertices<inst->k && !q.empty ())
606
606
{
@@ -624,7 +624,7 @@ void EdgeAwareInterpolatorImpl::GetKNNMatches_ParBody::operator() (const Range&
624
624
delete[] expanded_flag;
625
625
}
626
626
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)
628
628
{
629
629
double sa[6 ][6 ]={{0 .}}, sb[6 ]={0 .};
630
630
Mat A (6 , 6 , CV_64F, &sa[0 ][0 ]),
@@ -671,7 +671,7 @@ void weightedLeastSquaresAffineFit(int* labels, float* weights, int count, float
671
671
MM.reshape (2 ,3 ).convertTo (dst,CV_32F);
672
672
}
673
673
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)
675
675
{
676
676
int idx;
677
677
Point2f src_points[3 ];
@@ -702,7 +702,7 @@ void generateHypothesis(int* labels, int count, RNG& rng, unsigned char* is_used
702
702
getAffineTransform (src_points,dst_points).convertTo (dst,CV_32F);
703
703
}
704
704
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)
706
706
{
707
707
float * tr = hypothesis_transform.ptr <float >(0 );
708
708
Point2f a,b;
@@ -748,12 +748,12 @@ void EdgeAwareInterpolatorImpl::RansacInterpolation_ParBody::operator() (const R
748
748
start = tmp-1 ;
749
749
}
750
750
751
- int * KNNlabels;
751
+ short * KNNlabels;
752
752
float * KNNdistances;
753
753
unsigned char * is_used = new unsigned char [inst->k ];
754
754
Mat hypothesis_transform;
755
755
756
- int * inlier_labels = new int [inst->k ];
756
+ short * inlier_labels = new short [inst->k ];
757
757
float * inlier_distances = new float [inst->k ];
758
758
float * tr;
759
759
int num_inliers;
@@ -764,7 +764,7 @@ void EdgeAwareInterpolatorImpl::RansacInterpolation_ParBody::operator() (const R
764
764
if (inst->g [i].empty ())
765
765
continue ;
766
766
767
- KNNlabels = inst->NNlabels .ptr <int >(i);
767
+ KNNlabels = inst->NNlabels .ptr <short >(i);
768
768
KNNdistances = inst->NNdistances .ptr <float >(i);
769
769
if (inc>0 ) // forward pass
770
770
{
@@ -845,11 +845,11 @@ void EdgeAwareInterpolatorImpl::ransacInterpolation(vector<SparseMatch>& matches
845
845
parallel_for_ (Range (0 ,ransac_num_stripes),RansacInterpolation_ParBody (*this ,transforms,weighted_inlier_nums,eps,&matches.front (),ransac_num_stripes,-1 ));
846
846
847
847
// construct the final piecewise-affine interpolation:
848
- int * label_row;
848
+ short * label_row;
849
849
float * tr;
850
850
for (int i=0 ;i<h;i++)
851
851
{
852
- label_row = labels.ptr <int >(i);
852
+ label_row = labels.ptr <short >(i);
853
853
Point2f* dst_row = dst_dense_flow.ptr <Point2f>(i);
854
854
for (int j=0 ;j<w;j++)
855
855
{
0 commit comments