@@ -53,10 +53,7 @@ ERStat::ERStat(int init_level, int init_pixel, int init_x, int init_y) : pixel(i
53
53
parent(0 ), child(0 ), next(0 ), prev(0 ), local_maxima(0 ),
54
54
max_probability_ancestor(0 ), min_probability_ancestor(0 )
55
55
{
56
- bbox[0 ] = init_x;
57
- bbox[1 ] = init_y;
58
- bbox[2 ] = init_x;
59
- bbox[3 ] = init_y;
56
+ rect = Rect (init_x,init_y,1 ,1 );
60
57
raw_moments[0 ] = 0.0 ;
61
58
raw_moments[1 ] = 0.0 ;
62
59
central_moments[0 ] = 0.0 ;
@@ -543,21 +540,25 @@ void ERFilterNM::er_add_pixel(ERStat *parent, int x, int y, int non_border_neigh
543
540
544
541
if (parent->crossings ->size ()>0 )
545
542
{
546
- if (y<parent->bbox [ 1 ] ) parent->crossings ->push_front (2 );
547
- else if (y>parent->bbox [ 3 ] ) parent->crossings ->push_back (2 );
543
+ if (y<parent->rect . y ) parent->crossings ->push_front (2 );
544
+ else if (y>parent->rect . br (). y - 1 ) parent->crossings ->push_back (2 );
548
545
else {
549
- parent->crossings ->at (y - parent->bbox [ 1 ] ) += 2 -2 *non_border_neighbours_horiz;
546
+ parent->crossings ->at (y - parent->rect . y ) += 2 -2 *non_border_neighbours_horiz;
550
547
}
551
548
} else {
552
549
parent->crossings ->push_back (2 );
553
550
}
554
551
555
552
parent->euler += (d_C1 - d_C2 + 2 *d_C3) / 4 ;
556
553
557
- parent->bbox [0 ] = min (parent->bbox [0 ],x);
558
- parent->bbox [1 ] = min (parent->bbox [1 ],y);
559
- parent->bbox [2 ] = max (parent->bbox [2 ],x);
560
- parent->bbox [3 ] = max (parent->bbox [3 ],y);
554
+ int new_x1 = min (parent->rect .x ,x);
555
+ int new_y1 = min (parent->rect .y ,y);
556
+ int new_x2 = max (parent->rect .br ().x -1 ,x);
557
+ int new_y2 = max (parent->rect .br ().y -1 ,y);
558
+ parent->rect .x = new_x1;
559
+ parent->rect .y = new_y1;
560
+ parent->rect .width = new_x2-new_x1+1 ;
561
+ parent->rect .height = new_y2-new_y1+1 ;
561
562
562
563
parent->raw_moments [0 ] += x;
563
564
parent->raw_moments [1 ] += y;
@@ -574,29 +575,34 @@ void ERFilterNM::er_merge(ERStat *parent, ERStat *child)
574
575
parent->area += child->area ;
575
576
576
577
parent->perimeter += child->perimeter ;
578
+
577
579
578
- for (int i=parent->bbox [ 1 ] ; i<=min (parent->bbox [ 3 ] ,child->bbox [ 3 ] ); i++)
579
- if (i-child->bbox [ 1 ] >= 0 )
580
- parent->crossings ->at (i-parent->bbox [ 1 ] ) += child->crossings ->at (i-child->bbox [ 1 ] );
580
+ for (int i=parent->rect . y ; i<=min (parent->rect . br (). y - 1 ,child->rect . br (). y - 1 ); i++)
581
+ if (i-child->rect . y >= 0 )
582
+ parent->crossings ->at (i-parent->rect . y ) += child->crossings ->at (i-child->rect . y );
581
583
582
- for (int i=parent->bbox [ 1 ] -1 ; i>=child->bbox [ 1 ] ; i--)
583
- if (i-child->bbox [ 1 ] < (int )child->crossings ->size ())
584
- parent->crossings ->push_front (child->crossings ->at (i-child->bbox [ 1 ] ));
584
+ for (int i=parent->rect . y -1 ; i>=child->rect . y ; i--)
585
+ if (i-child->rect . y < (int )child->crossings ->size ())
586
+ parent->crossings ->push_front (child->crossings ->at (i-child->rect . y ));
585
587
else
586
588
parent->crossings ->push_front (0 );
587
589
588
- for (int i=parent->bbox [ 3 ]+ 1 ; i<child->bbox [ 1 ] ; i++)
590
+ for (int i=parent->rect . br (). y ; i<child->rect . y ; i++)
589
591
parent->crossings ->push_back (0 );
590
592
591
- for (int i=max (parent->bbox [ 3 ]+ 1 ,child->bbox [ 1 ] ); i<=child->bbox [ 3 ] ; i++)
592
- parent->crossings ->push_back (child->crossings ->at (i-child->bbox [ 1 ] ));
593
+ for (int i=max (parent->rect . br (). y ,child->rect . y ); i<=child->rect . br (). y - 1 ; i++)
594
+ parent->crossings ->push_back (child->crossings ->at (i-child->rect . y ));
593
595
594
596
parent->euler += child->euler ;
595
597
596
- parent->bbox [0 ] = min (parent->bbox [0 ],child->bbox [0 ]);
597
- parent->bbox [1 ] = min (parent->bbox [1 ],child->bbox [1 ]);
598
- parent->bbox [2 ] = max (parent->bbox [2 ],child->bbox [2 ]);
599
- parent->bbox [3 ] = max (parent->bbox [3 ],child->bbox [3 ]);
598
+ int new_x1 = min (parent->rect .x ,child->rect .x );
599
+ int new_y1 = min (parent->rect .y ,child->rect .y );
600
+ int new_x2 = max (parent->rect .br ().x -1 ,child->rect .br ().x -1 );
601
+ int new_y2 = max (parent->rect .br ().y -1 ,child->rect .br ().y -1 );
602
+ parent->rect .x = new_x1;
603
+ parent->rect .y = new_y1;
604
+ parent->rect .width = new_x2-new_x1+1 ;
605
+ parent->rect .height = new_y2-new_y1+1 ;
600
606
601
607
parent->raw_moments [0 ] += child->raw_moments [0 ];
602
608
parent->raw_moments [1 ] += child->raw_moments [1 ];
@@ -606,14 +612,14 @@ void ERFilterNM::er_merge(ERStat *parent, ERStat *child)
606
612
parent->central_moments [2 ] += child->central_moments [2 ];
607
613
608
614
// child region done, we can calculate 1st stage features from the incrementally computable descriptors
609
- child->aspect_ratio = (float )(child->bbox [ 2 ]-child-> bbox [ 0 ]+ 1 )/(child->bbox [ 3 ]-child-> bbox [ 1 ]+ 1 );
615
+ child->aspect_ratio = (float )(child->rect . width )/(child->rect . height );
610
616
child->compactness = sqrt ((float )(child->area ))/child->perimeter ;
611
617
child->num_holes = (float )(1 -child->euler );
612
618
613
619
vector<int > m_crossings;
614
- m_crossings.push_back (child->crossings ->at ((int )(child->bbox [ 3 ]-child-> bbox [ 1 ]+ 1 )/6 ));
615
- m_crossings.push_back (child->crossings ->at ((int )3 *(child->bbox [ 3 ]-child-> bbox [ 1 ]+ 1 )/6 ));
616
- m_crossings.push_back (child->crossings ->at ((int )5 *(child->bbox [ 3 ]-child-> bbox [ 1 ]+ 1 )/6 ));
620
+ m_crossings.push_back (child->crossings ->at ((int )(child->rect . height )/6 ));
621
+ m_crossings.push_back (child->crossings ->at ((int )3 *(child->rect . height )/6 ));
622
+ m_crossings.push_back (child->crossings ->at ((int )5 *(child->rect . height )/6 ));
617
623
std::sort (m_crossings.begin (), m_crossings.end ());
618
624
child->med_crossings = (float )m_crossings.at (1 );
619
625
@@ -750,14 +756,14 @@ ERStat* ERFilterNM::er_tree_filter ( cv::InputArray image, ERStat * stat, ERStat
750
756
CV_Assert ( src.type () == CV_8UC1 );
751
757
752
758
// Fill the region and calculate 2nd stage features
753
- Mat region = region_mask (Rect (Point (stat->bbox [ 0 ] ,stat->bbox [ 1 ] ),Point (stat->bbox [ 2 ]+ 3 ,stat->bbox [ 3 ]+ 3 )));
759
+ Mat region = region_mask (Rect (Point (stat->rect . x ,stat->rect . y ),Point (stat->rect . br (). x + 2 ,stat->rect . br (). y + 2 )));
754
760
region = Scalar (0 );
755
761
int newMaskVal = 255 ;
756
762
int flags = 4 + (newMaskVal << 8 ) + FLOODFILL_FIXED_RANGE + FLOODFILL_MASK_ONLY;
757
763
Rect rect;
758
764
759
- floodFill ( src (Rect (Point (stat->bbox [ 0 ] ,stat->bbox [ 1 ] ),Point (stat->bbox [ 2 ]+ 1 ,stat->bbox [ 3 ]+ 1 ))),
760
- region, Point (stat->pixel %src.cols - stat->bbox [ 0 ] , stat->pixel /src.cols - stat->bbox [ 1 ] ),
765
+ floodFill ( src (Rect (Point (stat->rect . x ,stat->rect . y ),Point (stat->rect . br (). x ,stat->rect . br (). y ))),
766
+ region, Point (stat->pixel %src.cols - stat->rect . x , stat->pixel /src.cols - stat->rect . y ),
761
767
Scalar (255 ), &rect, Scalar (stat->level ), Scalar (0 ), flags );
762
768
rect.width += 2 ;
763
769
rect.height += 2 ;
0 commit comments