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