fixing trailing whitespaces

This commit is contained in:
dbloisi 2013-09-01 20:59:27 +02:00
parent a34f7b7714
commit f0910466f9
3 changed files with 117 additions and 124 deletions

View File

@ -74,7 +74,7 @@ The results as well as the input data are shown on the screen.
<< "--------------------------------------------------------------------------" << endl << "--------------------------------------------------------------------------" << endl
<< "This program shows how to use background subtraction methods provided by " << endl << "This program shows how to use background subtraction methods provided by " << endl
<< " OpenCV. You can process both videos (-vid) and images (-img)." << endl << " OpenCV. You can process both videos (-vid) and images (-img)." << endl
<< endl << endl
<< "Usage:" << endl << "Usage:" << endl
<< "./bs {-vid <video filename>|-img <image filename>}" << endl << "./bs {-vid <video filename>|-img <image filename>}" << endl
<< "for example: ./bs -vid video.avi" << endl << "for example: ./bs -vid video.avi" << endl
@ -186,7 +186,7 @@ The results as well as the input data are shown on the screen.
string suffix = fn.substr(index2); string suffix = fn.substr(index2);
string frameNumberString = fn.substr(index+1, index2-index-1); string frameNumberString = fn.substr(index+1, index2-index-1);
istringstream iss(frameNumberString); istringstream iss(frameNumberString);
int frameNumber; int frameNumber = 0;
iss >> frameNumber; iss >> frameNumber;
rectangle(frame, cv::Point(10, 2), cv::Point(100,20), rectangle(frame, cv::Point(10, 2), cv::Point(100,20),
cv::Scalar(255,255,255), -1); cv::Scalar(255,255,255), -1);
@ -237,7 +237,7 @@ We discuss the main parts of the above code:
Ptr<BackgroundSubtractor> pMOG; //MOG Background subtractor Ptr<BackgroundSubtractor> pMOG; //MOG Background subtractor
Ptr<BackgroundSubtractor> pMOG2; //MOG2 Background subtractor Ptr<BackgroundSubtractor> pMOG2; //MOG2 Background subtractor
... ...
//create Background Subtractor objects //create Background Subtractor objects
pMOG = createBackgroundSubtractorMOG(); //MOG approach pMOG = createBackgroundSubtractorMOG(); //MOG approach
pMOG2 = createBackgroundSubtractorMOG2(); //MOG2 approach pMOG2 = createBackgroundSubtractorMOG2(); //MOG2 approach
@ -327,10 +327,7 @@ We discuss the main parts of the above code:
//update the path of the current frame //update the path of the current frame
fn.assign(nextFrameFilename); fn.assign(nextFrameFilename);
* Note that this example works only on image sequences in which the filename format is <n>.png, where n is the frame number (e.g., 7.png).
Note that:
* this example works only on image sequences in which the filename format is <n>.png, where n is the frame number (e.g., 7.png).
Results Results
======= =======
@ -389,6 +386,3 @@ References
* Background Models Challenge (BMC) website, `<http://bmc.univ-bpclermont.fr/>`_ * Background Models Challenge (BMC) website, `<http://bmc.univ-bpclermont.fr/>`_
* Antoine Vacavant, Thierry Chateau, Alexis Wilhelm and Laurent Lequievre. A Benchmark Dataset for Foreground/Background Extraction. In ACCV 2012, Workshop: Background Models Challenge, LNCS 7728, 291-300. November 2012, Daejeon, Korea. * Antoine Vacavant, Thierry Chateau, Alexis Wilhelm and Laurent Lequievre. A Benchmark Dataset for Foreground/Background Extraction. In ACCV 2012, Workshop: Background Models Challenge, LNCS 7728, 291-300. November 2012, Daejeon, Korea.

View File

@ -14,7 +14,7 @@ Look here in order to find use on your video stream algoritms like: motion extra
=============== ====================================================== =============== ======================================================
|BgSub| **Title:** :ref:`Background_Subtraction` |BgSub| **Title:** :ref:`Background_Subtraction`
*Compatibility:* > OpenCV 2.4.5 *Compatibility:* > OpenCV 2.4.6
*Author:* |Author_DomenicoB| *Author:* |Author_DomenicoB|
@ -34,4 +34,3 @@ Look here in order to find use on your video stream algoritms like: motion extra
:hidden: :hidden:
../background_subtraction/background_subtraction ../background_subtraction/background_subtraction

View File

