我使用 OpenCV 3.0.0 和 Visual Studio 2012。我发现这个程序可以检测人员并对他们进行计数并确定他们的运动方向。但它很慢。您知道如何加快速度吗?
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main (int argc, const char * argv[])
{
VideoCapture cap("C:/Users/John/Downloads/Video/Cam.avi");
cap.set(CV_CAP_PROP_FRAME_WIDTH, 100);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, 110);
if (!cap.isOpened())
return -1;
Mat img;
HOGDescriptor hog;
hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());
namedWindow("video capture", CV_WINDOW_AUTOSIZE);
while (true)
{
cap >> img;
if (!img.data)
continue;
vector<Rect> found, found_filtered;
hog.detectMultiScale(img, found, 0, Size(8,8), Size(32,32), 1.05, 2);
size_t i, j;
for (i=0; i<found.size(); i++)
{
Rect r = found[i];
for (j=0; j<found.size(); j++)
if (j!=i && (r & found[j])==r)
break;
if (j==found.size())
found_filtered.push_back(r);
}
for (i=0; i<found_filtered.size(); i++)
{
Rect r = found_filtered[i];
r.x += cvRound(r.width*0.1);
r.width = cvRound(r.width*0.8);
r.y += cvRound(r.height*0.06);
r.height = cvRound(r.height*0.9);
rectangle(img, r.tl(), r.br(), cv::Scalar(0,255,0), 2);
}
imshow("video capture", img);
if (waitKey(33) >= 0)
break;
}
return 0;
}
最佳答案
如果有 cuda gpu,请尝试使用相同代码的 gpu 版本
据此
http://opencv.org/platforms/cuda.html
行人检测速度提高 8 倍
https://github.com/Itseez/opencv/blob/master/samples/gpu/hog.cpp
关于c++ - 加速人员检测程序,使用 OpenCV 3.0 编写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35264008/