@@ -54,7 +54,7 @@ Ptr<cuda::BackgroundSubtractorFGD> cv::cuda::createBackgroundSubtractorFGD(const
54
54
#else
55
55
56
56
#include " cuda/fgd.hpp"
57
- #include " opencv2/imgproc/imgproc_c.h "
57
+ #include " opencv2/imgproc.hpp "
58
58
59
59
// ///////////////////////////////////////////////////////////////////////
60
60
// FGDParams
@@ -345,69 +345,35 @@ namespace
345
345
346
346
namespace
347
347
{
348
- void seqToContours (CvSeq* _ccontours, CvMemStorage* storage, OutputArrayOfArrays _contours)
349
- {
350
- Seq<CvSeq*> all_contours (cvTreeToNodeSeq (_ccontours, sizeof (CvSeq), storage));
351
-
352
- size_t total = all_contours.size ();
353
-
354
- _contours.create ((int ) total, 1 , 0 , -1 , true );
355
-
356
- SeqIterator<CvSeq*> it = all_contours.begin ();
357
- for (size_t i = 0 ; i < total; ++i, ++it)
358
- {
359
- CvSeq* c = *it;
360
- ((CvContour*)c)->color = (int )i;
361
- _contours.create ((int )c->total , 1 , CV_32SC2, (int )i, true );
362
- Mat ci = _contours.getMat ((int )i);
363
- CV_Assert ( ci.isContinuous () );
364
- cvCvtSeqToArray (c, ci.data );
365
- }
366
- }
367
-
368
348
int findForegroundRegions (GpuMat& d_foreground, Mat& h_foreground, std::vector< std::vector<Point> >& foreground_regions,
369
- CvMemStorage* storage, const FGDParams& params)
349
+ const FGDParams& params)
370
350
{
371
351
int region_count = 0 ;
372
352
373
353
// Discard under-size foreground regions:
374
354
375
355
d_foreground.download (h_foreground);
376
- IplImage ipl_foreground = cvIplImage (h_foreground);
377
- CvSeq* first_seq = 0 ;
378
356
379
- cvFindContours (&ipl_foreground, storage, &first_seq, sizeof (CvContour), CV_RETR_LIST);
357
+ int mode = RETR_LIST;
358
+ if (params.is_obj_without_holes ) mode |= RETR_EXTERNAL;
359
+ findContours (h_foreground, foreground_regions, mode, CHAIN_APPROX_NONE);
380
360
381
- for (CvSeq* seq = first_seq; seq; seq = seq-> h_next )
361
+ for (size_t i = 0 ; i < foreground_regions. size (); ++i )
382
362
{
383
- CvContour* cnt = reinterpret_cast <CvContour*>(seq);
363
+ const std::vector<Point> &cnt = foreground_regions[i];
364
+ const Rect rect = boundingRect (cnt);
384
365
385
- if (cnt-> rect .width * cnt-> rect .height < params.minArea || (params. is_obj_without_holes && CV_IS_SEQ_HOLE (seq)) )
366
+ if (rect.width * rect.height < params.minArea )
386
367
{
387
368
// Delete under-size contour:
388
- CvSeq* prev_seq = seq->h_prev ;
389
- if (prev_seq)
390
- {
391
- prev_seq->h_next = seq->h_next ;
392
-
393
- if (seq->h_next )
394
- seq->h_next ->h_prev = prev_seq;
395
- }
396
- else
397
- {
398
- first_seq = seq->h_next ;
399
-
400
- if (seq->h_next )
401
- seq->h_next ->h_prev = NULL ;
402
- }
403
369
}
404
370
else
405
371
{
406
- region_count++;
372
+ foreground_regions[ region_count++] = foreground_regions[i] ;
407
373
}
408
374
}
409
375
410
- seqToContours (first_seq, storage, foreground_regions);
376
+ foreground_regions. resize (region_count );
411
377
h_foreground.setTo (0 );
412
378
413
379
drawContours (h_foreground, foreground_regions, -1 , Scalar::all (255 ), -1 );
@@ -612,19 +578,14 @@ namespace
612
578
Ptr<cuda::Filter> dilateFilter_;
613
579
Ptr<cuda::Filter> erodeFilter_;
614
580
#endif
615
-
616
- CvMemStorage* storage_;
617
581
};
618
582
619
583
FGDImpl::FGDImpl (const FGDParams& params) : params_(params), frameSize_(0 , 0 )
620
584
{
621
- storage_ = cvCreateMemStorage ();
622
- CV_Assert ( storage_ != 0 );
623
585
}
624
586
625
587
FGDImpl::~FGDImpl ()
626
588
{
627
- cvReleaseMemStorage (&storage_);
628
589
}
629
590
630
591
void FGDImpl::apply (InputArray _frame, OutputArray fgmask, double )
@@ -640,7 +601,6 @@ namespace
640
601
CV_Assert ( curFrame.type () == CV_8UC3 || curFrame.type () == CV_8UC4 );
641
602
CV_Assert ( curFrame.size () == prevFrame_.size () );
642
603
643
- cvClearMemStorage (storage_);
644
604
foreground_regions_.clear ();
645
605
foreground_.setTo (Scalar::all (0 ));
646
606
@@ -655,7 +615,7 @@ namespace
655
615
#endif
656
616
657
617
if (params_.minArea > 0 || params_.is_obj_without_holes )
658
- findForegroundRegions (foreground_, h_foreground_, foreground_regions_, storage_, params_);
618
+ findForegroundRegions (foreground_, h_foreground_, foreground_regions_, params_);
659
619
660
620
// Check ALL BG update condition:
661
621
const double BGFG_FGD_BG_UPDATE_TRESH = 0.5 ;
0 commit comments