@ -31,17 +31,17 @@ void processImages(char* firstFrameFilename);
void help() void help()
{ {
cout cout
<< "--------------------------------------------------------------------------" << endl << "--------------------------------------------------------------------------" << endl
<< "This program shows how to use background subtraction methods provided by " << endl << "This program shows how to use background subtraction methods provided by " << endl
<< " OpenCV. You can process both videos (-vid) and images (-img)." << endl << " OpenCV. You can process both videos (-vid) and images (-img)." << endl
<< endl << endl
<< "Usage:" << endl << "Usage:" << endl
<< "./bs {-vid <video filename>|-img <image filename>}" << endl << "./bs {-vid <video filename>|-img <image filename>}" << endl
<< "for example: ./bs -vid video.avi" << endl << "for example: ./bs -vid video.avi" << endl
<< "or: ./bs -img /data/images/1.png" << endl << "or: ./bs -img /data/images/1.png" << endl
<< "--------------------------------------------------------------------------" << endl << "--------------------------------------------------------------------------" << endl
<< endl; << endl;
} }
/** /**
@ -49,38 +49,38 @@ void help()
*/ */
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
//print help information //print help information
help(); help();
//check for the input parameter correctness //check for the input parameter correctness
if(argc != 3) { if(argc != 3) {
cerr <<"Incorret input list" << endl; cerr <<"Incorret input list" << endl;
cerr <<"exiting..." << endl; cerr <<"exiting..." << endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
//create GUI windows //create GUI windows
namedWindow("Frame"); namedWindow("Frame");
namedWindow("FG Mask MOG"); namedWindow("FG Mask MOG");
namedWindow("FG Mask MOG 2"); namedWindow("FG Mask MOG 2");
//create Background Subtractor objects //create Background Subtractor objects
pMOG = createBackgroundSubtractorMOG(); //MOG approach pMOG = createBackgroundSubtractorMOG(); //MOG approach
pMOG2 = createBackgroundSubtractorMOG2(); //MOG2 approach pMOG2 = createBackgroundSubtractorMOG2(); //MOG2 approach
if(strcmp(argv[1], "-vid") == 0) { if(strcmp(argv[1], "-vid") == 0) {
//input data coming from a video //input data coming from a video
processVideo(argv[2]); processVideo(argv[2]);
} }
else if(strcmp(argv[1], "-img") == 0) { else if(strcmp(argv[1], "-img") == 0) {
//input data coming from a sequence of images //input data coming from a sequence of images
processImages(argv[2]); processImages(argv[2]);
} }
else { else {
//error in reading input parameters //error in reading input parameters
cerr <<"Please, check the input parameters." << endl; cerr <<"Please, check the input parameters." << endl;
cerr <<"Exiting..." << endl; cerr <<"Exiting..." << endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
//destroy GUI windows //destroy GUI windows
destroyAllWindows(); destroyAllWindows();
@ -94,35 +94,35 @@ void processVideo(char* videoFilename) {
//create the capture object //create the capture object
VideoCapture capture(videoFilename); VideoCapture capture(videoFilename);
if(!capture.isOpened()){ if(!capture.isOpened()){
//error in opening the video input //error in opening the video input
cerr << "Unable to open video file: " << videoFilename << endl; cerr << "Unable to open video file: " << videoFilename << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
//read input data. ESC or 'q' for quitting //read input data. ESC or 'q' for quitting
while( (char)keyboard != 'q' && (char)keyboard != 27 ){ while( (char)keyboard != 'q' && (char)keyboard != 27 ){
//read the current frame //read the current frame
if(!capture.read(frame)) { if(!capture.read(frame)) {
cerr << "Unable to read next frame." << endl; cerr << "Unable to read next frame." << endl;
cerr << "Exiting..." << endl; cerr << "Exiting..." << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
//update the background model //update the background model
pMOG->apply(frame, fgMaskMOG); pMOG->apply(frame, fgMaskMOG);
pMOG2->apply(frame, fgMaskMOG2); pMOG2->apply(frame, fgMaskMOG2);
//get the frame number and write it on the current frame //get the frame number and write it on the current frame
stringstream ss; stringstream ss;
rectangle(frame, cv::Point(10, 2), cv::Point(100,20), rectangle(frame, cv::Point(10, 2), cv::Point(100,20),
cv::Scalar(255,255,255), -1); cv::Scalar(255,255,255), -1);
ss << capture.get(CAP_PROP_POS_FRAMES); ss << capture.get(CAP_PROP_POS_FRAMES);
string frameNumberString = ss.str(); string frameNumberString = ss.str();
putText(frame, frameNumberString.c_str(), cv::Point(15, 15), putText(frame, frameNumberString.c_str(), cv::Point(15, 15),
FONT_HERSHEY_SIMPLEX, 0.5 , cv::Scalar(0,0,0)); FONT_HERSHEY_SIMPLEX, 0.5 , cv::Scalar(0,0,0));
//show the current frame and the fg masks //show the current frame and the fg masks
imshow("Frame", frame); imshow("Frame", frame);
imshow("FG Mask MOG", fgMaskMOG); imshow("FG Mask MOG", fgMaskMOG);
imshow("FG Mask MOG 2", fgMaskMOG2); imshow("FG Mask MOG 2", fgMaskMOG2);
//get the input from the keyboard //get the input from the keyboard
keyboard = waitKey( 30 ); keyboard = waitKey( 30 );
} }
//delete capture object //delete capture object
capture.release(); capture.release();
@ -135,52 +135,52 @@ void processImages(char* fistFrameFilename) {
//read the first file of the sequence //read the first file of the sequence
frame = imread(fistFrameFilename); frame = imread(fistFrameFilename);
if(!frame.data){ if(!frame.data){
//error in opening the first image //error in opening the first image
cerr << "Unable to open first image frame: " << fistFrameFilename << endl; cerr << "Unable to open first image frame: " << fistFrameFilename << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
//current image filename //current image filename
string fn(fistFrameFilename); string fn(fistFrameFilename);
//read input data. ESC or 'q' for quitting //read input data. ESC or 'q' for quitting
while( (char)keyboard != 'q' && (char)keyboard != 27 ){ while( (char)keyboard != 'q' && (char)keyboard != 27 ){
//update the background model //update the background model
pMOG->apply(frame, fgMaskMOG); pMOG->apply(frame, fgMaskMOG);
pMOG2->apply(frame, fgMaskMOG2); pMOG2->apply(frame, fgMaskMOG2);
//get the frame number and write it on the current frame //get the frame number and write it on the current frame
size_t index = fn.find_last_of("/"); size_t index = fn.find_last_of("/");
if(index == string::npos) { if(index == string::npos) {
index = fn.find_last_of("\\"); index = fn.find_last_of("\\");
} }
size_t index2 = fn.find_last_of("."); size_t index2 = fn.find_last_of(".");
string prefix = fn.substr(0,index+1); string prefix = fn.substr(0,index+1);
string suffix = fn.substr(index2); string suffix = fn.substr(index2);
string frameNumberString = fn.substr(index+1, index2-index-1); string frameNumberString = fn.substr(index+1, index2-index-1);
istringstream iss(frameNumberString); istringstream iss(frameNumberString);
int frameNumber; int frameNumber = 0;
iss >> frameNumber; iss >> frameNumber;
rectangle(frame, cv::Point(10, 2), cv::Point(100,20), rectangle(frame, cv::Point(10, 2), cv::Point(100,20),
cv::Scalar(255,255,255), -1); cv::Scalar(255,255,255), -1);
putText(frame, frameNumberString.c_str(), cv::Point(15, 15), putText(frame, frameNumberString.c_str(), cv::Point(15, 15),
FONT_HERSHEY_SIMPLEX, 0.5 , cv::Scalar(0,0,0)); FONT_HERSHEY_SIMPLEX, 0.5 , cv::Scalar(0,0,0));
//show the current frame and the fg masks //show the current frame and the fg masks
imshow("Frame", frame); imshow("Frame", frame);
imshow("FG Mask MOG", fgMaskMOG); imshow("FG Mask MOG", fgMaskMOG);
imshow("FG Mask MOG 2", fgMaskMOG2); imshow("FG Mask MOG 2", fgMaskMOG2);
//get the input from the keyboard //get the input from the keyboard
keyboard = waitKey( 30 ); keyboard = waitKey( 30 );
//search for the next image in the sequence //search for the next image in the sequence
ostringstream oss; ostringstream oss;
oss << (frameNumber + 1); oss << (frameNumber + 1);
string nextFrameNumberString = oss.str(); string nextFrameNumberString = oss.str();
string nextFrameFilename = prefix + nextFrameNumberString + suffix; string nextFrameFilename = prefix + nextFrameNumberString + suffix;
//read the next frame //read the next frame
frame = imread(nextFrameFilename); frame = imread(nextFrameFilename);
if(!frame.data){ if(!frame.data){
//error in opening the next image in the sequence //error in opening the next image in the sequence
cerr << "Unable to open image frame: " << nextFrameFilename << endl; cerr << "Unable to open image frame: " << nextFrameFilename << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
//update the path of the current frame //update the path of the current frame
fn.assign(nextFrameFilename); fn.assign(nextFrameFilename);
} }
} }