hi, ı writed this codes to dedect vehicle which is inside of each frame in the video. now ı want to count but ı don't know how to do, could you show me how ı'll make it by writing several codes?
include "stdafx.h"
include <opencv2 imgproc="" imgproc.hpp="">
include <opencv2 objdetect="" objdetect.hpp="">
include <opencv2 highgui="" highgui.hpp="">
include <iostream>
include <vector>
using namespace cv; using namespace std;
int main(){
VideoCapture cap("arabalar2.avi"); // open the video file for reading
if ( !cap.isOpened() ) // if not success, exit program
{
cout << "Cannot open the video file" << endl;
return -1;
}
Mat gray;
string cascade_file= "C:/Cascades/haarcascades/cars.xml";
CascadeClassifier cascade;
if (cascade_file.empty() || !cascade.load(cascade_file))
{
cout << "Hata: cascade dosyası bulunamadı!n";
return -1;
}
namedWindow("MyVideo",CV_WINDOW_NORMAL);
while(1){
Mat frame;
bool bSuccess = cap.read(frame); // read a new frame from video
if (!bSuccess) //if not success, break loop
{
cout << "Cannot read the frame from video file" << endl;
break;
}
cvtColor(frame, gray, CV_BGR2GRAY);
equalizeHist(gray, gray);
vector<Rect> cars;
cascade.detectMultiScale(gray, cars, 1.1, 3, CV_HAAR_DO_CANNY_PRUNING|CV_HAAR_SCALE_IMAGE, Size(30,30));
for (int i = 0; i < cars.size(); i++) // bulunan yüz ifadelerini dikdörtgen içine alma
{
Rect rect = cars[i];
rectangle(frame, rect, CV_RGB(0,255,0), 1);
}
imshow("MyVideo", frame);
if(waitKey(30) == 27) //wait for 'esc' key press for 30 ms. If 'esc' key is pressed, break loop
{
cout << "esc key is pressed by user" << endl;
break;
}
}
return 0;
}