hello! I'm trying a program that I find on web.
This program do a people detect. I have a little problem and I think that this is very trivial.
Below I Post the code but I have problem on each declaration of vectors.
I don't know how can I fix this problem!!!
Thanks you for your help.
using namespace cv;
using namespace std;
//La funzione che farà tutto il lavoro
void detectROIObject(Mat frame);
//istanzio le variabili che mi servono
cv::Mat frame;
cv::Mat back;
cv::Mat fore;
std::vector contours;
vector rectangle;
//definisco il video da processare (0 o -1 per la webcam)
cv::VideoCapture cap("pathdelvideo");
//istanzio un background subtractor per eliminare lo sfondo
cv::BackgroundSubtractorMOG bg(50000, 100.0, 0.5);
int main(int argc, char *argv[])
{
//apro la finestra frame
cv::namedWindow("Frame");
//comincio a processare il video frame per frame
while ( cap.read(frame) )
{
//quando termina esci dal while e chiudi
if( frame.empty() )
{
printf(" --(!) No captured frame -- Break!");
break;
}
//salva il frame nella variabile omonima
cap >> frame;
//lancia la funzione passando il frame come parametro
detectROIObject(frame);
//mostra il video principale
cv::imshow("Frame",frame);
if(cv::waitKey(30) >= 0) break;
}
return 0;
}
void detectROIObject(Mat frame) {
//elimina il backgound
bg.operator ()(frame,fore, -1);
//processa l'immagine in primo piano per migliorare la precisione dei contorni
cv::threshold(fore,fore,30,255,CV_THRESH_BINARY);
cv::dilate(fore,fore,cv::Mat());
vector contours;
vector hierarchy;
//trova i contorni
findContours( fore, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
//Approssima i contorni a polighoni + prendi i rettangoli migliori
//per l'oggetto che stiamo considerando
vector contours_poly( contours.size() );
vector boundRect( contours.size() );
for( int i = 0; i < contours.size(); i++ )
{
approxPolyDP( Mat(contours[i]), contours_poly[i], 3, true );
boundRect[i] = boundingRect( Mat(contours_poly[i]) );
}
//Disegna i rettangoli
for( int i = 0; i< contours.size(); i++ ) {
//aventi area più grande di 1000 px
if (boundRect[i].area() > 1000) {
Point pt1;
pt1.x = boundRect[i].tl().x;
pt1.y = boundRect[i].tl().y;
Point pt2;
pt2.x = boundRect[i].br().x;
pt2.y = boundRect[i].br().y;
Rect rect(pt1, pt2);
cv::rectangle( frame, rect, cvScalar(0, 255, 0, 0), 1, 8, 0);
}
}
//Mostra anche cosa accade nello sfondo
cv::imshow("Foreground",fore);
}
↧