projects
/
experiments
/
opencv_trail_effect.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Port to OpenCV4 and use the C++ API for everything
[experiments/opencv_trail_effect.git]
/
Segmentation.hpp
diff --git
a/Segmentation.hpp
b/Segmentation.hpp
index
bd9b4c9
..
9ad76d7
100644
(file)
--- a/
Segmentation.hpp
+++ b/
Segmentation.hpp
@@
-51,8
+51,8
@@
public:
cv::Mat gray_frame;
cv::Mat frame_mask;
cv::Mat gray_frame;
cv::Mat frame_mask;
- cvtColor(frame, gray_frame,
CV
_RGB2GRAY);
- cv::threshold(gray_frame, frame_mask, threshold, 255,
CV_
THRESH_TOZERO);
+ cvtColor(frame, gray_frame,
cv::COLOR
_RGB2GRAY);
+ cv::threshold(gray_frame, frame_mask, threshold, 255,
cv::
THRESH_TOZERO);
return frame_mask;
}
return frame_mask;
}
@@
-63,17
+63,17
@@
public:
* http://docs.opencv.org/master/d1/dc5/tutorial_background_subtraction.html
*/
* http://docs.opencv.org/master/d1/dc5/tutorial_background_subtraction.html
*/
-class MOG2Segmentation : public Segmentation
, public cv::BackgroundSubtractorMOG2
{
+class MOG2Segmentation : public Segmentation {
public:
public:
- MOG2Segmentation(cv::VideoCapture& inputVideo, int learning_frames) :
- cv::BackgroundSubtractorMOG2()
+ MOG2Segmentation(cv::VideoCapture& inputVideo, int learning_frames)
{
cv::Mat background;
cv::Mat foreground_mask;
{
cv::Mat background;
cv::Mat foreground_mask;
+ pMOG2 = cv::createBackgroundSubtractorMOG2();
for (int i = 0; i < learning_frames; i++) {
inputVideo >> background;
for (int i = 0; i < learning_frames; i++) {
inputVideo >> background;
-
this->operator()
(background, foreground_mask);
+
pMOG2->apply
(background, foreground_mask);
}
}
}
}
@@
-81,14
+81,22
@@
public:
{
cv::Mat foreground_mask;
{
cv::Mat foreground_mask;
-
this->operator()
(frame, foreground_mask, 0);
+
pMOG2->apply
(frame, foreground_mask, 0);
cv::erode(foreground_mask, foreground_mask, cv::Mat());
cv::dilate(foreground_mask, foreground_mask, cv::Mat());
cv::erode(foreground_mask, foreground_mask, cv::Mat());
cv::dilate(foreground_mask, foreground_mask, cv::Mat());
- cv::threshold(foreground_mask, foreground_mask, 0, 255,
CV_
THRESH_OTSU);
+ cv::threshold(foreground_mask, foreground_mask, 0, 255,
cv::
THRESH_OTSU);
cv::medianBlur(foreground_mask, foreground_mask, 9);
return foreground_mask;
}
cv::medianBlur(foreground_mask, foreground_mask, 9);
return foreground_mask;
}
+
+ void getBackgroundImage(const cv::Mat& background)
+ {
+ pMOG2->getBackgroundImage(background);
+ }
+
+private:
+ cv::Ptr<cv::BackgroundSubtractor> pMOG2;
};
#endif // SEGMENTATION_HPP
};
#endif // SEGMENTATION_HPP