Skip to content

Commit

Permalink
Merge pull request Smorodov#41 from Nuzhny007/master
Browse files Browse the repository at this point in the history
Some sppedup for Motion detection
  • Loading branch information
Smorodov authored Aug 18, 2017
2 parents 7c50791 + b02c795 commit 56fc3a5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
8 changes: 8 additions & 0 deletions Detector/BackgroundSubtract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ BackgroundSubtract::BackgroundSubtract(
m_modelSuBSENSE = std::make_unique<BackgroundSubtractorLOBSTER>(); // default params
break;

case ALG_MOG2:
m_modelOCV = cv::createBackgroundSubtractorMOG2(500, 16, true).dynamicCast<cv::BackgroundSubtractor>();
break;

default:
m_modelVibe = std::make_unique<vibe::VIBE>(m_channels, samples, pixel_neighbor, distance_threshold, matching_threshold, update_factor);
break;
Expand Down Expand Up @@ -137,6 +141,10 @@ void BackgroundSubtract::subtract(const cv::Mat& image, cv::Mat& foreground)
}
break;

case ALG_MOG2:
m_modelOCV->apply(GetImg(), foreground);
break;

default:
m_modelVibe->update(GetImg());
foreground = m_modelVibe->getMask();
Expand Down
5 changes: 2 additions & 3 deletions Detector/BackgroundSubtract.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class BackgroundSubtract
ALG_GMG,
ALG_CNT,
ALG_SuBSENSE,
ALG_LOBSTER
ALG_LOBSTER,
ALG_MOG2
};

BackgroundSubtract(BGFG_ALGS algType, int channels = 1, int samples = 20, int pixel_neighbor = 1, int distance_threshold = 20, int matching_threshold = 3, int update_factor = 16);
Expand All @@ -33,9 +34,7 @@ class BackgroundSubtract

private:
std::unique_ptr<vibe::VIBE> m_modelVibe;
#if USE_OCV_BGFG
cv::Ptr<cv::BackgroundSubtractor> m_modelOCV;
#endif
std::unique_ptr<BackgroundSubtractorLBSP> m_modelSuBSENSE;
};

Expand Down
8 changes: 5 additions & 3 deletions Tracker/track.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,12 @@ class CTrack
params.compressed_size = 1;
params.desc_pca = cv::TrackerKCF::GRAY;
params.desc_npca = cv::TrackerKCF::GRAY;
params.resize = false;

params.resize = true;
#if (((CV_VERSION_MAJOR == 3) && (CV_VERSION_MINOR >= 3)) || (CV_VERSION_MAJOR > 3))
m_tracker = cv::TrackerKCF::create(params);
#else
m_tracker = cv::TrackerKCF::createTracker(params);
//m_tracker = cv::Tracker::create("TLD");
#endif
cv::Rect2d lastRect(m_predictionRect.x, m_predictionRect.y, m_predictionRect.width, m_predictionRect.height);
m_tracker->init(prevFrame, lastRect);
}
Expand Down
6 changes: 4 additions & 2 deletions VideoExample.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ class MotionDetector : public VideoExample
///
bool InitTracker(cv::Mat grayFrame)
{
m_detector = std::make_unique<CDetector>(BackgroundSubtract::ALG_MOG, m_useLocalTracking, grayFrame);
m_minObjWidth = grayFrame.cols / 50;

m_detector = std::make_unique<CDetector>(BackgroundSubtract::ALG_MOG2, m_useLocalTracking, grayFrame);
m_detector->SetMinObjectSize(cv::Size(m_minObjWidth, m_minObjWidth));

m_tracker = std::make_unique<CTracker>(m_useLocalTracking,
Expand Down Expand Up @@ -257,7 +259,7 @@ class MotionDetector : public VideoExample
for (const auto& track : m_tracker->tracks)
{
if (track->IsRobust(m_fps / 2, // Minimal trajectory size
0.8f, // Minimal ratio raw_trajectory_points / trajectory_lenght
0.6f, // Minimal ratio raw_trajectory_points / trajectory_lenght
cv::Size2f(0.1f, 8.0f)) // Min and max ratio: width / height
)
{
Expand Down

0 comments on commit 56fc3a5

Please sign in to comment.