opencv Hog Demo
生活随笔
收集整理的這篇文章主要介紹了
opencv Hog Demo
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
需注意此代碼要在Release x64之下運(yùn)行?
#include <iostream> #include <stdexcept> #include <opencv2/objdetect.hpp> #include <opencv2/highgui.hpp> #include <opencv2/imgproc.hpp> #include <opencv2/imgcodecs.hpp> //Release x64 版本 using namespace cv; using namespace std; int main() {Mat src = imread("pic4.png");;if (!src.data){cout << "圖片未找到!" << endl;return -1;}imshow("input title", src);/*resize(src, src, Size(64, 128));HOGDescriptor detector = HOGDescriptor(Size(64, 128), Size(16, 16), Size(8, 8), Size(8, 8), 9);vector<float>descriptions;vector<Point>points;detector.compute(src, descriptions, Size(0, 0), Size(0, 0), points);cout << "the number of HOG descriptions:" <<descriptions.size()<< endl;*/HOGDescriptor hog = HOGDescriptor();hog.setSVMDetector(hog.getDefaultPeopleDetector());//opencv中已經(jīng)有訓(xùn)練好的行人檢測(cè)數(shù)據(jù)集Mat resultImg = src.clone();vector<Rect>foundlocations;hog.detectMultiScale(src, foundlocations, 0, Size(3, 3), Size(32, 32), 1.05, 2);//根據(jù)圖片需要隨時(shí)調(diào)整Size()大小for (size_t i = 0; i < foundlocations.size(); i++){//cout << "foundlocation:" << foundlocations[i] << endl;rectangle(resultImg, foundlocations[i], Scalar(0, 0, 255), 2, 8, 0);}imshow("HOG SVM demo", resultImg);waitKey(0);return 0; }運(yùn)行結(jié)果:
我的總結(jié):
之前復(fù)制網(wǎng)上代碼一致不行,執(zhí)行到?hog.setSVMDetector(hog.getDefaultPeopleDetector())就出錯(cuò)。大概就是Debug Error之類的。曾經(jīng)懷疑是不是我的opencv3版本中沒有這個(gè),于是找到opencv中的samples下peopledetect.cpp案例。那就說(shuō)明此opencv版本是支持hog的。于是接著找問(wèn)題在哪里。什么改變平臺(tái)之類的都試過(guò)一遍,還是不行。最后想起可能是引入的包不對(duì)?于是就把sample中peopledetect.cpp中的所有include拷貝過(guò)來(lái)就ok了。
總結(jié)
以上是生活随笔為你收集整理的opencv Hog Demo的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 佳能g2800清零软件天空_可能是史上最
- 下一篇: 计算机水平考试改革,浅析全国计算机等级考