From 23b1ca3ddc44f95c1ec4b362c5295b505703231a Mon Sep 17 00:00:00 2001 From: Moskalenko Date: Wed, 19 Aug 2015 14:30:49 +0300 Subject: [PATCH 1/2] Moskalenko_NOT_READY --- apps/detector_Moskalenko.cpp | 78 ++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 apps/detector_Moskalenko.cpp diff --git a/apps/detector_Moskalenko.cpp b/apps/detector_Moskalenko.cpp new file mode 100644 index 0000000..27c1021 --- /dev/null +++ b/apps/detector_Moskalenko.cpp @@ -0,0 +1,78 @@ +#include +#include +#include + +#include "opencv2/core/core.hpp" +#include "opencv2/highgui/highgui.hpp" +#include "opencv2/objdetect/objdetect.hpp" + +using namespace std; +using namespace cv; + +const char* params = + "{ h | help | false | print usage }" + "{ | detector | | XML file with a cascade detector }" + "{ | image | | image to detect objects on }" + "{ | video | | video file to detect on }" + "{ | camera | false | whether to detect on video stream from camera }"; + + +void drawDetections(const vector& detections, + const Scalar& color, + Mat& image) +{ + for (size_t i = 0; i < detections.size(); ++i) + { + rectangle(image, detections[i], color, 2); + } +} + +const Scalar red(0, 0, 255); +const Scalar green(0, 255, 0); +const Scalar blue(255, 0, 0); +const Scalar colors[] = {red, green, blue}; + +int main(int argc, char** argv) +{ + // Parse command line arguments. + CommandLineParser parser(argc, argv, params); + // If help flag is present, print help message and exit. + if (parser.get("help")) + { + parser.printParams(); + return 0; + } + + string detector_file = parser.get("detector"); + CV_Assert(!detector_file.empty()); + string image_file = parser.get("image"); + string video_file = parser.get("video"); + bool use_camera = parser.get("camera"); + + // TODO: Load detector. + + if (!image_file.empty()) + { + // TODO: Detect objects on image. + + } + else if (!video_file.empty()) + { + // TODO: Detect objects on every frame of a video. + + } + else if (use_camera) + { + // TODO: Detect objects on a live video stream from camera. + + } + else + { + cout << "Declare a source of images to detect on." << endl; + } + + return 0; +} + + + From 8baa61ddd167f817530ae4a1b130409c69c803bc Mon Sep 17 00:00:00 2001 From: Moskalenko Date: Wed, 19 Aug 2015 17:46:30 +0300 Subject: [PATCH 2/2] Detector_Moskalenko --- apps/detector_Moskalenko.cpp | 64 ++++++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 7 deletions(-) diff --git a/apps/detector_Moskalenko.cpp b/apps/detector_Moskalenko.cpp index 27c1021..26f21ef 100644 --- a/apps/detector_Moskalenko.cpp +++ b/apps/detector_Moskalenko.cpp @@ -27,6 +27,7 @@ void drawDetections(const vector& detections, } } +const Scalar white(255,255, 255); const Scalar red(0, 0, 255); const Scalar green(0, 255, 0); const Scalar blue(255, 0, 0); @@ -43,28 +44,77 @@ int main(int argc, char** argv) return 0; } + string detector_unn_str = "./unn_logo_cascade/cascade.xml"; + string detector_itseez_str = "./itseez_logo_w_caption_cascade/cascade.xml"; + string detector_opencv_str = "./opencv_logo_cascade/cascade.xml"; + string detector_file = parser.get("detector"); CV_Assert(!detector_file.empty()); string image_file = parser.get("image"); string video_file = parser.get("video"); bool use_camera = parser.get("camera"); - // TODO: Load detector. + cv::CascadeClassifier detector; + cv::CascadeClassifier detector_unn; + cv::CascadeClassifier detector_itseez; + cv::CascadeClassifier detector_opencv; + detector.load(detector_file); + detector_unn.load(detector_unn_str); + detector_itseez.load(detector_itseez_str); + detector_opencv.load(detector_opencv_str); if (!image_file.empty()) { - // TODO: Detect objects on image. - + Mat image; + image = cv::imread(image_file); + vector result; + detector.detectMultiScale(image,result); + drawDetections(result,red,image); + imshow("Image", image); + waitKey(0); } else if (!video_file.empty()) { - // TODO: Detect objects on every frame of a video. - + namedWindow("Video",1); + cv::VideoCapture cap(video_file); + CV_Assert(cap.isOpened()); + Mat image; + cap >> image; + while (cap.isOpened()) + { + cap >> image; + vector result; + detector.detectMultiScale(image,result); + drawDetections(result,red,image); + imshow("Video", image); + if(waitKey(30) >= 0) break; + }; } else if (use_camera) { - // TODO: Detect objects on a live video stream from camera. - + namedWindow("Video",1); + cv::VideoCapture cap = cv::VideoCapture(0); + cap.open(0); + Mat image; + cap >> image; + for(;;) + { + cap >> image; + vector result; + vector resultUnn; + vector resultOpencv; + vector resultItseez; + detector.detectMultiScale(image,result); + detector_unn.detectMultiScale(image,resultUnn); + detector_opencv.detectMultiScale(image,resultOpencv); + detector_itseez.detectMultiScale(image,resultItseez); + drawDetections(resultUnn,red,image); + drawDetections(resultOpencv,blue,image); + drawDetections(resultItseez,green,image); + drawDetections(result,white,image); + imshow("Video", image); + if(waitKey(30) >= 0) break; + }; } else {