我用“OpenCV”来处理C++人群检测代码,这需要2帧,并减去它们。然后将结果与阈值进行比较。
这是我第一次为C++处理“C++”,而且我没有多少关于它的信息。
这些是守则的步骤:
c++代码:
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main (int argc, const char * argv[])
{
//first frame.
Mat current_frame = imread("image1.jpg",CV_LOAD_IMAGE_GRAYSCALE);
//secunde frame.
Mat previous_frame = imread("image2.jpg",CV_LOAD_IMAGE_GRAYSCALE);
//Minus the current frame from the previous_frame and store the result.
Mat result = current_frame-previous_frame;
//compare the difference with threshold, if the deference <70 -> there is crowd.
//if it is > 70 there is no crowd
int threshold= cv::threshold(result,result,0,70,CV_THRESH_BINARY);
if (threshold==0) {
cout<< "crowd detected \n";
}
else {
cout<<" no crowd detected \n ";
}
}的问题是:阈值总是为零!输出总是:即使没有人群,也会检测到人群。
我们不关心输出图像,因为我们不会使用它,我们只想知道阈值的最后一个值。
我的目的是了解两个帧之间的差异。我想比较一下与阈值的差异,以检测特定地点的人群。
我希望你们中的一个能帮我
谢谢
发布于 2013-11-19 22:05:10
在使用门限函数时存在一些缺陷
你可能想要的是:
cv::threshold(result,result,70,1, CV_THRESH_BINARY); // same as : result = result>70;
int on_pixels = countNonZero(result);
// or:
int on_pixels = sum(result)[0];sidenote:如果你真的想发现人群,你必须付出更多的汗水。只是不同的框架是容易出错的照明变化,也有鸟类,汽车和交通灯
https://stackoverflow.com/questions/20082797
复制相似问题