diff --git a/examples/Demo.cpp b/examples/Demo.cpp index 2bfec63b297acb1f1ec796f5349a9137d0674512..3b4c0bfdfc0122e63877bc8387a701ae5d395562 100644 --- a/examples/Demo.cpp +++ b/examples/Demo.cpp @@ -11,82 +11,82 @@ #define CV_CAP_PROP_FRAME_COUNT cv::CAP_PROP_FRAME_COUNT #endif -int main(int argc, char **argv) +int main(int argc, char** argv) { - std::cout << "Using OpenCV " << CV_MAJOR_VERSION << "." << CV_MINOR_VERSION << "." << CV_SUBMINOR_VERSION << std::endl; - - cv::VideoCapture capture; - - if (argc > 1) - { - std::cout << "Openning: " << argv[1] << std::endl; - capture.open(argv[1]); - } - else - capture.open(0); - - if (!capture.isOpened()) - { - std::cerr << "Cannot initialize video!" << std::endl; - return -1; - } - - /* Background Subtraction Methods */ - auto algorithmsName = BGS_Factory::Instance()->GetRegisteredAlgorithmsName(); - - std::cout << "List of available algorithms:" << std::endl; - std::copy(algorithmsName.begin(), algorithmsName.end(), std::ostream_iterator<std::string>(std::cout, "\n")); - - for (const std::string& algorithmName : algorithmsName) - { - std::cout << "Running " << algorithmName << std::endl; - auto bgs = BGS_Factory::Instance()->Create(algorithmName); - - cv::Mat img_input; - - capture.set(CV_CAP_PROP_POS_FRAMES, 0); // Set index to 0 (start frame) - auto frame_counter = 0; - std::cout << "Press 's' to stop:" << std::endl; - auto key = 0; - while (key != 's') - { - // Capture frame-by-frame - capture >> img_input; - frame_counter += 1; - - if (img_input.empty()) break; - - cv::resize(img_input, img_input, cv::Size(380, 240), 0, 0, CV_INTER_LINEAR); - cv::imshow("input", img_input); - - cv::Mat img_mask; - cv::Mat img_bkgmodel; - try - { - bgs->process(img_input, img_mask, img_bkgmodel); // by default, it shows automatically the foreground mask image - - //if(!img_mask.empty()) - // cv::imshow("Foreground", img_mask); - // do something - } - catch (std::exception& e) - { - std::cout << "Exception occurred" << std::endl; - std::cout << e.what() << std::endl; - } - - key = cv::waitKey(33); - } - - std::cout << "Press 'q' to exit, or anything else to move to the next algorithm:" << std::endl; - key = cv::waitKey(0); - if (key == 'q') - break; - - cv::destroyAllWindows(); - } - - capture.release(); - - return 0; + std::cout << "Using OpenCV " << CV_MAJOR_VERSION << "." << CV_MINOR_VERSION << "." << CV_SUBMINOR_VERSION << std::endl; + + cv::VideoCapture capture; + + if (argc > 1) + { + std::cout << "Openning: " << argv[1] << std::endl; + capture.open(argv[1]); + } + else + capture.open(0); + + if (!capture.isOpened()) + { + std::cerr << "Cannot initialize video!" << std::endl; + return -1; + } + + /* Background Subtraction Methods */ + auto algorithmsName = BGS_Factory::Instance()->GetRegisteredAlgorithmsName(); + + std::cout << "List of available algorithms:" << std::endl; + std::copy(algorithmsName.begin(), algorithmsName.end(), std::ostream_iterator<std::string>(std::cout, "\n")); + + for (const std::string& algorithmName : algorithmsName) + { + std::cout << "Running " << algorithmName << std::endl; + auto bgs = BGS_Factory::Instance()->Create(algorithmName); + + cv::Mat img_input; + + capture.set(CV_CAP_PROP_POS_FRAMES, 0); // Set index to 0 (start frame) + auto frame_counter = 0; + std::cout << "Press 's' to stop:" << std::endl; + auto key = 0; + while (key != 's') + { + // Capture frame-by-frame + capture >> img_input; + frame_counter += 1; + + if (img_input.empty()) break; + + cv::resize(img_input, img_input, cv::Size(380, 240), 0, 0, CV_INTER_LINEAR); + cv::imshow("input", img_input); + + cv::Mat img_mask; + cv::Mat img_bkgmodel; + try + { + bgs->process(img_input, img_mask, img_bkgmodel); // by default, it shows automatically the foreground mask image + + //if(!img_mask.empty()) + // cv::imshow("Foreground", img_mask); + // do something + } + catch (std::exception& e) + { + std::cout << "Exception occurred" << std::endl; + std::cout << e.what() << std::endl; + } + + key = cv::waitKey(33); + } + + std::cout << "Press 'q' to exit, or anything else to move to the next algorithm:" << std::endl; + key = cv::waitKey(0); + if (key == 'q') + break; + + cv::destroyAllWindows(); + } + + capture.release(); + + return 0; } diff --git a/examples/Demo2.cpp b/examples/Demo2.cpp index 197d4e073658591f7f576c88197c31f788ed9e8c..43f19917bf0ab4c7afae3653e90aa5164a048c12 100644 --- a/examples/Demo2.cpp +++ b/examples/Demo2.cpp @@ -10,72 +10,72 @@ #define CV_LOAD_IMAGE_COLOR cv::IMREAD_COLOR #endif -int main(int argc, char **argv) +int main(int argc, char** argv) { - std::cout << "Using OpenCV " << CV_MAJOR_VERSION << "." << CV_MINOR_VERSION << "." << CV_SUBMINOR_VERSION << std::endl; - - std::string baseDir = "./dataset/frames"; - if (argc > 1) - baseDir = argv[1]; - std::cout << "Openning: " << baseDir << std::endl; - - /* Background Subtraction Methods */ - auto algorithmsName = BGS_Factory::Instance()->GetRegisteredAlgorithmsName(); - - std::cout << "List of available algorithms (" << algorithmsName.size() << "):" << std::endl; - std::copy(algorithmsName.begin(), algorithmsName.end(), std::ostream_iterator<std::string>(std::cout, "\n")); - - for (const std::string& algorithmName : algorithmsName) - { - std::cout << "Running " << algorithmName << std::endl; - auto bgs = BGS_Factory::Instance()->Create(algorithmName); - - auto frame_counter = 0; - std::cout << "Press 's' to stop:" << std::endl; - auto key = 0; - while (key != 's') - { - // Capture frame-by-frame - frame_counter++; - std::stringstream ss; - ss << frame_counter; - auto fileName = baseDir + "/" + ss.str() + ".png"; - // std::cout << "reading " << fileName << std::endl; - - auto img_input = cv::imread(fileName, CV_LOAD_IMAGE_COLOR); - - if (img_input.empty()) - break; - - cv::imshow("input", img_input); - - cv::Mat img_mask; - cv::Mat img_bkgmodel; - try - { - bgs->process(img_input, img_mask, img_bkgmodel); // by default, it shows automatically the foreground mask image - - //if(!img_mask.empty()) - // cv::imshow("Foreground", img_mask); - // do something - } - catch (std::exception& e) - { - std::cout << "Exception occurred" << std::endl; - std::cout << e.what() << std::endl; - break; - } - - key = cv::waitKey(33); - } - - std::cout << "Press 'q' to exit, or anything else to move to the next algorithm:" << std::endl; - key = cv::waitKey(0); - if (key == 'q') - break; - - cv::destroyAllWindows(); - } - - return 0; + std::cout << "Using OpenCV " << CV_MAJOR_VERSION << "." << CV_MINOR_VERSION << "." << CV_SUBMINOR_VERSION << std::endl; + + std::string baseDir = "./dataset/frames"; + if (argc > 1) + baseDir = argv[1]; + std::cout << "Openning: " << baseDir << std::endl; + + /* Background Subtraction Methods */ + auto algorithmsName = BGS_Factory::Instance()->GetRegisteredAlgorithmsName(); + + std::cout << "List of available algorithms (" << algorithmsName.size() << "):" << std::endl; + std::copy(algorithmsName.begin(), algorithmsName.end(), std::ostream_iterator<std::string>(std::cout, "\n")); + + for (const std::string& algorithmName : algorithmsName) + { + std::cout << "Running " << algorithmName << std::endl; + auto bgs = BGS_Factory::Instance()->Create(algorithmName); + + auto frame_counter = 0; + std::cout << "Press 's' to stop:" << std::endl; + auto key = 0; + while (key != 's') + { + // Capture frame-by-frame + frame_counter++; + std::stringstream ss; + ss << frame_counter; + auto fileName = baseDir + "/" + ss.str() + ".png"; + // std::cout << "reading " << fileName << std::endl; + + auto img_input = cv::imread(fileName, CV_LOAD_IMAGE_COLOR); + + if (img_input.empty()) + break; + + cv::imshow("input", img_input); + + cv::Mat img_mask; + cv::Mat img_bkgmodel; + try + { + bgs->process(img_input, img_mask, img_bkgmodel); // by default, it shows automatically the foreground mask image + + //if(!img_mask.empty()) + // cv::imshow("Foreground", img_mask); + // do something + } + catch (std::exception& e) + { + std::cout << "Exception occurred" << std::endl; + std::cout << e.what() << std::endl; + break; + } + + key = cv::waitKey(33); + } + + std::cout << "Press 'q' to exit, or anything else to move to the next algorithm:" << std::endl; + key = cv::waitKey(0); + if (key == 'q') + break; + + cv::destroyAllWindows(); + } + + return 0; }