#include "opencv2/imgcodecs.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/videoio.hpp"
#include <opencv2/highgui.hpp>
#include <opencv2/video.hpp>
#include <iostream>
#include <sstream>
using namespace cv;
using namespace std;
void processVideo(Ptr<BackgroundSubtractorKNN> pBackgroundKnn, string videoFilename)
{
cv::Mat frame,FGMask;
int keyboard=0;
VideoCapture capture(videoFilename);
if(!capture.isOpened())
exit(EXIT_FAILURE);
while( (char)keyboard != 'q' && (char)keyboard != 27 )
{
if(!capture.read(frame))
exit(EXIT_FAILURE);
cv::resize(frame, frame,cv::Size(), 0.2,0.2);
pBackgroundKnn->setHistory(200);
pBackgroundKnn->setDist2Threshold(600);
pBackgroundKnn->setShadowThreshold(0.5);
pBackgroundKnn->apply(frame, FGMask);
stringstream ss;
rectangle(frame, cv::Point(10, 2), cv::Point(100,20),
cv::Scalar(255,255,255), -1);
ss << capture.get(CAP_PROP_POS_FRAMES);
string frameNumberString = ss.str();
putText(frame, frameNumberString.c_str(), cv::Point(15, 15),
FONT_HERSHEY_SIMPLEX, 0.5 , cv::Scalar(0,0,0));
imshow("Frame", frame);
imshow("FGMask", FGMask);
keyboard = waitKey(30);
}
capture.release();
}
int main(int argc, char* argv[])
{
Ptr<BackgroundSubtractorKNN> pBackgroundKnn =
createBackgroundSubtractorKNN();
string inputPath = "..\\images\\car.avi";
processVideo( pBackgroundKnn, inputPath);
return 0;
}