#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 | | 列印幫助資訊 }"
"{ camera c | 0 | 從攝像頭捕獲影片(裝置索引從 0 開始)}"
"{ video v | | 使用影片作為輸入 }";
int main(
int argc,
char** argv)
{
parser.about("此示例演示了 HoG 描述符的使用。");
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 << "無法開啟影片流:'" << (file.empty() ? "<camera>" : file) << "'" << endl;
return 2;
}
cout << "按 'q' 或 <ESC> 退出。" << endl;
cout << "按 <空格鍵> 在 Default 和 Daimler 檢測器之間切換" << endl;
Detector detector;
for (;;)
{
cap >> frame;
if (frame.empty())
{
cout << "讀取完成:空幀" << endl;
break;
}
vector<Rect> found = detector.detect(frame);
{
ostringstream buf;
buf << "模式: " << 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);
}
if (key == 27 || key == 'q')
{
cout << "已請求退出" << endl;
break;
}
else if (key == ' ')
{
detector.toggleMode();
}
}
return 0;
}
如果陣列沒有元素,則返回 true。
int64_t int64
2D 矩形的模板類。
定義 types.hpp:444
Point_< _Tp > tl() const
左上角
_Tp x
左上角的 x 座標
定義 types.hpp:487
_Tp y
左上角的 y 座標
定義 types.hpp:488
_Tp width
矩形的寬度
定義 types.hpp:489
_Tp height
矩形的高度
定義 types.hpp:490
Point_< _Tp > br() const
右下角
用於指定影像或矩形大小的模板類。
Definition types.hpp:335
用於從影片檔案、影像序列或攝像頭捕獲影片的類。
Definition videoio.hpp:772
virtual bool open(const String &filename, int apiPreference=CAP_ANY)
開啟影片檔案或捕獲裝置或 IP 影片流以進行影片捕獲。
virtual bool isOpened() const
如果影片捕獲已初始化,則返回 true。
cv::getTickCount
int64 getTickCount()
int cvRound(double value)
將浮點數舍入為最接近的整數。
Definition fast_math.hpp:200
void imshow(const String &winname, InputArray mat)
在指定視窗中顯示影像。
int waitKey(int delay=0)
等待按鍵按下。
void rectangle(InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
繪製一個簡單、粗或填充的矩形。
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)
繪製文字字串。
int main(int argc, char *argv[])
定義 highgui_qt.cpp:3
HOG(定向梯度直方圖)描述符和物件檢測器的實現。
定義 objdetect.hpp:403
virtual void setSVMDetector(InputArray svmdetector)
設定線性 SVM 分類器的係數。
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
檢測輸入影像中不同大小的物件。檢測到的物件作為列表返回...