#include <iostream>
#include <iomanip>
class Detector
{
enum Mode { Default, Daimler } m;
public:
Detector() : m(Default), hog(), hog_d(
Size(48, 96),
Size(16, 16),
Size(8, 8),
Size(8, 8), 9)
{
}
void toggleMode() { m = (m == Default ? Daimler : Default); }
string modeName() const { return (m == Default ? "Default" : "Daimler"); }
{
vector<Rect> found;
if (m == Default)
else if (m == Daimler)
return found;
}
void adjustRect(
Rect & r)
const
{
}
};
static const string keys = "{ help h | | print help message }"
"{ camera c | 0 | capture video from camera (device index starting from 0) }"
"{ video v | | use video as input }";
int main(
int argc,
char** argv)
{
parser.about("This sample demonstrates the use of the HoG descriptor.");
if (parser.has("help"))
{
parser.printMessage();
return 0;
}
int camera = parser.get<int>("camera");
string file = parser.get<string>("video");
if (!parser.check())
{
parser.printErrors();
return 1;
}
if (file.empty())
else
{
file = samples::findFileOrKeep(file);
}
{
cout << "Can not open video stream: '" << (file.empty() ? "<camera>" : file) << "'" << endl;
return 2;
}
cout << "Press 'q' or <ESC> to quit." << endl;
cout << "Press <space> to toggle between Default and Daimler detector" << endl;
Detector detector;
for (;;)
{
cap >> frame;
if (frame.empty())
{
cout << "Finished reading: empty frame" << endl;
break;
}
vector<Rect> found = detector.detect(frame);
{
ostringstream buf;
buf << "Mode: " << detector.modeName() << " ||| "
putText(frame, buf.str(),
Point(10, 30), FONT_HERSHEY_PLAIN, 2.0,
Scalar(0, 0, 255), 2, LINE_AA);
}
for (vector<Rect>::iterator i = found.begin(); i != found.end(); ++i)
{
detector.adjustRect(r);
}
imshow(
"People detector", frame);
if (key == 27 || key == 'q')
{
cout << "Exit requested" << endl;
break;
}
else if (key == ' ')
{
detector.toggleMode();
}
}
return 0;
}
Designed for command line parsing.
Definition utility.hpp:820
n-dimensional dense array class
Definition mat.hpp:812
Template class for 2D rectangles.
Definition types.hpp:444
Point_< _Tp > tl() const
the top-left corner
_Tp x
x coordinate of the top-left corner
Definition types.hpp:480
_Tp y
y coordinate of the top-left corner
Definition types.hpp:481
_Tp width
width of the rectangle
Definition types.hpp:482
_Tp height
height of the rectangle
Definition types.hpp:483
Point_< _Tp > br() const
the bottom-right corner
Template class for specifying the size of an image or rectangle.
Definition types.hpp:335
Class for video capturing from video files, image sequences or cameras.
Definition videoio.hpp:731
virtual bool open(const String &filename, int apiPreference=CAP_ANY)
Opens a video file or a capturing device or an IP video stream for video capturing.
virtual bool isOpened() const
Returns true if video capturing has been initialized already.
int64_t int64
Definition interface.h:61
int cvRound(double value)
Rounds floating-point number to the nearest integer.
Definition fast_math.hpp:200
double getTickFrequency()
Returns the number of ticks per second.
int64 getTickCount()
Returns the number of ticks.
void imshow(const String &winname, InputArray mat)
Displays an image in the specified window.
int waitKey(int delay=0)
Waits for a pressed key.
void rectangle(InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
Draws a simple, thick, or filled up-right rectangle.
void putText(InputOutputArray img, const String &text, Point org, int fontFace, double fontScale, Scalar color, int thickness=1, int lineType=LINE_8, bool bottomLeftOrigin=false)
Draws a text string.
int main(int argc, char *argv[])
Definition highgui_qt.cpp:3
"black box" representation of the file storage associated with a file on disk.
Definition core.hpp:102
Implementation of HOG (Histogram of Oriented Gradients) descriptor and object detector.
Definition objdetect.hpp:403
virtual void setSVMDetector(InputArray svmdetector)
Sets coefficients for the linear SVM classifier.
virtual void detectMultiScale(InputArray img, std::vector< Rect > &foundLocations, std::vector< double > &foundWeights, double hitThreshold=0, Size winStride=Size(), Size padding=Size(), double scale=1.05, double groupThreshold=2.0, bool useMeanshiftGrouping=false) const
Detects objects of different sizes in the input image. The detected objects are returned as a list of...