i want to make outdoor system which count people standing in front of camera and ignore the tress like moving objects... i wrote code written below but its not working in my system having openCV 2.3.1 . can anyone tell me why and what changes should i make in it to run it successfully ...
#include "opencv2/video/tracking.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/video/background_segm.hpp"
#include "opencv2/features2d/features2d.hpp"
using namespace cv;
int main()
{
VideoCapture cap;
int thresh = 8 ;//
//cap.open(-1);//
cap.open("sidewalk.avi"); // Reads the video image
if( !cap.isOpened() ) //
{
puts("***Could not initialize capturing...***\n");
return 0;
}
namedWindow( "Capture ", CV_WINDOW_AUTOSIZE);
namedWindow( "Foreground ", CV_WINDOW_AUTOSIZE );
namedWindow( "Control Window", CV_WINDOW_AUTOSIZE );
createTrackbar("Threshold", "Control Window", &thresh, 100);
Mat frame,foreground,image;
BackgroundSubtractorMOG2 mog;
int fps=cap.get(CV_CAP_PROP_FPS);
if(fps<=0)
fps=10;
else
fps=1000/fps;
for(;;)
{
cap>>frame;
if(frame.empty())
break;
image=frame.clone();
mog(frame,foreground,-1);
threshold(foreground,foreground,double(thresh)*255/100.0,255,THRESH_BINARY);
medianBlur(foreground,foreground,9);
//erode(foreground,foreground,Mat());
//dilate(foreground,foreground,Mat());
//medianBlur(foreground,foreground,9);
//erode(foreground,foreground,Mat());
// Show on the display part
imshow( "Capture ",image );
// image.copyTo(foreground,foreground); // Try it and see what happens at one
imshow("Foreground ",foreground);
//
// BLOB DETECTOR
//
// set up the parameters (check the defaults in opencv's code in blobdetector.cpp)
cv::SimpleBlobDetector::Params params;
params.minDistBetweenBlobs = 50.0f;
params.filterByInertia = false;
params.filterByConvexity = false;
params.filterByColor = false;
params.filterByCircularity = false;
params.filterByArea = true;
params.minArea = 10.0f;
params.maxArea = 1000.0f;
// set up and create the detector using the parameters
cv::Ptr<cv::featuredetector> blob_detector = new cv::SimpleBlobDetector(params);
blob_detector->create("SimpleBlob");
// detect!
vector<cv::keypoint> keypoints;
blob_detector->detect(foreground, keypoints);
for(int j = 0; j<keypoints.size(); j++)
{
string text = format("%d", (int)j);
putText(foreground, text, keypoints[j].pt, FONT_HERSHEY_PLAIN, 0.8, CV_RGB(255,0,0), 1.0);
}
string text = format("%d People", (int)keypoints.size()) ;
putText(foreground, text, Point(20, 20), FONT_HERSHEY_PLAIN, 1.3, CV_RGB(255,255,255), 1.2);
imshow("Foreground ",foreground);
char c = (char)waitKey(fps);
if( c == 27 )
break;
}
}
thanks in advance..